I would like to have a constrained parameter type that’s like ordered_sum_to_zero_vector (for paramters corresponding to mixture weights.)
My understanding is that a parameter of type sum_to_zero_vector[k] v only uses k-1 scalar parameters under the hood and then uses some sort of transformation to fill in the last degree of freedom. The “obvious” method would be to simply do something along the lines
v_K = -\sum_{k=1}^{K-1}v_k
but that feels wrong? Like, not sensitive? Like, if the vector is long, the last component will be in a different order magnitude than the rest… So I would guess the transformation is actually something else. What is it?
My idea is to then apply it to a regular ordered[k-1] vector to obtain what I want.
data {
int<lower=0> N;
}
parameters {
vector<lower=0>[N - 1] raw;
// real<lower=0> scale; // optional, for flexibility
}
transformed parameters {
vector[N] diff;
diff[1] = 0; // Anchor point
diff[2:N] = cumulative_sum(raw);
// vector[N] z = scale * (diff - mean(diff)); // if you want to scale
vector[N] z = (diff - mean(diff));
}
model {
raw ~ exponential(sqrt(N - 1) - 1); // or any distribution with mass on the positive reals
// scale ~ normal(0, 1); // or any appropriate prior
}
generated quantities {
real z_sum = sum(z);
}