Data stack and factors

341 views
Skip to first unread message

Jussi

unread,
Mar 19, 2013, 5:31:05 AM3/19/13
to r-inla-disc...@googlegroups.com
Dear all,

I'm wondering whether INLA treats factors incorrectly or am I missing something. In this toy example there is a variable with 6 factor levels, which I put into a stack and feed to INLA, which returns estimates for 7 levels!? However, if I give the data directly to INLA I get 5 as should:

data(InsectSprays)
n = nrow(InsectSprays)

loc = matrix(runif(n),n,2)
mesh = inla.mesh.create.helper(points.domain=loc, max.edge=c(0.1,0.5))
spde = inla.spde2.matern(mesh)
index = inla.spde.make.index("spatial", mesh$n)
A = inla.spde.make.A(mesh, loc, index=1:n)

stack = inla.stack(data=list(count=InsectSprays$count), A=list(A, 1),
                   effects=list(c(index, list(intercept=1)), list(spray=InsectSprays$spray)))
summary(inla(count ~ -1 + intercept + spray, data=inla.stack.data(stack), control.predictor=list(A=inla.stack.A(stack))))
summary(inla(count ~ spray, data=InsectSprays))


Jussi

unread,
Mar 19, 2013, 5:38:58 AM3/19/13
to r-inla-disc...@googlegroups.com
I just updated INLA. Now I get 6 estimates, so still something wrong.

Finn Lindgren

unread,
Mar 19, 2013, 6:20:47 AM3/19/13
to Jussi, r-inla-disc...@googlegroups.com
Dear Jussi,

inla.stack() does not currently support factors. You can transform them
into 0/1 variables instead and build your model using that.

Another way is to use model.matrix() and feed that into inla.stack() as
a matrix, which will allow you to keep most of the rest of the code
intact. I'll see if I can find the example I wrote for that a long time
ago...

Finn
> --
> 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 an email to
> r-inla-disc...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/r-inla-discussion-group?hl=en-GB.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Jussi

unread,
Mar 19, 2013, 7:01:03 AM3/19/13
to r-inla-disc...@googlegroups.com, Jussi
Ok, I see. Thank you for the answer.

Elias Teixeira Krainski

unread,
Mar 19, 2013, 7:06:53 AM3/19/13
to r-inla-disc...@googlegroups.com
We have an example with factors on inla.stack() on
any answer on semi continuous data at this list.


Reply all
Reply to author
Forward
0 new messages