INLA_spatio-temporal models

874 views
Skip to first unread message

a_r

unread,
Jan 22, 2017, 1:31:48 PM1/22/17
to R-inla discussion group
Dear all, 

I've been running a spatio temporal model in R-INLA. the time scope is 46 years, and it's yearly data. 

The models run pretty smoothly for the Knorr-Held formulation described in "spatio and spatio-temporal bayesian models with R-INLA", with the following code:

control <- list(
  predictor = list(compute = TRUE),
  results = list(return.marginals.random = TRUE, return.marginals.predictor=TRUE),
  compute = list(hyperpar=TRUE, return.marginals=TRUE, dic=TRUE, mlik = TRUE, cpo = TRUE, 
                 po = TRUE, waic=TRUE, graph=TRUE, gdensity=TRUE, openmp.strategy="huge"), 
  group = list(model="rw2"))


#non-parametric dynamic trend
#knorr-held formulation
formula2 <- numberTorn ~1 + f(ID, model = "bym", graph=tornb.inla) + f(Year, model="crw2")+
  f(Year2, model="iid")
modelsptp2 <- inla(formula = formula2, family = "poisson", 
                   quantiles = c(.05, .5, .95), 
                   data = TornInla,
                   control.compute = control$compute,
                   control.predictor = control$predictor)
summary(modelsptp2)

But I also would like to understand the space-time interactions, so I started to dig into it, and this is what happens:

#SP-TIME INTERACTION
#TYPE I
TornInla$area.year <- seq(1,length(countyTorn))
formTypeI <- numberTorn~ + f(ID, model="bym", graph=tornb.inla)+
  f(Year, model="crw2") + f(Year2, model="iid")+
  f(area.year, model="iid")

mod.intI <- inla(formTypeI,family="poisson",data=TornInla,
                 control.predictor=list(compute=TRUE),
                 control.compute=list(dic=TRUE,cpo=TRUE))

--------------- type I works fine



#Type II
TornInla$area.int <- TornInla$ID
TornInla$year.int <- TornInla$Year

formTypeII <-numberTorn ~ + f(ID, model="bym", graph=tornb.inla)+
  f(Year, model= "rw2") + f(Year2, model="iid") + 
  f(area.int, model="iid", group = year.int
    control.group=list(model="rw2"))

mod.intII<-inla(formTypeII,family="poisson",data=TornInla, 
                control.predictor=control$predictor, 
                control.compute=list(dic=TRUE,cpo=TRUE))

----------------------throws an error:
Warning in inla(formTypeII, family = "poisson", data = TornInla, control.predictor = control$predictor,  :
  f(area.int, ...) :  There is no indices where group[]=1, this is *usually* a misspesification
Warning in inla(formTypeII, family = "poisson", data = TornInla, control.predictor = control$predictor,  :
  f(area.int, ...): Number of unused groups >= the number of groups used: 1969 >= 47, this is *usually* a misspesification
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 not help, please contact the developers at <he...@r-inla.org>.
In addition: Warning message:
running command '"C:/Users/rp/Documents/R/win-library/3.3/INLA/bin/windows/64bit/inla.exe"  -b -s -v  "C:/Users/rp/AppData/Local/Temp/RtmpY3Jd2d/file1df8390cd9/Model.ini"' had status 1 

#Type III
formTypeIII<- numberTorn~+ f(ID, model="bym", graph= tornb.inla)+
  f(Year, model="crw2") + 
  f(Year2, model="iid") +
  f(year.int, model="iid", group =area.int
    control.group=list(model="besag", graph = tornb.inla))

mod.intIII <- inla (formTypeIII,family="poisson",data=TornInla, 
                    control.predictor=control$predictor, 
                    control.compute=control$compute)

###Type IV 
formTypeIV<- numberTorn ~+ f(ID, model="bym", graph=tornb.inla)+
  f(Year, model="crw2") + f(Year2, model="iid") + 
  f(area.int, control.group= list(model="rw2"))

mod.intIV <- inla (formTypeIV,family="poisson",data=TornInla, 
                   control.predictor=control$predictor, 
                   control.compute=control$compute)



Type III and IV just take too long (more than 12 hours so far). I even set in control.compute   openmp.strategy="huge", and I am running the scripts in MRO, which is supposelly faster than R, but still it isn't fast enough. Is this normal, or is there something wrong with the code? And why does it crash when I try to run the type II?
Any advice is welcome!

Thanks in advance, 
Angela

Haakon Bakka

unread,
Jan 23, 2017, 7:30:43 AM1/23/17
to a_r, R-inla discussion group
Partial answer:

To speed up spacetime, use 
           control.inla=list(int.strategy='eb')
(No integration of hyper-param)

and select good staring values, to input in
control.mode=list(theta=c(   <starting values in internal scale>   ), 
                             restart=TRUE), 

See the SPDE tutorial for more space-time code.

Kind regards,
Haakon






--
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-group+unsub...@googlegroups.com.
To post to this group, send email to r-inla-discussion-group@googlegroups.com.
Visit this group at https://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.

Finn Lindgren

unread,
Jan 23, 2017, 8:21:44 AM1/23/17
to Haakon Bakka, a_r, R-inla discussion group
For case 2, focus on the warning messages; the error is very likely an effect, and what the warnings are about is the cause.
Finn

Finn
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 email to r-inla-disc...@googlegroups.com.

Paolo Girardi

unread,
Mar 28, 2017, 9:20:14 AM3/28/17
to R-inla discussion group, ba...@r-inla.org, afonsoange...@gmail.com
I think you have to scale the temporal variable starting from one.

To post to this group, send email to r-inla-disc...@googlegroups.com.
Visit this group at https://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.

--
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-group+unsub...@googlegroups.com.

Finn Lindgren

unread,
Mar 28, 2017, 9:24:25 AM3/28/17
to Paolo Girardi, R-inla discussion group, ba...@r-inla.org, afonsoange...@gmail.com
Indeed, good catch Paolo!

All indexed models start on 1, so a model with years 1950,1951,..,1960, for example, needs to have indexes 1,2,...,11. Otherwise the model will have 1960 timesteps instead of just 11.

Finn

Finn
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.

Håvard Rue

unread,
Mar 28, 2017, 9:30:01 AM3/28/17
to Finn Lindgren, Paolo Girardi, R-inla discussion group, ba...@r-inla.org, afonsoange...@gmail.com
On Tue, 2017-03-28 at 14:24 +0100, Finn Lindgren wrote:
> Indeed, good catch Paolo!

Indeed!!!!

--
Håvard Rue
Department of Mathematical Sciences
Norwegian University of Science and Technology
N-7491 Trondheim, Norway
Voice: +47-7359-3533 URL : http://www.math.ntnu.no/~hrue
Mobile: +47-9260-0021 Email: havar...@math.ntnu.no

R-INLA: www.r-inla.org

Angela Rodrigues Afonso

unread,
Mar 28, 2017, 12:04:09 PM3/28/17
to hr...@r-inla.org, ba...@r-inla.org, R-inla discussion group, paologi...@gmail.com
Great! 

Thank you all. 
Reply all
Reply to author
Forward
0 new messages