Error when sampling a transformed parameter - Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable

That is not an error, but rather a warning. If your code does not execute, then there is some other problem.

First, sampling statements do not imply something is being sampled. Rather a_mu ~ von_mises (4, 2); gets mapped to

increment the posterior kernel (in log units) by the logarithm of the Von Mises PDF for a_mu

except a_mu is a transformed parameter rather than a parameter so the warning above is telling you that if you continue you will not be drawing from the intended posterior distribution. The question is: If a_mu is distributed according to the Von Mises distribution, then what is the PDF of the parameter v_a_mu. The answer is the Von Mises PDF — written in terms of v_a_mu — multiplied by the absolute value of the determinant of the Jacobian matrix for the transformation from v_a_mu to a_mu. This change-of-variables process is talked about a lot in the Stan User Manual and is also discussed at

So, you would need to increment target by the logarithm of that absolute determinant. Usually it is easier to reformulate your problem so that the priors can be applied directly to the things declared in the parameters block.

1 Like