# Mixed discrete-continuous priors

**URL:** <https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262>\
**Category:** Modeling\
**Created:** [October 6, 2019, 3:57pm UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262 "2019-10-06T15:57:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@roman](https://discourse.mc-stan.org/u/roman)\
**Post date:** [October 6, 2019, 3:57pm UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/1 "2019-10-06T15:57:21Z")

</div>

Consider a model with a prior p(\theta) = \alpha \delta(\theta) + (1-\alpha), \theta\in[0,1], where \alpha is a known parameter and \delta is Dirac’s delta, and possibly other unknown parameters as well. The particular form of the likelihood doesn’t matter much here I think.

The goal is to be able to compute expectations w.r.t. the posterior \theta|D.

Are there any tricks to encode this in Stan, or to encode only the continuous part and then somehow combine with the discrete part outside of Stan? All I can come up with requires calculating the total evidence p(D).

---

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/emiruz/32/5518_2.png) [@emiruz](https://discourse.mc-stan.org/u/emiruz)\
**Post date:** [October 6, 2019, 8:58pm UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/2 "2019-10-06T20:58:45Z")

</div>

If you want to know how a Dirac delta can be encoded in a Stan model there is a HGP example from Stancon 2017 which makes use of the Dirac function here:

> **[stancon2017-trangucci-hierarchical-gps.pdf](https://mc-stan.org/events/stancon2017-notebooks/stancon2017-trangucci-hierarchical-gps.pdf)**
>
> 45.67 MB

---

<div class="post-metadata">

**Author:** ![roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@roman](https://discourse.mc-stan.org/u/roman)\
**Post date:** [October 7, 2019, 5:49am UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/3 "2019-10-07T05:49:14Z")

</div>

Thanks, that’s an interesting paper.

But if you are referring to this part

 ![Screenshot_20191007_084109](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/4054c0bf9f90bbd56b1d59f322620905b5fac10a.png)

then they misnamed it — that’s [Kronecker delta](https://en.wikipedia.org/wiki/Kronecker_delta), which is a discrete analog of [Dirac delta](https://en.wikipedia.org/wiki/Dirac_delta_function). So I don’t think that helps with my problem.

---

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/emiruz/32/5518_2.png) [@emiruz](https://discourse.mc-stan.org/u/emiruz)\
**Post date:** [October 7, 2019, 7:50am UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/4 "2019-10-07T07:50:50Z")

</div>

Could you perhaps try put it into a Stan model with some example data and point out what isn’t working for you? It’ll make it much easier to help. So far as I can tell the Dirac delta function is actually a valid continuous density distribution so I can’t see what the problem is right now; but perhaps I’m missing something.

---

<div class="post-metadata">

**Author:** ![roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@roman](https://discourse.mc-stan.org/u/roman)\
**Post date:** [October 7, 2019, 8:10am UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/5 "2019-10-07T08:10:20Z")

</div>

> [@emiruz](#):
>
> Could you perhaps try put it into a Stan model with some example data and point out what isn’t working for you?

Well, the closest pseudocode would be something like

```stan
data {
  real<lower=0,upper=1> alpha;
  ...
}
parameters {
  real<lower=0,upper=1> theta;
  ...
}
model {
  if (theta == 0)
    target += Infinity + log(alpha);
}

```

> [@emiruz](#):
>
> So far as I can tell the Dirac delta function is actually a valid continuous density distribution so I can’t see what the problem is right now

It is not; the density is zero almost everywhere and yet it integrates to 1 (hence `Infinity` above). It can be approximated with a very narrow Gaussian (or in this case Beta), but (1) a fixed approximation means there will be no convergence to the target posterior no matter how many samples you draw, and (2) I’m not sure Stan will handle such a narrow Gaussian well.

In plain English, the prior belief I am trying to express is “there is probability \alpha that p is exactly zero; and with probability 1-\alpha it’s somewhere else in [0,1]”.

---

<div class="post-metadata">

**Author:** ![emiruz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/emiruz/32/5518_2.png) [@emiruz](https://discourse.mc-stan.org/u/emiruz)\
**Post date:** [October 7, 2019, 9:41am UTC](https://discourse.mc-stan.org/t/mixed-discrete-continuous-priors/11262/6 "2019-10-07T09:41:44Z")

</div>

Interesting, and so specific . I’d be interested to know how this is solved but don’t have an answer for you . I’ll look into zero-inflated continuous distributions particularly the zero inflated beta distribution given your constraints.
