# What transformation does Stan use to constrain parameter between 0 and 1?

Hi,

I am wondering - when a parameter is declared as bounded between 0 and 1, what transformation does the Stan algorithm use to make the parameter unconstrained?

Thanks

It uses the log-odds function (\mathrm{logit})

And just to clarify, bc this was something I came to understand far too late in my Stan learning, all constraints are achieved in Stan by always using proposals that are unconstrained, then deriving the the value of any unconstrained parameter by using a transform while also adding behind the scenes the relevant increment to the log-probability associated with the transform, which enables the user to then express priors on the constrained parameter. So if you had:

//Stan-ish pseudo-code:
parameters{
real<constraint> x ;
}
model{
x ~ prior() ;
}


behind the scenes Stan implements:

//Stan-ish pseudo-code:
parameters{
real x_unconstrained ;
}
model{
x_unconstrained ~ constraint_jacobian() ;
real x = constraint_transform( x_unconstrained ) ;
x ~ prior() ;
}


and that’s necessary because for all but a narrow subset of
transforms, doing:

//Stan-ish pseudo-code:
parameters{
real y ;
}
model{
real z = transform( y ) ;
z ~ prior() ;
}


Would not yield the expected behaviour of samples for z reflecting the specified prior.