spOccupancy tMsPGOcc() worked example?

102 views
Skip to first unread message

Jarrad Barnes

unread,
Mar 25, 2024, 8:54:49 PMMar 25
to hmecology: Hierarchical Modeling in Ecology
Hi all, I'm dipping my toe into the spOccupancy package as I'm interested in developing a multi-species multi-season occupancy model, but I'm swimming a bit. I'm familiar with occupancy models through other packages (notably unmarked and camtrapR), but spOccupancy is a bit of a different beast for me. I've played through the simulated data for tMsPGOcc() but I would really like to see a worked example with real data so I can see how I might shape my own dataset to this function. I haven't had any luck online finding one, but I'm hoping there might be someone or something that can provide a direction with this. Thanks for any help/insight. Jarrad

Jeff Doser

unread,
Mar 29, 2024, 9:14:04 AMMar 29
to Jarrad Barnes, hmecology: Hierarchical Modeling in Ecology
Hi Jarrad,

I've attached a script that walks through an example using tMsPGOcc() with the Hubbard Brook bird data that is included as part of the package. I'm hoping at some point to put together a vignette on the package website that walks through the multi-species, multi-season models, but in the meantime, you might also take a look at this data formatting vignette (which is for single-season models but could be adapted accordingly) and this vignette on single-species multi-season models (which are very similar in form to the multi-species functions).

Hope that helps!

Jeff

On Mon, Mar 25, 2024 at 8:54 PM Jarrad Barnes <jarrad...@gmail.com> wrote:
Hi all, I'm dipping my toe into the spOccupancy package as I'm interested in developing a multi-species multi-season occupancy model, but I'm swimming a bit. I'm familiar with occupancy models through other packages (notably unmarked and camtrapR), but spOccupancy is a bit of a different beast for me. I've played through the simulated data for tMsPGOcc() but I would really like to see a worked example with real data so I can see how I might shape my own dataset to this function. I haven't had any luck online finding one, but I'm hoping there might be someone or something that can provide a direction with this. Thanks for any help/insight. Jarrad

--
*** Three hierarchical modeling email lists ***
(1) unmarked: for questions specific to the R package unmarked
(2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
(3) HMecology (this list): for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
---
You received this message because you are subscribed to the Google Groups "hmecology: Hierarchical Modeling in Ecology" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hmecology+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hmecology/a1c9d8cb-18bd-4189-a6a4-3c70372ee746n%40googlegroups.com.
hbef-tMsPGOcc.R

Jarrad Barnes

unread,
Mar 29, 2024, 9:14:09 AMMar 29
to Jeff Doser, hmecology: Hierarchical Modeling in Ecology
Thanks Jeff, appreciate you replying to this so quickly. I'll take a good look at everything you've sent/suggested. Jarrad
--

Jarrad Barnes

unread,
Apr 9, 2024, 9:38:20 AMApr 9
to hmecology: Hierarchical Modeling in Ecology
Hi Jeff, I've managed to work through and adapt the code you've provided right up to running the tMsPGOcc function and I'm running across two issues:

1) I get an "error in colMeans [...] x must be numeric" error. As far as I can tell this is because several of my occupancy covariates are factors. I assume it is possible to use factors in the model, as for other occupancy models, and I'm just missing something?

2) When I try to run the function without factors, it begins to run but R Studio terminates as soon as the first chain begins. Is this a common occurrence? Happy to provide any code, data, etc. that might help pinpoint the problem. For what it's worth, in case it's a memory issue, I'm working with a dataset of 17 species, over 9 primary sampling periods, with 21 secondary sampling periods per primary.

Thanks,
Jarrad

Jeff Doser

unread,
Apr 10, 2024, 12:08:57 PMApr 10
to Jarrad Barnes, hmecology: Hierarchical Modeling in Ecology
Hi Jarrad,

Yes, you should be able to include factors in the model. They can either be supplied as a factor directly in "occ.covs" or "det.covs", or you can specify them as a numeric or categorical in "occ.covs"/"det.covs" and then include them in the model formula with the factor() function (e.g., occ.formula = ~ factor(habitatType)).

As far as the second problem goes, that could be related to a problem in an older version in the package. Under certain circumstances, the model could fail to run across multiple chains when specifying the MCMC criteria in a specific manner (see this github issue here). If you install the latest spOccupancy version from CRAN then I think that should go away.

Feel free to send me your code/data and I can try and debug if you still can't get it to work. There could potentially be other formatting issues that are leading to the problems.

Jeff

Jarrad Barnes

unread,
Apr 16, 2024, 9:43:21 PMApr 16
to hmecology: Hierarchical Modeling in Ecology
Thanks Jeff, I'll give those things a try and see how I get on. Hopefully it will all be smooth sailing, otherwise you may hear from me one more time ... !

Jarrad

Reply all
Reply to author
Forward
0 new messages