Any moderate sized covariance matrix has a good chance to become numerically problematic for some values of the structural parameters that Stan lands on during the leapfrom process. Basically, the advice is
- Parameterize things in terms of a Cholesky factor of a covariance matrix when possible
- If the error is due to numerical asymmetry, you can do something like
R = 0.5 * (R + transpose(R))
after filling it. - If the error is due to numerical indefiniteness, you can add a tiny positive constant to the diagonal of
R
after filling it or do something more complicated .