doserjef / spOccupancy

Single-species, Multi-species, and Integrated Spatial Occupancy Models
https://www.jeffdoser.com/files/spoccupancy-web/
GNU General Public License v3.0
51 stars 8 forks source link

Memory errors when using `predict` for models with the same variable as a fixed and random effect #30

Open doserjef opened 1 year ago

doserjef commented 1 year ago

A memory error will occur when predicting for models that use the same variable as a fixed effect and unstructured random effect in the model (e.g., a linear year trend and a random, unstructured effect of year). This occurs for all spOccupancy model types. This is currently fixed on the development version for two model types (svcTMsPGOcc and stMsPGOcc), and I will fix this for additional model types within the next few weeks. I will update this when all model types are fixed on GitHub, and then eventually fixed on the next CRAN version. Thanks to Liam Kendall for making me aware of this problem.

doserjef commented 6 months ago

This error still exists for all model types except svcTMsPGOcc and stMsPGOcc. A simple, but somewhat clunky, solution to this problem is to supply two different variables to occ.covs when fitting the model and subsequently doing prediction. For example, if you want to fit a multi-season model with a linear trend for years as well as an unstructured random effect for years, then you can supply two identical variables to occ.covs with slightly different names (e.g., years and years.random), fit the model with the two identical variables with different names (e.g., occ.formula = ~ years + (1 | years.random)), and then generate the prediction design matrix with the same structure.

I am not updating this functionality in v0.7.3 that will be released on CRAN in April 2024, but rather I am waiting to update this for when I add in random slope functionality. I'll keep this issue open until that happens.