# Multiple draws from same multivariate normal

**URL:** <https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918>\
**Category:** Modeling\
**Tags:** specification\
**Created:** [March 24, 2022, 11:58am UTC](https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918 "2022-03-24T11:58:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darby](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@darby](https://discourse.mc-stan.org/u/darby)\
**Post date:** [March 24, 2022, 11:58am UTC](https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918/1 "2022-03-24T11:58:34Z")

</div>

I would like to create a model like the below, where each row in the response matrix is drawn from the same multivariate normal distribution.

```stan
data {
  int<lower=1> N;
  matrix[N, 3] ys;
}

parameters {
  cov_matrix[3] covmat;
  vector[3] means;
}

model {
  ys ~ multi_normal(means, covmat);
}

```

but I can only get it working by using arrays of vectors instead of matrixes and by broadcasting the mean vector manually as below

```stan

data {
  int<lower=1> N;
  array[N] vector[3] ys;
}

parameters {
  cov_matrix[3] covmat;
  vector[3] means;
}

transformed parameters {
  array[N] vector[3] b_means;
  
  b_means[,1] = to_array_1d(rep_vector(means[1], N));
  b_means[,2] = to_array_1d(rep_vector(means[2], N));
  b_means[,3] = to_array_1d(rep_vector(means[3], N));
}

model {
  ys ~ multi_normal(b_means, covmat)
}

```

Is this really the correct way to specify this model in stan 2.29? The signatures for multi\_normal seem extremely limited

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [March 24, 2022, 5:18pm UTC](https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918/2 "2022-03-24T17:18:26Z")

</div>

See discussion [here](https://github.com/stan-dev/stanc3/issues/937).

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [March 24, 2022, 5:19pm UTC](https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918/3 "2022-03-24T17:19:15Z")

</div>

Oops, I mean [here](https://github.com/stan-dev/math/issues/2532).

---

<div class="post-metadata">

**Author:** ![darby](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@darby](https://discourse.mc-stan.org/u/darby)\
**Post date:** [March 24, 2022, 8:57pm UTC](https://discourse.mc-stan.org/t/multiple-draws-from-same-multivariate-normal/26918/4 "2022-03-24T20:57:57Z")

</div>

Thanks for the link! The discussion really helped me understand the function
