Hi all,
Given the surge of posts about sum-to-zero recently I thought I’d add another one. I’ve posted about this on Slack before but it might be of broader interest.
My question is about implementing sum-to-zero vectors with a covariance matrix using non-centered parameterisation. Consider the following Stan program:
data {
int<lower=0> J; // number of observations
array[J] real x; // input
int<lower=0, upper=1> flag;
}
parameters {
sum_to_zero_vector[J] z;
real<lower=0> tau;
vector<lower=0>[flag ? 1 : 0] rho;
}
transformed parameters {
vector[J] theta = tau * z; // s2z Gaussian
if (flag) {
matrix[J, J] K = gp_exp_quad_cov(x, 1, rho[1]),
L = cholesky_decompose(K);
theta = L * theta;
}
}
model {
// also add priors for tau, rho
z ~ std_normal(); // or normal(0, sqrt(J * inv(J - 1)).
}
When flag = 0, the sum-to-zero vector theta is scaled by tau so the vector still sums to 0. When flag = 0, the vector is additionally scaled by a covariance matrix so the vector doesn’t still sum to zero. I often write Stan programs this way to I can toggle complexity on and off.
My question is mostly about the “validity” of this sum-to-zero approach. I suspect there’s still sampling efficiency by enforcing the constraint at the level of the z-scores, but it’s not the same as putting a centered parameteristion like this:
model {
matrix[J, J] K = gp_exp_quad_cov(x, tau, rho[1]),
L = cholesky_decompose(K);
z ~ multi_normal_cholesky(L);
}
because her, I believe, z is constrained to sum to zero while having the GP prior.
I’m mostly interested in the implications of having the z-scores summing to 1 and then multiplying by a Cholesky factor, vs. having the multi normal prior while also summing to 0.
Cheers,
Matt