row vectors in multi_normal_rng

99 views
Skip to first unread message

Dr. Hans Hansen

unread,
Jan 28, 2017, 3:18:33 PM1/28/17
to Stan users mailing list
Hi,

is there a reason that row vectors do not work in multi_normal_rng()?

I have this sampling statement:

  for (i in 1:N){
      dat[i,] ~ multi_normal(pred[i,], sigma); 
  }

and like to simulate data for posterior predictive checking:

  for (i in 1:N){
      pred_dat[i,] ~ multi_normal_rng(pred[i,], sigma); 
  }

i get a type mismatch error. my solution now is to transpose my matrix, then the row vector is a vector and it works. would there be another way to declare a row vector as a vector?

thanks, felix
Message has been deleted
Message has been deleted

Bob Carpenter

unread,
Jan 30, 2017, 1:10:43 AM1/30/17
to stan-...@googlegroups.com

> On Jan 28, 2017, at 3:18 PM, Dr. Hans Hansen <drhans...@gmail.com> wrote:
>
> Hi,
>
> is there a reason that row vectors do not work in multi_normal_rng()?

Just for consistency. The multivariate types pin down particular forms
of arguments, which can then be vectorized by putting them into
arrays.

> I have this sampling statement:
>
> for (i in 1:N){
> dat[i,] ~ multi_normal(pred[i,], sigma);
> }

The declarations should look like this:

vector[K] dat[N];
vector[K] pred[N];

and then the sampling statement can be vectorized as

dat ~ multi_normal(pred, sigma);

This will be more efficient and stable if sigma is a cholesky
factor and you use multi_normal_cholesky(...).

> and like to simulate data for posterior predictive checking:
>
> for (i in 1:N){
> pred_dat[i,] ~ multi_normal_rng(pred[i,], sigma);
> }

Here you need to use the loop, but you can use the same
types.

- Bob
Reply all
Reply to author
Forward
0 new messages