bayesian - R STAN - How to formulate multivariate co-variance matrix -
i using r stan fit multivariate normal distribution. current model is
b ~ mvn ( 0 , sigma )
where
b = ( x1 , x2 , x3 )
0 = ( 0 , 0 ,0 )
i able build co-variance matrix using 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 me seems incredibly manual , inefficient. there proper or recommended way building such variance structures ?
on highly related note proc mixed in sas offers wide array of "out box" variance structures such unstructured, compound symmetry, autoregressive , etc. there equivalent in stan or need manually construct them each time ?
note: question more theoretical assumed data + working example not beneficial. happy provide data + working example though if people play around or deem otherwise.
your construction isn't guaranteed produce positive definite matrix. there's cov_matrix
type , cholesky_cov_matrix
type guarantee positive definiteness. latter goes themulti_normal_cholesky
parameterization. recommend scaling correlation matrix, there parallel types.
there aren't out of box variance structures in stan. there several within rstanarm, may more you're looking for. higher-level language stan , lets specify autoregressive , spatial models various hierarchical structure. , automatically preconditions qr decomposition.
Comments
Post a Comment