Test: Soft vs Hard sum-to-zero constrain + choosing the right prior for soft constrain

@stemangiola @mitzimorris

There might be another way to do this from Fraser CJM 1951.
Something like:

transformed data{
  matrix [N,N] A = rep_matrix(-inv(x-1),N,N);
  for(i in 1:N)
    A[i,i] = 1;
  matrix [N,N] A_sqrt = chol(A);
//or
//matrix [N,N] A_sqrt = eigenvectors_sym(A) * diagonal(sqrt(eigenvalues(A)))* inverse(eigenvectors_sym(A));

}
parameters {
  vector [N-1] x_raw; 
}
transformed parameters{
   x =  A_sqrt * append_row(x,0); //structure of the chol matrix, means that this could actually be done in O(n) time.
}
model {
  x_raw ~ normal(0,1/sqrt(1-inv(N)));
}

Some more references:
https://cms.math.ca/openaccess/cjm/v3/cjm1951v03.0363-0366.pdf
http://r.789695.n4.nabble.com/A-vector-of-normal-distributed-values-with-a-sum-to-zero-constraint-td4687954.html

1 Like