Hi All,
First off apologies this is a cross post from stack overflow as I have only just found this forum !!
EDIT: removed link to original post as apparently new users can only have 2 links per post >.<
I am currently using R-Stan to fit a multivariate normal distribution. The current model is
b ~ MVN ( 0 , Sigma )
where
b = ( x1 , x2 , x3 )
0 = ( 0 , 0 ,0 )
I am able to build the co-variance matrix using the following:
parameters {
row_vector b[3];
real<lower=0> b_sigma[3];
real<lower=-1, upper=1> b_rho[3];
}
transformed parameters {
matrix[3,3] b_SIGMA;
b_SIGMA[1,1] = b_sigma[1] ^ 2;
b_SIGMA[2,2] = b_sigma[2] ^ 2;
b_SIGMA[3,3] = b_sigma[3] ^ 2;
b_SIGMA[1,2] = b_rho[1] * b_sigma[1] * b_sigma[2] ;
b_SIGMA[2,1] = b_rho[1] * b_sigma[1] * b_sigma[2] ;
b_SIGMA[3,1] = b_rho[2] * b_sigma[1] * b_sigma[3];
b_SIGMA[1,3] = b_rho[2] * b_sigma[1] * b_sigma[3];
b_SIGMA[2,3] = b_rho[3] * b_sigma[2] * b_sigma[3];
b_SIGMA[3,2] = b_rho[3] * b_sigma[2] * b_sigma[3];
}
However this to me seems incredibly manual and inefficient. Is there a proper or recommended way for building such variance structures ?
On a highly related note PROC MIXED in SAS (see Table 56.15) offers a wide array of “out the box” variance structures such as unstructured, compound symmetry, autoregressive , etc. Is there an equivalent in STAN or will I need to manually construct them each time ?
NOTE: As this question was more theoretical I assumed that data + a fully working example was not beneficial. I am happy to provide data + fully working example though if people would like to play around with it or deem otherwise.