Meaning of {a, b, c} ~ N(mu, sigma) in 'model' section

When I read a reference stan code I am confused about the following statement in the ‘model’ part of Stan:

data{
 real<lower = 0> sigma;
 real mu;
} 

paramter{
 real b1;
 real b2;
 real b3;
} 

model{
{b1, b2, b3}  ~ normal(mu, sigma); 
}

I am not sure what does ‘{b1, b2, b3} ~ normal(mu, sigma);’ means here since when I used rstan to run the stan file, the error message said that:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Illegal statement beginning with non-void expression parsed as
b1
Not a legal assignment, sampling, or function statement. Note that

  • Assignment statements only allow variables (with optional indexes) on the left;
  • Sampling statements allow arbitrary value-denoting expressions on the left.
  • Functions used as statements must be declared to have void returns

So I changed the Stan code as:

data{
 real<lower = 0> sigma;
 real mu;
} 

paramter{
 real b1;
 real b2;
 real b3;
} 

model{
b1 ~ normal(mu, sigma); 
b2 ~ normal(mu, sigma); 
b3 ~ normal(mu, sigma); 
}

May I ask that are these two Stan codes equivalent? If not, what’s the meaning of '{b1, b2, b3} ~ normal(mu, sigma); '?

1 Like

This is short for saying “make a real array out of b1, b2, b3”. The statement is thus a vectorized expression which apparently only works with newer Stans (don’t know when that was introduced).

Thanks so much!

Since I am a beginner of Stan, in my understanding that the following two expressions are equal, are I right?:

model{
{b1, b2, b3}  ~ normal(mu, sigma); 
}
model{
b1 ~ normal(mu, sigma); 
b2 ~ normal(mu, sigma); 
b3 ~ normal(mu, sigma); 
}

The first expression is exactly equal to

model {
  real b[3];
  b[1] = b1;
  b[2] = b2;
  b[3] = b3;
  b ~ normal(mu, sigma);
}

and yes, that is essentially the same as the second expression.

Thx!

It’s my first time to see the expression and I feel that I have learnt a lot!

model {
  real b[3];
  b[1] = b1;
  b[2] = b2;
  b[3] = b3;
  b ~ normal(mu, sigma);
}