@martinmodrak suggested I post a link to this blog post on marginalizing over discrete parameters in Stan: https://mbjoseph.github.io/posts/2020-04-28-a-step-by-step-guide-to-marginalizing-over-discrete-parameters-for-ecologists-using-stan/
Summing discrete parameters out of a model can be a stumbling block for applied ecologists that are trying to transition to Stan. There are a few key steps in this transition (writing the joint density, writing the log joint density, translating it to Stan). Each step provides an opportunity for people to get lost, or to learn something new.
This post aims to help BUGS/JAGS/NIMBLE users learn to specify models with discrete parameters in Stan. It’s written for a less-technical audience, maybe at the risk of seeming too verbose to folks that already know this stuff.
Feedback is welcome (here, or feel free to open an issue on GitHub if you have specific suggestions/edits).