This is partly a Stan question and partly a stats question.
For Stan, you need to define any derived quantities that depend on parameters in either the transformed parameters block or as a local variable in the model block (or in generated quantities if the log density doesn’t depend on the output).
The stats problem is more subtle and is going to depend on what f
is and other information you have in the model. Typically, you need a Jacobian adjustment when changing variables this way and trying to put a distribution on the transform. Here, you need to be able to map from x
back to z1
and z2
. The manual explains how this works in the chapter on transformed parameters and also the entire chapter on how the internal transform works.