This is an old version, view current version.
10.3 Upper bounded scalar
Stan uses a negated logarithmic transform for upper bounds.
Upper bound transform
If a variable \(X\) is declared to have an upper bound \(b\), it is transformed to the unbounded variable \(Y\) by
\[ Y = \log(b - X). \]
Upper bound inverse transform
The inverse of the upper bound transform converts the unbounded variable \(Y\) to the variable \(X\) bounded above by \(b\) through
\[ X = b - \exp(Y). \]
Absolute derivative of the upper bound inverse transform
The absolute derivative of the inverse of the upper bound transform is
\[ \left| \, \frac{d}{dy} \left( b - \exp(y) \right) \, \right| = \exp(y). \]
Therefore, the density of the unconstrained variable \(Y\) is defined in terms of the density of the variable \(X\) with an upper bound of \(b\) by
\[ p_Y(y) = p_X \!\left( b - \exp(y) \right) \cdot \exp(y). \]