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

Fatal Error in R Session When Using tMsPGOcc for Multi-Species Multi-Season Occupancy Model #45

Closed Xuletajr closed 5 months ago

Xuletajr commented 6 months ago

Hello Jeff,

I am experiencing a fatal error in my R session when attempting to fit a multi-species, multi-season occupancy model (tMsPGOcc) for five coqui species. My data consists of detection-non-detection observations across 187 sites over a period of three years (I will soon have the data from the fourth year to incorporate). The code runs perfectly with the hbefTrends data object for both single and multiple species, as well as with the single-species multi-season occupancy model (tPGOcc) when applied to one species from my dataset (Eleutherodactylus coqui). However, it crashes with a fatal error when I try to use tMsPGOcc for the multi-species model.I have attempted various checks and minor adjustments to the data without success. I am attaching my code and a workspace containing the data for your review.

Any insights or suggestions you can provide would be greatly appreciated.

Thank you very much for your attention and collaboration.

Best wishes, José

Multi-species_multi-season_occupancy_model_JWRJ.zip

Xuletajr commented 6 months ago

Hi Jeff,

I would like to take advantage of this open issue to ask about the possibility of deriving estimates of colonization and extinction/persistence dynamics using the functions in the spOccupancy package. Is there any way to derive these parameters from the available functions?

Would you recommend any literature or have any suggestions for estimating the dynamics of colonization and extinction/persistence?

Any insights you can provide would be greatly appreciated.

Thanks

doserjef commented 6 months ago

Hi José,

Thanks for the note and for sharing your code/data. It seems like the problem here is actually related to a similar problem you helped me find a while back (#11 ) in a different model function. It turns out I didn't fix that problem in any of the multi-season, multi-species models (tMsPGOcc, stMsPGOcc, svcTMsPGOcc), which is why you were encountering this error. I have updated the functions and if you install the development version from GitHub everything should now work for you. Let me know if you have any troubles.

As far as your second comment goes: there is not really any easy way to estimate colonization/extinction dynamics in spOccupancy. The multi-season models in spOccupancy are not designed explicitly for looking at colonization and extinction dynamics, and so you won't be able to get any information on how covariates influence those processes when using spOccupancy. If you wanted to get estimates of colonization/extinction, you could try to derive those by manipulating the out$z.samples object (where out is the resulting model fit object from tMsPGOcc). You could do that by looking at the transitions from 1 to 0 (i.e., extinction) and the transitions from 0 to 1 to try and get some sort of estimate of colonization/extinction, although I've never done that and I'm not sure how exactly it would work. So, long story short, if colonization/extinction are your main interest you might be best trying to fit a multi-species dynamic occupancy model in JAGS/NIMBLE. I think Ken Kellner's ubms package has single-species dynamic occupancy models, so you could potentially check that out. I don't know of any papers off the top of my head that use multi-species dynamic occupancy models, but a quick google search shows there are multiple papers that have seemingly fit those types of models (e.g., https://www.nature.com/articles/s41586-020-2090-6 and https://esajournals.onlinelibrary.wiley.com/doi/full/10.1002/ecs2.2674).

Hope that helps, and thanks for bringing the error to my attention!

Jeff

Xuletajr commented 5 months ago

Hi Jeff,

I very much appreciate the quick response and solution. The function is working normally with the development version from GitHub. I would also like to thank you for your feedback on estimating colonization/extinction dynamics. I will delve deeper into this for projects that need to estimate these parameters, but for now, spOccupancy does a great job and it has been an essential package in my everyday work (it has helped me a lot).

Have a great week.

José

doserjef commented 5 months ago

Hi José,

Great, I'm very glad to hear it! I'll go ahead and close this issue but of course feel free to reach out again in the future if you run into any more problems.

Jeff