# Spike and Slab question

**URL:** <https://discourse.mc-stan.org/t/spike-and-slab-question/25890>\
**Category:** brms\
**Created:** [January 6, 2022, 5:36pm UTC](https://discourse.mc-stan.org/t/spike-and-slab-question/25890 "2022-01-06T17:36:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [January 6, 2022, 6:11pm UTC](https://discourse.mc-stan.org/t/spike-and-slab-question/25890/2 "2022-01-06T18:11:07Z")

</div>

Stan does not support integer parameters; these need to be marginalized out. However, this generally doesn’t work well for the spike and slab, and it’s often (but not universally) recommended to use a horseshoe prior as a viable alternative. For more, see

- [Sparsity Blues](https://betanalpha.github.io/assets/case_studies/modeling_sparsity.html)
- [7 Latent Discrete Parameters | Stan User’s Guide](https://mc-stan.org/docs/2_28/stan-users-guide/latent-discrete.html)
- [Rao-Blackwellization and discrete parameters in Stan | Statistical Modeling, Causal Inference, and Social Science](https://statmodeling.stat.columbia.edu/2020/01/29/rao-blackwellization-and-discrete-parameters-in-stan/)
- [Maxwell B. Joseph: A step-by-step guide to marginalizing over discrete parameters for ecologists using Stan](https://mbjoseph.github.io/posts/2020-04-28-a-step-by-step-guide-to-marginalizing-over-discrete-parameters-for-ecologists-using-stan/)

See also your earlier post here

- [Spike and Slab redux](https://discourse.mc-stan.org/t/spike-and-slab-redux/24970)

And this post

- [Error when fitting the spike and slab priors - #2 by Christopher-Peterson](https://discourse.mc-stan.org/t/error-when-fitting-the-spike-and-slab-priors/18488/2)

Note also that in your code where you have

```
beta1 ~ lambda*slab+(1-lambda*spike);

```

you are using the `~` sampling notation but the right-hand side is not a distribution (it’s just a number). This is in one sense a secondary concern since the spike-and-slab probably isn’t achievable in the way you want in the first place. In another sense, it’s important to understand what `~` does and why statements like this one don’t mean anything in the Stan language to support your future modeling endeavors in Stan.

---

_[View the full topic](https://discourse.mc-stan.org/t/spike-and-slab-question/25890)._
