inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
73 stars 21 forks source link

error when run a LGCP model with inlabru 2.5.2.9000 #141

Closed rita86ribeiro closed 2 years ago

rita86ribeiro commented 2 years ago

Hi,

I am using inlabru to predict the distribution of bat roosts. I fitted my data with a LGCP with inlabru dev 2.3.1.9000, and the model worked ok. However, I have now upgraded to the new dev versions of INLA and of inlabru and I can't run the same LGCP models - R does not runs. With verbose = TRUE, R does not progress and after some minutes results this message "Error in rep(k, sum(nonzero)) : invalid 'times' argument". If I tried to run the gorillas exercise, all works ok, but if I only model with the intercept term (e.g. comp <- coordinates ~ Intercept (1)), the same message happens. However, with the same dev versions, if I run a Poisson version of the model with bru() all works fine.

I have removed the dev versions and installed the latest stable versions, and I have the same issue as previously described. I don't understand what is happening.

This is my sessionInfo()with the stable versions of INLA and inlabru:

R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.0

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] parallel stats graphics grDevices utils datasets methods base

other attached packages: [1] ggpolypath_0.1.0 ggpubr_0.4.0 raster_3.5-15 rgdal_1.5-29 units_0.7-2
[6] sf_1.0-4 readxl_1.3.1 dplyr_1.0.8 ggplot2_3.3.5 RColorBrewer_1.1-3 [11] inlabru_2.5.2 INLA_22.03.16 sp_1.4-6 foreach_1.5.1 Matrix_1.3-4

loaded via a namespace (and not attached): [1] Rcpp_1.0.8.3 lattice_0.20-45 tidyr_1.2.0 class_7.3-19
[5] assertthat_0.2.1 digest_0.6.29 utf8_1.2.2 R6_2.5.1
[9] cellranger_1.1.0 plyr_1.8.7 backports_1.3.0 MatrixModels_0.5-0 [13] stats4_4.1.2 e1071_1.7-9 pillar_1.7.0 rlang_1.0.2
[17] rstudioapi_0.13 car_3.0-12 labeling_0.4.2 splines_4.1.2
[21] munsell_0.5.0 proxy_0.4-26 broom_0.7.12 numDeriv_2016.8-1.1 [25] compiler_4.1.2 pkgconfig_2.0.3 mnormt_2.0.2 tmvnsim_1.0-2
[29] tidyselect_1.1.2 tibble_3.1.6 codetools_0.2-18 fansi_1.0.3
[33] crayon_1.5.1 withr_2.5.0 wk_0.5.0 grid_4.1.2
[37] gtable_0.3.0 lifecycle_1.0.1 DBI_1.1.1 magrittr_2.0.3
[41] scales_1.1.1 KernSmooth_2.23-20 cli_3.2.0 carData_3.0-4
[45] farver_2.1.0 ggsignif_0.6.3 sn_2.0.0 ellipsis_0.3.2
[49] generics_0.1.2 vctrs_0.4.0 s2_1.0.7 iterators_1.0.13
[53] tools_4.1.2 glue_1.6.2 purrr_0.3.4 abind_1.4-5
[57] colorspace_2.0-3 terra_1.5-21 rstatix_0.7.0 classInt_0.4-3

Thank you Rita

finnlindgren commented 2 years ago

To support more complex models, the logic for +Intercept(1) unfortunately sometimes has trouble figuring out the required predictor size, which is why you get that error when that's the only component in some models. In those case, the easiest solution is make sure the component input is dynamically sized to match the (also dynamically sized) predictor. If the coordinate names are x and y, use +Intercept(x*0+1).

rita86ribeiro commented 2 years ago

Hi Finn,

Thank you so much for your prompt reply. The coordinate names are x and y. The model with just an Intercept term runs without error if I use Intercept (x*0+1). However, it takes too long to run and results in a negative DIC and Inf CPO. These are not the same results I obtained previously, and are not normal. I can't figure out why these differences. I will keep testing.

finnlindgren commented 2 years ago

Upgrade to the latest INLA version (22.04.09). Then also try with the option inla.mode="experimental".

rita86ribeiro commented 2 years ago

Hi Finn,

Thank you very much. I have upgrade to INLA 22.04.09 and used the option inla.mode="experimental", and the model runs ok now and the predictions are the expected ones. Thank you.