How to specify the coefficient for reference group as zero in stan

I have a categorical variable (drug treatment) with 6 groups.
Rather than doing redundant parameterization (6 parameters), I want to set the control treatment as the reference level such that its coefficient is zero (5 parameters).

In rjags, I could do:

for(i in 1:5){bT[i] ~ dnorm(0, 1)}
bT[6] <- 0

But when I try to do it in stan, like this:

parameters {
  vector[6] bT;
} 

model{
 bT[1:5] ~ normal(0, 1);
 bT[6] = 0;

 // some likelihood function
}

It tells me that

Cannot assign to global variable 'bT' declared in previous blocks.

I found a similar post here but it does not include any code.
I am guessing I have to add something in the transformed parameters block, but it is not immediately obvious to me (a stan newb) what the correct syntax is.

Many thanks in advance -
A.L.

1 Like

Only specify the vector of length 5 as a parameter, and then you can create a temporary vector with the zero appended for the last group in the model block

parameters {
  vector[5] bT_params;
} 

model{
  vector[6] bT; 

  bT_params ~ normal(0, 1);
  bT = append_row(bT_params, 0.0);

 // some likelihood function
}
2 Likes