Model selection using p-values

414 views
Skip to first unread message

Sophie Lee

unread,
Jul 29, 2014, 6:37:27 AM7/29/14
to r-inla-disc...@googlegroups.com
I'm trying to fit a model including fixed effects, a spatial term and random effects using INLA. I've managed to fit a full model including all possible covariates (of which there are 20) but I want to use backwards selection to find which covariates to include in the final modell. I could use the DIC measure but as I have 20 covariates it would take hours to fit each possible model and compare the DIC for each, is there any way to produce p-values similar to those seen in the summary output for GLM or GAM models?

Daniel Simpson

unread,
Jul 29, 2014, 6:42:05 AM7/29/14
to Sophie Lee, r-inla-disc...@googlegroups.com
In a word: no. To do that in a bayesian way, you'd need "spike and slab" priors to move through the space, which is impossible in INLA. Otherwise, write an R script and send it running overnight. 

Best wishes,

Dan

On Tuesday, July 29, 2014, Sophie Lee <sophie...@gmail.com> wrote:
I'm trying to fit a model including fixed effects, a spatial term and random effects using INLA. I've managed to fit a full model including all possible covariates (of which there are 20) but I want to use backwards selection to find which covariates to include in the final modell. I could use the DIC measure but as I have 20 covariates it would take hours to fit each possible model and compare the DIC for each, is there any way to produce p-values similar to those seen in the summary output for GLM or GAM models?

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To post to this group, send email to r-inla-disc...@googlegroups.com.
Visit this group at http://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.

INLA help

unread,
Jul 29, 2014, 6:42:07 AM7/29/14
to Sophie Lee, r-inla-disc...@googlegroups.com
not really...

INLA is good for fitting one model. Comparing/Chosing models is
different issues

--
Håvard Rue
he...@r-inla.org

zarkov qrygen

unread,
Nov 6, 2016, 6:14:44 AM11/6/16
to R-inla discussion group, sophie...@gmail.com, he...@r-inla.org
Same problem here. I also wanted to do a variable selection, and I used the mlik criteria. 
I started of with a null model: 

f.null<-as.formula(y~1)
model0 = inla(f0, family="binomial", data = mydata, Ntrials=rep(1,n))
null.lml <- model0$mlik[1];

#mydata with p predictor variables

p<-dim(mydata)[2]
predictor.index <- c(1:p)
log.mlik <- rep(0,length(predictor.index))

for (i in 1:length(log.mlik)){
    formula = y ~ mydata[,predictor.index[i]] + f(id, model = "iid") 
    result = inla(formula,family="binomial", data = mydata,
             control.compute =list(mlik = TRUE,config=TRUE))
    log.ml[i] <- result$mlik[1]
}
names(mydata)[predictor.index[which(log.ml>null.lml)]]

And so for the 1st variable to include in the model, I put the one with the highest mlik. However, for the next step, adding more variables 
( I want to do like a forward selection, or stepwise procedure), I am still confused on how to keep the selected ones, then combining it with the others.
e.g. let x1 be the selected, so my model is: 
     y~x1

Then, I want to add x2, ..., xp one at a time to the model, and re-do the above steps again. 
How can I do this without 'manually' write the model one by one? Any help is much appreciated.

INLA help

unread,
Nov 6, 2016, 8:00:22 AM11/6/16
to zarkov qrygen, R-inla discussion group, sophie...@gmail.com
On Sun, 2016-11-06 at 03:14 -0800, zarkov qrygen wrote:



> Then, I want to add x2, ..., xp one at a time to the model, and re-do
> the above steps again. 
> How can I do this without 'manually' write the model one by one? Any
> help is much appreciated.


you can use the update-function on a formula,

> vars = paste0("x", 1:10)
> vars
 [1] "x1"  "x2"  "x3"  "x4"  "x5"  "x6"  "x7"  "x8"  "x9"  "x10"
> formula = y ~ 1
> for(v in vars) { f
formula = update(formula, paste(". ~ . +", v))
        print(formula); 
}

y ~ x1
y ~ x1 + x2
y ~ x1 + x2 + x3
y ~ x1 + x2 + x3 + x4
y ~ x1 + x2 + x3 + x4 + x5
y ~ x1 + x2 + x3 + x4 + x5 + x6
y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7
y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8
y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10



H
 

--
Håvard Rue
he...@r-inla.org

Haakon Bakka

unread,
Nov 6, 2016, 4:37:02 PM11/6/16
to INLA help, zarkov qrygen, R-inla discussion group, sophie...@gmail.com
Alternatively, if you have a dataframe "df" with many different covariates, and you have a sequence "covar" of 1/0 or T/F of which covariates you want to include:

formula.basic = paste('y ~ 1 ')
formula.basic = paste(formula.basic, ' + ', paste(colnames(df[ ,covar]), collapse=' + '))
as.formula(formula.basic)

Essentially you can use paste( ..., collapse = " + ") to do most things you want with a formula!

Haakon


--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.
To post to this group, send an email to r-inla-discussion-group@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages