# Occupancy modeling in Stan

**URL:** <https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292>\
**Category:** Publicity\
**Tags:** ecology\
**Created:** [August 16, 2019, 1:24pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292 "2019-08-16T13:24:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Erickson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/richard_erickson/32/5705_2.png) [@Richard\_Erickson](https://discourse.mc-stan.org/u/Richard_Erickson)\
**Post date:** [August 16, 2019, 1:24pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/1 "2019-08-16T13:24:17Z")

</div>

The purpose of this post is to raise awareness of my occupancy modeling work with RStan, help people find my work, and seek out possible collaborators to help other avoid reinventing the wheel. I also hope others would **please add links to your own tutorials on occupancy modeling with Stan**.

I am writing a set of tutorials on doing Occupancy Modeling with RStan. The tutorials are on GitHub ([link here](https://github.com/rerickson-usgs/StanOccupancyModelTutorials)). I am also in the process of putting the tutorials into an R Package (currently in rough shape on [GitHub](https://github.com/rerickson-usgs/rstanOcc)). My long term goal is to put all of the tutorials as Vignettes in the R Package.

I am motivated for my project by environmental DNA (eDNA) occupancy modeling (or occupancy modeling with sub-sampling). The models require at least 3-levels: Molecular detection (e.g., did qPCR detect the eDNA?); Sample capture (e.g., did you get eDNA in your water bottle?); and Site-level occupancy (e.g., is eDNA at the site?). I am currently working with USGS and USFWS scientists who use these 3-level models for their work and my tutorials builds up to them, starting with `glm()` in R before moving to Stan and occupancy models.

I have found that @jsocolar has posted a [nice tutorial](https://jsocolar.github.io/occupancyModels/) comparing JAGS to RStan (and @jsocolar, I invite you (and anyone else!) to collaborate with me on my projects). I also know that @mbjoseph has a nice tutorial on [Dynamic occupancy models in Stan](https://mbjoseph.github.io/posts/2018-12-27-dynamic-occupancy-models-in-stan/) and a paper using [SEM models with occupancy models in Stan](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4877056/).

---

<div class="post-metadata">

**Author:** ![mbjoseph](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mbjoseph/32/870_2.png) [@mbjoseph](https://discourse.mc-stan.org/u/mbjoseph)\
**Post date:** [August 16, 2019, 2:41pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/2 "2019-08-16T14:41:08Z")

</div>

Nice! Happy to hear this @Richard_Erickson. Note that my blog post is now directing folks to the BPA Stan implementations: [https://github.com/stan-dev/example-models/tree/master/BPA](https://github.com/stan-dev/example-models/tree/master/BPA)

---

<div class="post-metadata">

**Author:** ![Manuel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/manuel/32/5178_2.png) [@Manuel](https://discourse.mc-stan.org/u/Manuel)\
**Post date:** [August 23, 2019, 2:14pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/3 "2019-08-23T14:14:12Z")

</div>

I am very interested also to see any development of occupancy models with brms or rstanarm.

Manuel

---

<div class="post-metadata">

**Author:** ![Richard\_Erickson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/richard_erickson/32/5705_2.png) [@Richard\_Erickson](https://discourse.mc-stan.org/u/Richard_Erickson)\
**Post date:** [August 27, 2019, 8:59pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/4 "2019-08-27T20:59:20Z")

</div>

@Manuel I’m doing my own project independent of those. However, the package will avoid making people compile their own models (or serve as a starting place if they do want to create their!).

---

<div class="post-metadata">

**Author:** ![Manuel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/manuel/32/5178_2.png) [@Manuel](https://discourse.mc-stan.org/u/Manuel)\
**Post date:** [August 27, 2019, 10:01pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/5 "2019-08-27T22:01:59Z")

</div>

@Richard_Erickson that´s great. I will be very interested on see that. I am not very good on programming so I feel more confortable with brms.

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [September 9, 2019, 1:11am UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/6 "2019-09-09T01:11:00Z")

</div>

Thanks for posting. We can also provide a link in our external references page on our web site (where we link books and tutorials on Stan).

Also, I wrote a case study on the Dorazio and Royle (2006) model:

[https://mc-stan.org/users/documentation/case-studies/dorazio-royle-occupancy.html](https://mc-stan.org/users/documentation/case-studies/dorazio-royle-occupancy.html)

---

<div class="post-metadata">

**Author:** ![Richard\_Erickson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/richard_erickson/32/5705_2.png) [@Richard\_Erickson](https://discourse.mc-stan.org/u/Richard_Erickson)\
**Post date:** [September 13, 2019, 7:18pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/7 "2019-09-13T19:18:08Z")

</div>

Thank you @Bob_Carpenter. Once I get things more polished, I’ll seek to promote it on your resources page.

---

<div class="post-metadata">

**Author:** ![Richard\_Erickson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/richard_erickson/32/5705_2.png) [@Richard\_Erickson](https://discourse.mc-stan.org/u/Richard_Erickson)\
**Post date:** [November 3, 2021, 8:28pm UTC](https://discourse.mc-stan.org/t/occupancy-modeling-in-stan/10292/8 "2021-11-03T20:28:32Z")

</div>

As another resource: I recently learned about this package: [Bayesian Models for Data from Unmarked Animals using Stan • ubms (kenkellner.com)](https://kenkellner.com/ubms/)
