Assigning priors to vector of parameters

Hi all,

I have a quick question about assigning priors to a vector of values. Say I have a parameterization:

parameters {
  real mu
  vector[N] mu_staff
  ...
}
model {
  ...
  mu ~ normal(0, 1)
  mu_staff ~ normal(mu, ...)
}

I understand the case above as a multilevel model, where elements of mu_staff are different values that depend the same normal(mu) distribution.

What if I parameterized my model this way?

parameters {
  vector[N] mu_staff
  ...
}
model {
  ...
  mu_staff ~ normal(10, ...)
}

Does the assignment here vectorize? More specifically, does each value of mu_staff come from its own normal(10) prior, i.e. N separate priors for each element of mu_staff? Or does it denote a multilevel model i.e. all elements of mu_staff come from the same normal(10) distribution like the above?

I dug through the manual but couldn’t find a good answer. Hope what I’m asking makes sense!

Any “sampling” statement of the form

y ~ distribution(x, ...)

where y is a vector (or 1D real array) of size N and x is a real scalar is going to conceptually translate into

for (n in 1:N)
  target += distribution_lpdf(y[n] | x, ...);

which is to say that it is going to add N independent terms to the posterior kernel in log units.

3 Likes

Great, that helps. Thanks!

Hi,

I have a little follow-up question to that:

what if:

y ~ distribution(x, ...); `y` and `x` are both vectors (or 1D real array) of size `N`.

is y[n] sampled using the corresponding x[n], that is

for (n in 1:N) target += distribution_lpdf(y[n] | x[n], ...);
?

1 Like

Yes, that is correct.