Prediction with Joint hurdle model

263 views
Skip to first unread message

Sylvan Benaksas

unread,
Oct 21, 2021, 12:32:36 PM10/21/21
to R-inla discussion group
Hi there,

I have created a joint hurdle model with binomial and truncated negative binomial liklihoods, I would now like to predict the fitted values across a fine-scale grid of locations. I have created a grid of locations with covariates and have tried to create prediction stacks, one for the binomial liklihood and one for the count liklihood. I have read to leave the response as NA for prediction, but joint models already contain NAs for the count part at locations with 0 in the binary part, as well as having two responses (e.g. response = cbind(NA, y)). I am confused how to write this with such a joint model, as well, does a family need to be listed in the inla call for the prediction stacks (eg "binary" or "zeroinflatednbinomial0").

kind regards,
Sylvan

Sylvan Benaksas

unread,
Oct 21, 2021, 12:38:10 PM10/21/21
to R-inla discussion group
here are example code, data, and a prediction matrix of locations
inla sandeels predicting.R
ns sandeels env and sed clipped inla.csv
prediction matrix example.csv

Sylvan Benaksas

unread,
Oct 21, 2021, 12:43:31 PM10/21/21
to R-inla discussion group
sorry here is the correct example code
example code inla prediction.R

Elias T. Krainski

unread,
Oct 22, 2021, 4:47:56 AM10/22/21
to R-inla discussion group
Dear Sylvan, 

You have a bivariate outcome and correctly set two columns in the fitting data stack. You just need to do the same for the prediction as well: you have to set a two-columns outcome for the prediction data stack. If 'npred.z' and 'npred.y' are the size of the prediction scenario for z and y, respectively, you can do matrix(NA, nrow=npred.z, ncol=2) and matrix(NA, nrow=npred.y, ncol=2) for the corresponding prediction stack.  

Notes:
1. is better to use the UTM in km (you have it but didn't use it). 
2. you do not need to include NA's in the data stack for the model fitting.
3. Since you are building a model for only positives (the second outcome), therefore a more suitable likelihood would be any of this kind.
4. When defining SPDE models with plain INLA (building all the related stuff) you have to explicitly include the intercept and drop the one R usually includes by default (something like response ~ 0 + y.intercept + z.intercept + ...). The easier way to deal with SPDE models is through the inlabru package.
5. I tried your code but one of the factor covariate has too few observations that brings a problem when combining with the other factor: zero in the contingency table leads to the impossibility of fitting all the contrast levels.

Elias

--
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/bb949013-5112-46f6-a0b9-aef1ff71c593n%40googlegroups.com.

Sylvan Benaksas

unread,
Oct 22, 2021, 6:14:09 AM10/22/21
to R-inla discussion group
Hi Elias,

Thanks for getting back to me, I am only new to INLA and I really appreciate all of your advice. I have implemented your code and It seems to be running now thank you! it will take a while I'm sure so I will have to wait to see the end result.

In your 2. note you said NAs are not needed in fitting the model, I'm not sure what you mean by this do you refer to the bivariate response in the stack? could you explain that please?

best wishes,
Sylvan

Sylvan Benaksas

unread,
Oct 22, 2021, 8:10:33 AM10/22/21
to R-inla discussion group
Hi Elias,

The model is running but some time in it exits with an error:

these are the last few lines of the output

config 78/149=[  1.084  1.095  1.184 -1.142 -0.333  0.436 -1.172 -1.048  0.763  0.914 ] log(rel.dens)= -6.446, [5] accept, compute, 19.39s
config 79/149=[  1.084 -1.098 -1.099 -1.142 -0.333 -0.940  1.033  0.915  0.763  0.914 ] log(rel.dens)= -6.047, [3] accept, compute, 16.17s
config 80/149=[ -1.124  1.095 -1.099  1.134  0.057 -0.940  1.033  0.915 -0.017  0.914 ] log(rel.dens)= -4.140, [2] accept, compute, 17.05s
config 81/149=[  1.084 -1.098  1.184  1.134 -0.333  0.436 -1.172  0.915 -0.017 -0.925 ] log(rel.dens)= -7.647, [4] accept, compute, 17.54s
config 82/149=[ -1.124 -1.098  1.184 -1.142 -0.333 -0.940  1.033 -1.048 -0.017 -0.925 ] log(rel.dens)= -6.168, [1] accept, compute, 17.55s
config 83/149=[  1.084  1.095  1.184 -1.142 -0.333  0.436  1.033  0.915 -0.017 -0.925 ] log(rel.dens)= -7.414, [5] accept, compute, 18.58s
config 84/149=[ -0.000 -0.000  0.000  0.000 -0.000 -2.974  0.000 -0.000 -0.000  0.000 ] log(rel.dens)= -7.724, [0] accept, compute, 21.21s
config 85/149=[  1.084 -1.098 -1.099 -1.142 -0.333  0.436 -1.172  0.915 -0.017  0.914 ] log(rel.dens)= -5.155, [3] accept, compute, 20.72s
config 86/149=[ -1.124  1.095 -1.099  1.134  0.057 -0.940  1.033  0.915  0.763 -0.925 ] log(rel.dens)= -3.511, [2] accept, compute, 18.49s
config 87/149=[  1.084 -1.098  1.184  1.134 -0.333  0.436 -1.172

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

do you know what might be causing this?


Cheers,
Sylvan

Helpdesk

unread,
Oct 22, 2021, 10:23:49 AM10/22/21
to Sylvan Benaksas, R-inla discussion group

this is due to lack of memory.

either add

control.inla=list(int.strategy="eb")

or reduce the number of threads (argument 'num.threads'), or use R-4.1
and the most recent testing version adding argument
inla.mode="experimental"
> --
> 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/ce2d70a8-ba4f-4919-a7d0-3603f4bb5905n%40googlegroups.com
> .

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

Sylvan Benaksas

unread,
Oct 22, 2021, 11:13:09 AM10/22/21
to R-inla discussion group
Hi Håvard,

using control.inla=list(int.strategy="eb") the model has now run(!!), thank you very much for your help. Are these memory reducing strategies likely to change the model outputs, i.e. should they only be used for model creation/testing and not final results?

Cheers,
Sylvan

Helpdesk

unread,
Oct 24, 2021, 4:55:07 AM10/24/21
to Sylvan Benaksas, R-inla discussion group
'eb' just use the mode for the hyperparameters hence ignores that
uncertainty. so the results will be slightly different
Reply all
Reply to author
Forward
0 new messages