Random Effects and Spatial factor in single season occupancy model

31 views
Skip to first unread message

Víctor Beltrán Francés

unread,
Jun 19, 2025, 2:54:16 AMJun 19
to spOccupancy and spAbundance users
Dear group,

I am running a single-season occupancy model to investigate the occupancy patterns of Macaca maura along their complete geographic distribution in Sulawesi (Indonesia). We collected data in 206 sites (1 site = 2 km²) along the distribution of the species, which is around 20.000 km². However, I'm finding some issues related to the goodness-of-fit test, as the Bayesian p-values are 0 or <0.05, even with spatial factor occupancy models (spPGOcc). The only way that I have to obtain Bayesian p-value ≈ 0.5 is by including sampling location ID (sl) as a random effect in the detection model. But if I do include the random effect, the random effect seems to have a strong effect on the model. Thus, I am not sure if including the random effect would be recommended in this case, or if I should include another random effect different from sl. Prior to running the models in spOccupancy, I used unmarked, where I did not find goodness-of-fit issues with the McKenzie-Bailey Test. Also, if I include the random effect, the results between unmarked and spOccupancy models vary significantly, especially for selecting the best model based on WAIC.

These are the formulas for the best model (in unmarked I was able to include an interaction between treeheight and edge in a stable model):
occ.formula = ~ scale(treeheight)+scale(edge)+scale(hfi),
det.formula = ~ scale(slope)+I(scale(slope)^2)+scale(forest250)

And for the spatial factor, the best setting was using 5 neighbors.

Simple Occupancy Model:
nonspatialOM.JPG

Random Effect Occupancy Model:
randomeffectOM.JPG


Spatial Factor Occupancy Model:
spatialOM.JPG


What do you think would be the best approach? Do you recommend any changes in the modeling to try to find a better fit for the models?

Thank you very much for your help,
Best
Víctor

Víctor Beltrán Francés

unread,
Jun 19, 2025, 11:51:22 AMJun 19
to spOccupancy and spAbundance users
Hi again,

I forgot to add that I've tried to include more (and less) covariates to both formulas, and Bayesian p-value issues still continue. Also, in all cases, trace plots show convergence for all covariates.

Best,
Víctor

Jeffrey Doser

unread,
Jun 22, 2025, 5:28:26 PMJun 22
to Víctor Beltrán Francés, spOccupancy and spAbundance users
Hi Victor,

Thanks for the question. The differences that you are finding between GoF assessment in unmarked and spOccupancy are interesting. What settings were you using when doing posterior predictive checks in spOccupancy? The values you set the argument to will help you in assessing how to go about assessing why the model is not fitting ideally. Take a look at the output from the ppcOcc() function besides just the summary p-value to try and determine where and why things may not be fitting well. The fact that the detection random effect improves the model fit suggests to me that there is unmodeled heterogeneity in the detection portion of the model that may not be getting picked up by the McKenzie-Bailey test in unmarked. However, exploring the output from ppcOcc will provide a bit more context on what could be going on. Take a look here for some example plots you could look at to try and assess better what's going on. It could also be insightful to try and fit the model with the site-level detection random effect in unmarked to see if the results are substantially different from what you get in spOccupancy when including the random effect.

Jeff

--
You received this message because you are subscribed to the Google Groups "spOccupancy and spAbundance users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spocc-spabund-u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/spocc-spabund-users/ed0832dc-dbfd-40ac-bd2e-481370d39397n%40googlegroups.com.


--
Jeffrey W. Doser, Ph.D.
Assistant Professor
Department of Forestry and Environmental Resources
North Carolina State University
Pronouns: he/him/his

Víctor Beltrán Francés

unread,
Jun 23, 2025, 11:50:38 PMJun 23
to spOccupancy and spAbundance users
Dear Jeff,

Thanks for your reply. For the posterior predictive check, I am using both the Freeman and chi-square tests and both groups, site and survey. As you mentioned, the heterogeneity seems to be inter-site, as p-values are low within group 1 (sites), but they are around 0.5 within group 2 (surveys). I tried to add different ecological and site-related covariates, but model fitness does not improve. In unmarked the model does not estimate coefficients when including (1|sl) in the detection model, as it returns NaN to all the covariates in both the occupancy and detection models. I check posterior predictive results from ppcOcc() and the number of sites that are farther than -0.5 points from the expected value are around 30 (of 206 sites). I think variability could be an effect of site-differences in macaque density, human pressure (hunting, poisoning), dog presence. Unfortunately, we do not have data about that to include them as covariates in the model. Do you think tuning spatial factor priors in spPGOcc() might help to account for this variability?

Thanks,
Best,
Víctor

Jeffrey Doser

unread,
Jun 26, 2025, 5:27:59 AMJun 26
to Víctor Beltrán Francés, spOccupancy and spAbundance users
Hi Victor,

Thanks for the additional details. If you think that the other factors you laid out there (particularly the density) may be causing heterogeneity in detection probabiity, then it seems very reasonable to me to include the random site effect on detection probability. In many ways, including a random site effect on detection is very intuitive as it can attempt to account for detection heterogeneity due to abundance. I am hopeful that one day I'll be able to get an option for including a spatial random effect on detection probability in the model to try to do this (as opposed to just the unstructured effect) but that is likely a ways away. Fitting a spatial model with spPGOcc would only help if the variation not currently explained in the model is related to the occupancy probability of the species, and not the detection probability (since the detection component of the spatial and non-spatial models implemented in spOccupancy are identical).

Jeff

Reply all
Reply to author
Forward
0 new messages