8.6 Program Block: transformed parameters
The transformed parameters
program block consists of optional
variable declarations followed by statements. After the statements
are executed, the constraints on the transformed parameters are
validated. Any variable declared as a transformed parameter is part
of the output produced for draws.
Any variable that is defined wholly in terms of data or transformed data should be declared and defined in the transformed data block. Defining such quantities in the transformed parameters block is legal, but much less efficient than defining them as transformed data.
Constraints are for Error Checking
Like the constraints on data, the constraints on transformed parameters is meant to catch programming errors as well as convey programmer intent. They are not automatically transformed in such a way as to be satisfied. What will happen if a transformed parameter does not match its constraint is that the current parameter values will be rejected. This can cause Stan’s algorithms to hang or to devolve to random walks. It is not intended to be a way to enforce ad hoc constraints in Stan programs. See the section on reject statements for further discussion of the behavior of reject statements.