biodiverse / spOccupancy

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

R session aborted with observational level covariates #11

Closed Xuletajr closed 1 year ago

Xuletajr commented 2 years ago

Hi Jeff,

I am running a multi-species occupancy models using "msPGOcc" function. The msPGOcc is working well for model with a null model (intercept only) and with site-level covariates. However, when I add observational-level covariates (e.g., Julian day) for detection portion of the model the R session is aborted.

Do you any idea what could have caused this issue?

Thank you very much for your attention.

image

doserjef commented 2 years ago

Hi José,

Thanks for reaching out. Here are a few ideas as to what could be going on:

  1. The multi-species models can require a decent amount of memory to store the resulting objects, in particular if you have a lot of species and/or sites. How many sites/species do you have? Have you run multiple multi-species models in the same R session? If so, you may have run out of memory to save the objects (depending on how big your data set is). In that case, I would recommend running the models in different R sessions and saving the resulting objects to then analyze later on.
  2. Since the null model and site-level covariates model worked, it could be a problem in the formatting of the detection covariates. Make sure the observation-level covariates are included in the det.covs object of the data argument as site x visit matrices. Also, do you have a lot of missing values in the data (i.e., different numbers of visits at each site?) msPGOcc() checks for misalignment between the NA values in det.covs and the detection-nondetection data, but it could have missed something.
  3. Have you standardized the covariate values (either directly in the data or in the occ.formula and det.formula arguments? Sometimes if there are large numbers in the covariate values this can lead to problems with the model fitting.

If none of those thoughts help figure out what's going on, feel free to send me your code and data and I can try to reproduce the error to see what's going on.

Jeff

Xuletajr commented 2 years ago

Hi Jeff,

thank you very much for fast reply.

  1. I have 85 species, 120 sites and 89 sampling days with very unbalnced design (the sites were sampled from 14 to 48 days). I have run just one multi-species model in each R session.
  2. The formatting of the detection covariates seems ok for me (i.e., sites x sampling days). Yes, I have a lot of missing values in the data, since I am using data from automated recording devices that were deployed during different periods in the field. I've checked the position of the NA values in det.covs and the detection-nondetection data, and they look identical (e.g. identical(which(is.na(y[1,,])), which(is.na(sampling_day))) is resulting TRUE).
  3. Yes, I have standardized the covariate values directly in the data. I had some issues trying to standardize in the occ.formula and det.formula arguments.

I'll check if I can share the data with you. I asked for permission to do so.

José

doserjef commented 2 years ago

We determined this was a problem related to the repeated surveys at each site. All spOccupancy functions assumed the data were formatted such that the dimension of the detection-nondetection data corresponding to repeat visits was equal to the maximum number of repeat surveys at any given site. This leads to problems when the repeat visits are supplied as was done in this case, with the 89 visits corresponding to different sampling days and each site only surveyed at a subset of those sampling days. This is now fixed in the GitHub development version of the package, where I have updated all single-species and multi-species functions to work in this case. I'm leaving the issue open for now until I get the updated version on CRAN (likely in a month or so). Thanks again to José for raising this issue.

doserjef commented 1 year ago

Updated on CRAN in v0.5.0