Multilevel model with covariance of 3 variables

Hi there,

I’m not sure I completely understand what you mean, but if I understand it right you would like to use multiple correlated random effects. The way I would probably approach that is by putting an LKJ prior on the covariance of the random effects. This example has only two correlated coefficients, but if instead of:

    chol, corr, stds = pm.LKJCholeskyCov("chol", n=2, eta=2.0, sd_dist=sd_dist, compute_corr=True)

you write

    chol, corr, stds = pm.LKJCholeskyCov("chol", n=3, eta=2.0, sd_dist=sd_dist, compute_corr=True)

you will get a LKJ prior on a covariance matrix for three random variables rather than 2. You can then use that Cholesky factor to put a prior on your coefficients, e.g.:

vec = pm.MvNormal("coefs", mu=np.zeros(3), chol=chol, shape=(n_buildings, 3))

this should give you n_buildings vectors, each of length 3, and estimating the covariance between these. Of course the mean doesn’t have to be zero, you could do something else.

Let me know if that makes sense or this is not what you were looking for!

1 Like