How to specify the first term in the random walk prior in a sum_to_zero vector?

We have a parameter declared with a sum_to_zero_vector

parameter {
  sum_to_zero_vector[J_age] eta_age;        
} 

and then in the model block we have

model {
    for (i in 2:J_age) {

    eta_age[i] ~ normal(eta_age[i-1], 1);

  }     
} 

So here does the sum_to_zero constraint handle the first term eta_age[1], or do I need to specify a seperated prior for the first term, and loop the random walk prior till the second to last term (so the last term would be handled by the sum-to-zero constraint)? This idea looks something like this:

model {
eta_age[1] ~ normal(0, 1); 
for (i in 2:(J_age - 1)) {  
    eta_age[i] ~ normal(eta_age[i-1], 1);
}   
} 

Please let me know whether the 1st or second version of the code is correct!

1 Like

You can do either of these as the sum to zero constraint is satisfied across each value in the vector through a semi-orthogonal projection thus each element is equally effected by the constraint.

I’m less certain about using a random walk prior on a vector that sums to zero as a good idea. For small vector sizes the constraint will dominate over the prior. As the vector size increases your RW prior will behave similarly to the non-sum-to-zero vector case. If your J_age is moderate in size, say 4 - 8, you might experiment with putting a prior on eta_age[1] that forces it positive or negative if you have some prior knowledge about this effect. Since the vector must sum to zero there must be some values less than 0 and some greater.

That’s interesting – does the specific geometric / ‘hard’ sum-to-0 implemented as above have much of a different effect in this case compared to the ‘soft’ sum to zero, such as that implemented in Gao et al. "Improving multilevel regression and poststratification with structured priors” ? (GitHub repo here)

They use:

 for (j in 2:N_groups_age) {
    U_age[j] ~normal(U_age[j-1],1);
  }

  sum(U_age) ~ normal(0, 0.01 * N_groups_age); // constraint so we can write likelihood for rw(1).

My read of this is that it’s a ‘soft’ sum-to-0 on U_age. I have been generally switching to the sum_to_zero_vector for computational efficiency reasons, but perhaps I should be more careful about that ?