Error in inla[...] Covariate does not match [...]

1,262 views
Skip to first unread message

Olga Lyashevska

unread,
Feb 27, 2013, 10:37:58 AM2/27/13
to r-inla-disc...@googlegroups.com
Hi, 

I have the following model specification (thanks to Elias):

form <- Y ~ 0 + mu.z + mu.y + ycov + ucov + 
f(z.i, model=spde) + 
f(y.i, copy='z.i', 
hyper=list(theta=list(fixed=FALSE,  param=c(-2,5),
initial=-2))) 

load(d0Prooi)
n<-length(d0Prooi)
idat<-list(Y=matrix(NA, 2*n ,2))
idat$Y[1:n,1]<-ifelse(is.na(d0Prooi$Ymax),1,0) #z variable
idat$Y[n+1:n,2]<-d0Prooi$Ymax #y data
#covariates
idat$ucov <- c(d0Prooi$depth, rep(0,n)) ### covariate for z
idat$ycov <- c(rep(0,n), d0Prooi$depth) ### covariate for y
#intercepts
idat$mu.z <- rep(1:0, each=n) ### z
idat$mu.y <- rep(0:1, each=n) ### y
### index for the field (on z)
idat$z.i <- c(1:n, rep(NA,n)) 
### index for the field (on y)
idat$y.i <- c(rep(NA,n), 1:n) 

When I run my model:
result <- inla(formula=form, family=c('binomial', 'gaussian'), data=idat, control.predict=list(compute=TRUE))

I get the following error:
Error in inla(formula = form, family = c("binomial", "gaussian"), data = idat,  : 
 f(z.i). Covariate does not match 'values' 13179 times. Indexes for mismatch [...]

Any clues? I have seen a similar post by Shige Song from 6/28/11, but unfortunately I could not resolve my problem.

My spde object, input and reshaped data can be found here:


Thanks,
Olga


Elias Teixeira Krainski

unread,
Feb 27, 2013, 11:02:09 AM2/27/13
to r-inla-disc...@googlegroups.com
How you construct the mesh?
If the location points aren't vertices of the mesh,
you need to use the inla.stack()
> --
> 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.
>
>


Olga Lyashevska

unread,
Feb 28, 2013, 4:30:13 AM2/28/13
to r-inla-disc...@googlegroups.com
On 02/27/2013 05:02 PM, Elias Teixeira Krainski wrote:
> How you construct the mesh?

I constructed it as following:
(thanks to Finn)

###import shape file with borders
grenzen.shp<-readShapePoly("./grenzen_shp.shp",proj4string=CRS("+init=epsg:3035"))

###transform CRS, for some reason could not directly assign the one I
wanted, so I took a projection of one of my covariates
grenzen.shp<-spTransform(grenzen.shp, CRS(projection(depth)))
grenzen <- inla.sp2segment(grenzen.shp)
mesh <- inla.mesh.create(loc=d0Prooi@coords,boundary=grenzen,
refine=list(max.edge=10000), plot.delay=1)
spde<-inla.spde.create(mesh)

###or this one
### spde <- inla.spde2.matern(mesh)

btw what is the difference between inla.spde.create and
inla.spde2.matern, if I specify model="matern" in the former function,
would it be equivalent to the latter?

Regards,
Olga

Finn Lindgren

unread,
Feb 28, 2013, 4:36:57 AM2/28/13
to Olga Lyashevska, r-inla-disc...@googlegroups.com
On 28/02/13 09:30, Olga Lyashevska wrote:
> spde<-inla.spde.create(mesh)
> ###or this one ### spde <- inla.spde2.matern(mesh)
> btw what is the difference between inla.spde.create and
> inla.spde2.matern, if I specify model="matern" in the former function,
> would it be equivalent to the latter? Regards, Olga

They use slightly different parameterisations. I recommend
inla.spde2.matern, since new developments and improvements will happen
in that model.

Finn
Reply all
Reply to author
Forward
0 new messages