Hi Stan Experts,
I have a question regarding when constraints are checked and the resulting distribution. Looking at section 5.6 in the Stan Reference Manual did not quite answer my question and I’m not too familiar with the inner workings of Stan, so any insight will be greatly appreciated.
Here is a snippet of my Stan code:
parameters {
real<lower=0> alpha;
}
model {
alpha ~ normal(1, 5);
}
Alpha is drawn from a normal distribution and is constrained / truncated with real<lower=0>. I would like to figure out at what point the constraints are checked and how this influences the resulting distribution. (I am trying to replicate / simulate this distribution in python in the same way that Stan does).
-
Alpha is drawn from the normal(1, 5). Here, with no constraints, it is possible to have a sample < 0. Is this sample discarded immediately? This would continue until a value that satisfies the constraint is found. With repeated samples, I believe this would be equivalent to sampling from a normal distribution and subsetting the samples to be > 0.
-
Alpha is drawn from a truncatedNormal(1, 5) where the truncation is at 0. (Which in this case could be substituted with halfNormal since the truncation is at 0).
It is my understanding (from quick simulations) that options 1 and 2 would produce different distributions. Can anyone give any insight about how Stan deals with constraints with regard to sampling from distributions when they are specified according to the code above (parameter & model blocks)?
Thanks in advance for your insight!