inla program has crashed

135 views
Skip to first unread message

Anirban Basu

unread,
Aug 5, 2021, 3:36:53 PM8/5/21
to R-inla discussion group
Hi all,
 I am running a very simple program in the process of learning inla. 

I have pasted my full code below.

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>.

I have been using verbose=TRUE in inla, but can't locate the output. So I am attaching my full code here, which reads the data. 

The shape file from US Census (cb_2016_us_county_500k.shp)  is too big to attach. But can provide directly if needed.

Any advice is appreciated.

Thanks,
Anirban

#********** MY PROGRAM
library(sp)
library(rgeos)
library(rgdal)
library(maptools)
library(dplyr)
library(leaflet)
library(scales)
require(maptools)
# Read Data
dat <- read.csv(url, stringsAsFactors = FALSE)
# Colnames tolower
names(dat) <- tolower(names(dat))
dat$countyname <- tolower(dat$countyname)
# Wide data set, subset only what we need.
county_dat <- subset(dat, measureid == "296", 
                     select = c("reportyear","countyfips","statename", "countyname", "value", "unitname")) %>%
  subset(reportyear==2011, select = c("countyfips", "value"))
# Rename columns to make for a clean df merge later.
colnames(county_dat) <- c("GEOID", "airqlty")
# Have to add leading zeos to any FIPS code that's less than 5 digits long to get a good match.
# I'm cheating by using C code. sprintf will work as well.
county_dat$GEOID <- formatC(county_dat$GEOID, width = 5, format = "d", flag = "0")
### End data prep

## read shape file
##us.poly<-readShapePoly(system.file("cb_2016_us_county_500k.shp", package="spdep"))
us.poly<-readOGR("cb_2016_us_county_500k.shp")

# Remove Alaska(2), Hawaii(15), Puerto Rico (72), Guam (66), Virgin Islands (78), American Samoa (60)
#  Mariana Islands (69), Micronesia (64), Marshall Islands (68), Palau (70), Minor Islands (74)
#us.poly <- us.poly[!us.poly$STATEFP %in% c("02", "15", "72", "66", "78", "60", "69",
 #                                       "64", "68", "70", "74"),]
# Make sure other outling islands are removed.
#us.poly <- us.poly[!us.poly$STATEFP %in% c("81", "84", "86", "87", "89", "71", "76",
 #                                       "95", "79"),]

# create inla weight matrices
list.queen<-poly2nb(us.poly, queen=TRUE)
cards<-card(list.queen)
tr<- which(cards==0)
# Merge spatial df with downloade ddata.
sub.poly<- us.poly[-tr,]
leafmap2 <- merge(sub.poly, county_dat, by=c("GEOID"), all=FALSE)
list.queen2<-poly2nb(leafmap2, queen=TRUE)

set.ZeroPolicyOption(TRUE)
W<-nb2listw(list.queen2, style="W", zero.policy=TRUE)
#W1<-nb2mat(list.queen2, style="W", zero.policy=TRUE)
WW<-listw2mat(W)
W2<-as(WW, "Matrix")

# graph data
popup_dat2 <- paste0("<strong>County: </strong>", 
                     leafmap2$NAME, 
                     "<br><strong>Value: </strong>", 
                     leafmap2$airqlty)

pal2 <- colorQuantile("YlOrRd", NULL, n = 20)

leaflet(data = leafmap2) %>% addTiles() %>%
  addPolygons(fillColor = ~pal(airqlty), 
              fillOpacity = 0.8, 
              color = "#BDBDC3", 
              weight = 1,
              popup = popup_dat2)

plot(W, coordinates(leafmap2))




## INLA
library(INLA)

# setup data
D <- data.frame(leafmap2)
leafdata<-transform(D, GEOID = as.numeric(GEOID))
leafdata <- leafdata[ , c("GEOID", "airqlty")]
ID<-seq(1:NROW(leafdata))
leafdata <- cbind(leafdata, ID)
E <-rep(100, NROW(leafdata))


formula <- airqlty ~ 1 + f(ID, model="bym", graph = W2, hyper = 
                             list(prec.unstruct = list(prior="loggamma", param=c(1,0.01)),
                                  prec.spatial = list(prior="loggamma", param=c(1,0.001 ))))

mod<-inla(formula, family="poisson", E=E,  data=leafdata, verbose=TRUE)







Anirban Basu

unread,
Aug 5, 2021, 3:41:08 PM8/5/21
to R-inla discussion group
Forget the above program. Even the simple program that is on this website crashes for me. I am running this in R studio. I have R 4.1 installed on a Windows machine with 128GB RAM.

A

n = 100; a = 1; b = 1; tau = 100
z = rnorm(n)
eta = a + b*z

scale = exp(rnorm(n))
prec = scale*tau
y = rnorm(n, mean = eta, sd = 1/sqrt(prec))

data = list(y=y, z=z)
formula = y ~ 1+z
result = inla(formula, family = "gaussian", data = data)

summary(result)

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>.



Helpdesk

unread,
Aug 6, 2021, 2:12:54 AM8/6/21
to Anirban Basu, R-inla discussion group
that is weird,

you simulate with 'a scale' and you might want to use

result = inla(formula, family = "gaussian", data = data, scale=scale)


if that does not help, please try adding

verbose=TRUE, debug=TRUE

and send me the output
> --
> 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/24e174ce-142d-42ae-b785-457a2c46a13an%40googlegroups.com
> .

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

Anirban Basu

unread,
Aug 6, 2021, 2:09:57 PM8/6/21
to R-inla discussion group
Hi  Håvard,
 Actually, I had to update the Windows Virtual C++ environment. And then it started working fine. Apparently, some critical dlls were missing.

 Thanks for all your help. 

Anirban

Helpdesk

unread,
Aug 7, 2021, 3:15:29 AM8/7/21
to Anirban Basu, R-inla discussion group

yes, that was my next question, as someone had a similar issue earlier

thx for the feedback
Reply all
Reply to author
Forward
0 new messages