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