I think there are a two typos in Section 1.13 of the Stan User Guide, version 2.25.
For an older User Guide there was an open issue on GitHub as discussed here, but it’s closed now so I don’t really know where to post this.
In the Optimization through Cholesky Factorization section, there is this code in a code block:
transformed parameters {
matrix[J, K] beta;
beta = u * gamma + z * diag_post_multiply(L_Omega,tau);
}
Here, z
is a matrix, so one row of z
is a row vector (later defined to be standard (mv) normally distributed), thus we define a new variable \beta:=\Omega_L\mathrm{diag}(\tau), thus in column vector form: \beta'=\mathrm{diag}(\tau)\Omega_L'z'. But if we the figure out the variance of \beta, we find that \mathbb{V}[\beta']=\mathrm{diag}(\tau)\Omega_L'\Omega_L\mathrm{diag}(\tau). However, \Omega_L'\Omega_L\neq\Omega_L\Omega_L'=\Omega. Thus I think this should read
transformed parameters {
matrix[J, K] beta;
beta = u * gamma + z * diag_post_multiply(L_Omega', tau);
}
Another one of those comes a bit later in the lines of
Sigma_beta
= quad_form_diag(Omega, tau)
= diag_post_multiply(L_Omega,tau) * diag_post_multiply(L_Omega,tau)'
Here I think this should be
quad_form_diag(Omega, tau)
=\mathrm{diag}(\tau)\Omega\mathrm{diag}(\tau)=\mathrm{diag}(\tau)\Omega_L\Omega_L'\mathrm{diag}(\tau)=diag_pre_multiply(tau, Omega_L) * diag_pre_multiply(tau, Omega_L)'
I didn’t test this specific code, but I had the wrong versions in a model of mine and spend too long trying to find out why my estimates were off ever-so-slightly and then I applied the correction and everything works fine.