andrewzm / STRbook

Supplementary package for "Spatio-Temporal Statistics with R" by C.K. Wikle, A. Zammit-Mangion, and N. Cressie

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

INLA: Fail to get good enough initial values using MOcarolinawren_long example data

jamesdalg opened this issue · comments

library(INLA)
library(dplyr)
library(tidyr)
library(ggplot2)
#install_github("andrewzm/STRbook")
data("MOcarolinawren_long",package="STRbook")
coords<-unique(MOcarolinawren_long[c("loc.ID","lon","lat")])

par(mfrow=c(3,3))
boundary<-inla.nonconvex.hull(as.matrix(coords[,2:3]))

MOmesh <- inla.mesh.2d(boundary = boundary,max.edge = c(5,10),cutoff=3)
plot(MOmesh,asp=1,main="")

spde<-inla.spde2.pcmatern(mesh=MOmesh,alpha=2,prior.range=c(1,0.01),
                          prior.sigma=c(4,0.01))

A.est<-inla.spde.make.A(mesh=MOmesh,loc=as.matrix(coords[,2:3]))
spde<-inla.spde2.matern(mesh=MOmesh,alpha=2)
simple_nontemporal_formula=y ~ -1 + intercept + f(spatial.field, model=spde)
inla_model=inla(formula = simple_nontemporal_formula,data=list(y=MOcarolinawren_long$cnt, intercept= rep(1,nrow(MOcarolinawren_long)),spatial.field=1:spde$n.spde),control.predictor = list(A=A.est,compute=T) )

Error in inla.core(formula = formula, family = family, contrasts = contrasts,  : 
  MPredictor == ny is not TRUE

 *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=1/2 
Error in inla.core(formula = formula, family = family, contrasts = contrasts,  : 
  MPredictor == ny is not TRUE

 *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=2/2 
Error in inla.core(formula = formula, family = family, contrasts = contrasts,  : 
  MPredictor == ny is not TRUE
Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts,  : 
  *** Fail to get good enough initial values. Maybe it is due to something else.