# Prior on real<lower=0,upper=1> with half mass in 0

Greetings,

I am trying to implement Joint Species Models where the variance covariance of regression coefficients is informed by a correlation matrix derived from species phylogenies. One parameter that needs to be estimated is

real<lower=0,upper=1> rho;

which measures the strength of the phylogenetic signal. Ovaskainen et al. in their software HMSC https://www.helsinki.fi/en/researchgroups/statistical-ecology/hmsc use for this parameter the following prior:
with probability 0.5, rho = 0,
with probability 0.5, rho ~ Uniform(0,1).

the idea behind this is to allow rho to be zero for the case when phylogeny does not influence parameter estimates.

Is there a way to define a prior in Stan that will behave similarly?
I have tried a beta with lots of mass near zero but it is not quite the same.

Check out the mixture modelling section of the Stan User’s Guide.

ah!

So it was as simple as

``````target += log_sum_exp(log(0.5) + beta_lpdf(rho|1, 1000), log(0.5) +  beta_lpdf(rho|1, 1));
``````

thank you!

1 Like

Actually, now that I think about it you should look at the section on zero inflation, which will show you how to use a conditional and avoid the `beta_lpdf(rho|1, 1000)` bit (which I presume was your hack to convey certainty of a value at zero).

Also, this bit is going to be constant regardless of rho, so you can compute it once in the `transformed data` section and just add it here.