# Dimensions in Multivariate Normal Exa

**URL:** <https://discourse.pymc.io/t/dimensions-in-multivariate-normal-exa/9407>\
**Category:** General\
**Created:** [May 12, 2022, 8:18am UTC](https://discourse.pymc.io/t/dimensions-in-multivariate-normal-exa/9407 "2022-05-12T08:18:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeti](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jeti/32/7206_2.png) [@jeti](https://discourse.pymc.io/u/jeti)\
**Post date:** [May 12, 2022, 8:18am UTC](https://discourse.pymc.io/t/dimensions-in-multivariate-normal-exa/9407/1 "2022-05-12T08:18:47Z")

</div>

Hi all,

I’m trying to fit a multivariate normal analogous to this example

[https://docs.pymc.io/en/v3/pymc-examples/examples/case\_studies/LKJ.html](https://docs.pymc.io/en/v3/pymc-examples/examples/case_studies/LKJ.html)

Different from the example, I have several sets of observations for which I want to estimate independent parameters. I can’t seem to figure out how to add a dimension to the example to handle this (and I want to avoid an ugly loop thing). Normally I know how to work with the shapes but the observations being pairs somehow makes it different…

I’ve tried this (among other things)

```auto
t, trials = pd.factorize(baseline_data['Trial Index'], sort=True)
with pm.Model(coords=coords) as model:
     chol, corr, stds = pm.LKJCholeskyCov('chol', n=2, eta=2.,
     sd_dist=pm.HalfCauchy.dist(500,shape=(len(trials), 2)),
                                   compute_corr=True)

     μ = pm.Normal('μ', 0., 2000., 
     testval=baseline_data['X'].mean(axis=0), shape=(len(trials), 2))
     obs = pm.MvNormal('obs', μ[t], chol=chol[t], observed=np.array([baseline_data_static['X'].values, 
     baseline_data_static['Y'].values]).T)
     trace = pm.sample(tune=1000, return_inferencedata=True, 
     init='advi+adapt_diag')

```

It results in "  
IndexError: index 2 is out of bounds for axis 0 with size 2"

I have also tried different orders of the dimensions. And somewhere there is a version of the example with named dimensions but that didn’t help either…

Any suggestions are highly appreciated!

Many thanks  
Jan
