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 7 forks source link

R session fatal error occurs when using intMsPGOcc #40

Closed RachHus closed 6 months ago

RachHus commented 6 months ago

Hi Jeff,

I'm running into a fatal error in R when I use the intMsPGOcc function. I've been looking into potential causes based on your discussion with Xuletajr: https://github.com/Xuletajr. Also, the function seems to work fine with a simulated dataset of similar size (see simulation.R in the attached zip file). However, when I try to run it with my actual data, the error occurs.

I'd be very grateful if you could take a look at my attached R code and data. error examples.zip

Any insights you might have would be greatly appreciated.

Thank you.

RachHus commented 6 months ago

My data is a detection-non detection data of odonata species. Sites are 1km-resolution grids and there are duplicate sites from two data sources, which represent stream and estuary surveys, respectively. Each detection represents the integrated results of surveys conducted on a yearly basis in each 1km grid site. And it has three detection variables: SC: the number of surveys per year, S1: a dummy variable for spring surveym S2: a dummy variable for fall survey.

doserjef commented 6 months ago

Hi @RachHus

Thanks very much for posting this and for supplying everything to easily reproduce the error. That was very helpful!

The problem you were encountering was a bug in intMsPGOcc() that occurred under certain circumstances of how the data were formatted. The error was related to #11. In particular, intMsPGOcc() was assuming that at least one of the sites in each data set was sampled across every single replicate survey. In your case, your "replicates" correspond to years (I think), and there is no site in the second data set in your integrated "data.list" object that was sampled over all 12 years. This was not the case with the simulated data, which is why you weren't getting an error there.

I have fixed this issue in the development version of the package on GitHub, which will be on CRAN in the next couple of weeks. If you install this most recent version of the package from Github with devtools::install_github("doserjef/spOccupancy"), then you should be able to successfully run the model with your data set. Let me know if that doesn't work for you.

Thanks again for bringing this to my attention, and apologies for the inconvenience!

Jeff

RachHus commented 6 months ago

Thank you very much for you prompt answer!! I'm glad that my data helped you to update the package. Would it be appropriate to continue using my "data.list" for building occupancy models with the updated spOccupancy package?

P.S. I realize I should've provided the below R code flie. occupancy_model_example.zip This file contains the R code for running an occupancy model using my data. I'm shraing this, thinking you might need it for any further insights or adjustments.

Thank you again.

Francis

doserjef commented 6 months ago

Hi Francis,

Yes, you should now be able to use the "data.list" format exactly as you had it for fitting the models with the new version.

Kind regards,

Jeff