Bayesian spatiotemporal model

494 views
Skip to first unread message

Ebenezer Ogunsakin

unread,
Jul 21, 2024, 12:23:46 PM7/21/24
to R-inla discussion group
Hi all, 

I currently am new to INLA and am trying to run a Bayesian model but am trying to figure out this error.
*** inla.core.safe: The inla program failed, but will rerun in case better initial values may help. try=1/1 Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts, : The inla program call crashed. The inla program failed and the maximum number of tries has been reached.

Below is my code that gives the above error
result1  = inla(formula1,family="poisson",data=data,E=eL,control.compute=list(dic=TRUE,cpo=TRUE))
result1$dic$dic;result1$dic$p.eff
UH<-result1$summary.random$region[,2]
summary(result1)

Kai

unread,
Jul 21, 2024, 12:38:57 PM7/21/24
to R-inla discussion group
Hi  Ebenezer,

I am also a beginner. I've encounter same error before, until I found that there were many unexpected missing value in my random effect variable (the spatial id). 
So I would recommend checking the missingness of the covariates in your formula1 again.

And I know it would be helpful if you add verbose=TRUE while running your model - this can help debug.
Good luck.
Kai

Ebenezer Ogunsakin

unread,
Jul 21, 2024, 2:11:43 PM7/21/24
to R-inla discussion group
Thanks for your response, Kai.

I have used verbose=TRUE, before sending this comment. It wasn't working. Also, no missingness in the covariates.

Helpdesk (Haavard Rue)

unread,
Jul 23, 2024, 1:57:31 PM7/23/24
to Kai, R-inla discussion group
you're right Kai,

if that does not work, adding verbose=TRUE to inla(), then please share data and
code so we can rerun it here
> --
> 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 view this discussion on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/ceda4582-fdd4-4b2f-9b30-fd2047ed7f9en%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org

Ebenezer Ogunsakin

unread,
Jul 23, 2024, 2:01:15 PM7/23/24
to R-inla discussion group
Thanks for your feedback. Attached here are the dataset and r command.

Thank you.

data.csv
CM2_code.R
SubregionTBpaper.csv

Ebenezer Ogunsakin

unread,
Jul 28, 2024, 1:34:54 PM7/28/24
to R-inla discussion group
Good morning, Dr Håvard Rue. I trust you are doing well.

Would you happen to have any suggestions on how to handle the error on my INLA model?

Thank you

On Tuesday, July 23, 2024 at 1:57:31 PM UTC-4 Helpdesk (Haavard Rue) wrote:

Helpdesk (Haavard Rue)

unread,
Jul 28, 2024, 2:19:05 PM7/28/24
to Ebenezer Ogunsakin, R-inla discussion group


# africa = read_sf("africashape.shp")
# africa=readOGR("D:/new manuscript/combined.shp")
africa <- shapefile("AfricaMap.shp")


I need one of these

Ebenezer Ogunsakin

unread,
Jul 28, 2024, 2:38:24 PM7/28/24
to R-inla discussion group
combined.qmd
combined.prj
combined.cpg
combined.dbf

Ebenezer Ogunsakin

unread,
Jul 28, 2024, 2:40:02 PM7/28/24
to R-inla discussion group
Thanks, Dr Haavard.

Attached is the file. Thank you for your help.

combined.shx

Ebenezer Ogunsakin

unread,
Jul 28, 2024, 2:40:44 PM7/28/24
to R-inla discussion group
combined.shx

Helpdesk (Haavard Rue)

unread,
Jul 28, 2024, 2:50:24 PM7/28/24
to Ebenezer Ogunsakin, R-inla discussion group

I don't know how to generate the graph file from either one of these:


africa = read_sf("combined.shp")
##africa=readOGR("combined.shp")
##africa <- shapefile("combined.shp")



this will not work

f(region2,model="bym",graph="africa")


sometimes this function is used:

nb2INLA package:spdep R Documentation

Output spatial neighbours for INLA

Description:

Output spatial neighbours for INLA

Usage:

nb2INLA(file, nb)

Arguments:

file: file where adjacency matrix will be stored

nb: an object of class ‘nb’

Ebenezer Ogunsakin

unread,
Jul 28, 2024, 3:18:13 PM7/28/24
to R-inla discussion group
Thanks, Dr Haavard.

Apart from the one you mentioned which I agree with, yet the code does not work for

# model 1: spatial only UH
formula1 = yL~1+subregion+f(region,model="iid")

result1  = inla(formula1,family="poisson",data=data,E=eL,control.compute=list(dic=TRUE,cpo=TRUE))
result1$dic$dic;result1$dic$p.eff
UH<-result1$summary.random$region[,2]
summary(result1)

Remember the above does not need to generate a graph, yet it does still not run. Although, this line of code: formula1 = yL~1+subregion+f(region,model="iid") works but result1  = inla(formula1,family="poisson",data=data,E=eL,control.compute=list(dic=TRUE,cpo=TRUE)) does not.

Helpdesk (Haavard Rue)

unread,
Jul 29, 2024, 9:08:02 AM7/29/24
to Ebenezer Ogunsakin, R-inla discussion group

the poisson data are not integer,

> data$yL[1]
[1] 119.6

> length(which (data$yL != as.integer(data$yL)))
[1] 488
>


you may change 'poisson' into 'xpoisson' which acceptes non-integers; please
see doc inla.doc('xpoisson')

Helpdesk (Haavard Rue)

unread,
Jul 29, 2024, 9:08:42 AM7/29/24
to Ebenezer Ogunsakin, R-inla discussion group
here is the error msg


*** ERROR *** INLA.Data1: POISSON likelihood is defined on integers, but y[0]
= 119.6
Reply all
Reply to author
Forward
0 new messages