You have to be more specific. If we write
parameters {
real<lower = 0> sigma;
then the underlying parameter over which Stan samples is log(sigma)
. But, every iteration, the constrained value sigma
is calculated using exp()
. Then sigma
is the only variable exposed. To get back to the unconstrained variable, you’d have to do log(sigma)
, but it’s already too late.
Now if you want to do this yoursekf, it’s easy:
parameters {
real log_sigma;
transformed parameters {
real<lower = 0> sigma = exp(log_sigma);
If you want to put a distribution on sigma
, you also need the Jacobian adjustment
model {
target += fabs(inv(sigma)); // Jacobian adjustment
But if you just wnat to put a prior on log_sigma
, such as a normal to imply sigma
is lognormal, that you can do. But you still can’t put the resulting sigma
into a normal distribution if it underflows to zero.