Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

The inla result collection failed.

35 views
Skip to first unread message

TheCorinna1994

unread,
Apr 9, 2025, 6:13:19 PMApr 9
to R-inla discussion group
Hi,

I have a spatio-temporal binomial model and want to do k-fold crossvalidation.
Therefore I specify the sample und define Ntrials_late and for each k I run INLA.
But somehow it says: 
Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts,  :
The inla result collection failed.

Do you have any clue what this means?
Any remark is highly appreciated.

Best, Corinna
Here is a snippet of the code: 

set.seed(1)
spec=c(val1=.1, val2=.1, val3=.1, val4=.1, val5=.1, val6=.1, val7=.1, val8=.1, val9=.1, val10=.1)
g=sample(cut(seq(nrow(temp_late)), nrow(temp_late)*cumsum(c(0,spec)), labels=names(spec)))


Ntrials_late<-temp_late$Days_per_month

for(k in 1:10){
 
  index_val=which(g==paste0("val",k))
  index_train=which(g!=paste0("val",k))
 
  A.train<-inla.spde.make.A(mesh=mesh, loc=as.matrix(temp_late[index_train,c('Longitude','Latitude')]), group=temp_late$Month[index_train])

  A.val<-inla.spde.make.A(mesh=mesh, loc=as.matrix(temp_late[index_val,c('Longitude','Latitude')]), group=temp_late$Month[index_val])
  
  stack.train<-inla.stack(data=obs.data_late[index_train,], A=list(A.train,1),
                          effects=list(c(index,index_mean, list(Intercept=1)),
                                       list(covars.data_late[index_train,])),
                          tag="train")

  stack.val<-inla.stack(data=obs.data_pred[index_val,], A=list(A.val,1),
                         effects=list(c(index,index_mean, list(Intercept=1)),
                                       list(covars.data_late[index_val,])),
                         tag="val")

 
  join.stack<-inla.stack(stack.train, stack.val)
 
  Ntrials<-c(Ntrials_late[index_train], Ntrials_late[index_val])
 
  min_result<-inla(formula4_min,  family="binomial", Ntrials=Ntrials,
                   data=inla.stack.data(join.stack, spde=spde.nonstat),
                   control.family=list(link='logit'),
                   control.predictor = list(A=inla.stack.A(join.stack), compute=TRUE,link=1),
                   control.compute = list(dic=TRUE,cpo=TRUE, waic=TRUE, config=TRUE,
                                          openmp.strategy="pardiso.parallel"),
                   verbose=TRUE)
 
}  
  

Helpdesk (Haavard Rue)

unread,
Apr 10, 2025, 4:25:39 AMApr 10
to TheCorinna1994, R-inla discussion group
A better way to do k-fold crossvalidation is, described in the vignette (and you
find the main paper on arxiv)

Cross-validation and group-cross-validation in INLA - PDF source R code

this might be useful.

anyway, try adding option

verbose=TRUE,safe=FALSE

and hopefully something will show, why it fail.


make sure to use the most recent testing version, btw.

I can rerun here if you share data/code to do that
> --
> 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, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/6863ed39-7672-4039-9688-01f60cbddf3fn%40googlegroups.com
> .

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

Finn Lindgren

unread,
Apr 10, 2025, 5:06:07 AMApr 10
to TheCorinna1994, R-inla discussion group
In addition to Haavard's suggestions, please consider switching to inlabru for mesh/spde models (but also other models...) in particular, to avoid hard-to-debug stack issues.
From what I can guess from your code, your loop contents, starting from the first inla.spde.make.A call, can be replaced with something like this (it can _very_ likely be simplified further by modifying how you store your data, but the below attempts to be a drop-in replacement for what you have):

# Collect the data:
data_train <- cbind(obs.data_late[index_train,],
                    covars.data_late[index_train,],
                    temp_late[index_train,],
                    Ntrials = Ntrials_late[index_train])
data_val <- cbind(obs.data_pred[index_val,],
                  covars.data_late[index_val,],
                  temp_late[index_val,],
                  Ntrials = Ntrials_late[index_val])

# Guess of your model component & predictor structure:
components <- your_observation_variable ~ Intercept(1) +
  your + covariate + names +
  field(as.matrix(.data[, c("Longitude", "Latitude")]),
        model = field_model,
        group = Month,
        control.group = list(...)
  )

# Estimate:
result <- bru(
  components,
  family = "binomial",
  Ntrials = Ntrials,
  data = dplyr::bind_rows(data_train, data_val),
  options = list(
    control.compute = list(
      dic = TRUE,
      cpo = TRUE,
      waic = TRUE,
      openmp.strategy =
        "pardiso.parallel"
    ),
    verbose = TRUE
  )

# To locate the validation data in the output predictor:
index_val_output <- length(index_train) + seq_along(index_val)

--
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, visit https://groups.google.com/d/msgid/r-inla-discussion-group/6863ed39-7672-4039-9688-01f60cbddf3fn%40googlegroups.com.


--
Finn Lindgren
email: finn.l...@gmail.com

TheCorinna1994

unread,
Apr 10, 2025, 9:41:16 AMApr 10
to R-inla discussion group
Ok great thanks that worked out.

Since I need to run few big spde models, already implemented in INLA, I wanted to install INLA on a faster server with Red Hat Linux distribution. 
I have the following error code: 

*** ERROR ***
 *** dlopen error with file[/tmp/RtmprhBXXq/file1c8f4d2eeb640e/data.files/file1c8f4d34a2ba55.so] err_msg[file not found]
 
The inla program failed and the maximum number of tries has been reached.
Calls:inla -> inla.core.safe
Execution halted

I know switching to inlabru is the next step, however, everything is implemented already. Could you maybe help one more time please?

Best, Corinna
Reply all
Reply to author
Forward
0 new messages