Fitting community occupancy models with spOccupancy

120 views
Skip to first unread message

Marc Kery

unread,
Feb 14, 2024, 8:01:41 AM2/14/24
to hmec...@googlegroups.com
Dear all,

I just put together some example code that shows how to use R package spOccupancy to fit community occupancy models to an example data set contained in the AHMbook package; happy to share here.

In it, we use a data set with 145 species observed in at least one of 266 1km2 quadrats in the Swiss breeding bird survey MHB in the year 2014. We then use spOccupancy function msPGOcc() to fit two community occupancy models to this data set. The first model is a Null model which for each species just contains an intercept for occupancy and detection, respectively, and where the sets of 145 occupancy and detection parameters are each assumed to be drawn from their own Normal distribution with estimated hyperparameters. The latter represent the community in the model, and the values of the hyperparameters characterize the community in terms of its mean and its species-to-species variance. In the second model we add as species-specific random effects the effects of elevation and forest cover into the occupancy part of the model, and of date and survey duration in the detection part of the model.

These are the very powerful community models discussed in the latter parts of Chapter 11 in the AHM1 book (without data augmentation). spOccupancy now allows us to fit them within 20 minuters rather than 10 hours, as needed when fitting them with JAGS. In addition, we get posterior samples for the z (= species by site presence/absence) matrix. Thus, you could stick the posterior samples of z into any community ecology software such as many functions in package vegan and thereby obtain (1) measures of richness and community composition that are corrected for imperfect detection and (2) a whole posterior distribution for each quantity that vegan gives you.

Finally, if this type of model is important for your work, you might consider our workshop at Sempach in June 2024, where Jeff Doser will cover these models and many more, especially spatial versions of single- and multispecies occupancy and abundance models (http://www.phidot.org/forum/viewtopic.php?f=8&t=4514&sid=27037d3f81a72ca34270000ce9b2fb75).

Best regards  --- Marc
The_function_msPGOcc_with_MHB_data.R
Reply all
Reply to author
Forward
0 new messages