Problem doing linear combination with factor covariate

390 views
Skip to first unread message

SW

unread,
Oct 11, 2013, 2:25:32 PM10/11/13
to r-inla-disc...@googlegroups.com
Is there a way to specify linear combination for a model with factor covariates? I am faced with the error below when trying to do linear combination with my age group covariate. My work-around right now is to define multiple dummy variables for each age group, then use these dummy variables (as numeric) in the model. This gets very tedious, however, as I have multiple categorical variables that will need to be put into the model.

*** ERROR ***   Section no [0] named [Age.g] in file [39234672] offset[               0] is unknown.

Error in inla.inlaprogram.has.crashed() : 
  The inla-program exited with an error. Unless you interupted it yourself, please rerun with verbose=TRUE and check the output carefully.
  If this does help; please contact the developers at <he...@r-inla.org>.


Thanks so much in advance!

INLA help

unread,
Oct 13, 2013, 5:11:19 AM10/13/13
to SW, r-inla-disc...@googlegroups.com
On Fri, 2013-10-11 at 11:25 -0700, SW wrote:
> Is there a way to specify linear combination for a model with factor
> covariates? I am faced with the error below when trying to do linear
> combination with my age group covariate. My work-around right now is
> to define multiple dummy variables for each age group, then use these
> dummy variables (as numeric) in the model. This gets very tedious,
> however, as I have multiple categorical variables that will need to be
> put into the model.

for

formula = y ~ x

where 'x' is a factor, then the model.matrix() function expands this
into a sum of indicator variables, one for each level. Not all levels
needs to be presented, as this also depends on the contents of 'x'. (see
also a FAQ entry on this with R (and ?control.fixed)

the consequence, is that the expanded variable names need to be used
when defining a linear combination.

> x = as.factor(c("a", "b", 2))
> x
[1] a b 2
Levels: 2 a b
> r = inla(y ~ x, data = data.frame(y=1:3,x))
> rownames(r$summary.fixed)
[1] "(Intercept)" "xa" "xb"


so we need to do

> r = inla(y ~ x, data = data.frame(y=1:3,x), lincomb =
inla.make.lincomb(xa=-1,xb=1))



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

Susan W

unread,
Oct 15, 2013, 4:05:42 PM10/15/13
to he...@r-inla.org, r-inla-disc...@googlegroups.com
Hello Havard,

Thank you very much for this. Worked wonderfully!

Regards,
Susan
Reply all
Reply to author
Forward
0 new messages