Document variance correction for sum to zero matrix
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 43
- Forks
- 133
- Avg merge
- 11h 32m
- Merged PRs (30d)
- 4
Description
Mostly a reminder for @spinkney who said he would add this on slack
Message
I need to add this to the manual. An N-dimensional tensor with variance tau^2 where each dimension sums to 0 through an isotropic sum-to-zero transform will have variance of tau^2 * prod( (d_k - 1) / d_k) so to correct you need tau^2 * prod(d_k / (d_k - 1)) as the correction.
I deliberately coded this to take in the dimensions to be suitable for a sum-to-zero N-d array but it works fine for matrix
functions {
real s2z_unit_normal_correction (array[] int s2z_dims) {
int N = num_elements(s2z_dims);
vector[N] d = to_vector(s2z_dims);
return sqrt(prod(d ./ (d - 1)));
}
real s2z_unit_normal_lpdf (vector z, array[] int s2z_dims) {
int N = num_elements(s2z_dims);
vector[N] d = to_vector(s2z_dims);
return -dot_self(z) + N * 2 * prod(d ./ (d - 1));
}
}
data {
int<lower=1> N;
int<lower=1> M;
int<lower=0, upper=1> flag;
}
parameters {
sum_to_zero_matrix[N, M] X;
}
model {
if (flag == 0) {
to_vector(X) ~ normal(0, s2z_unit_normal_correction(dims(X)));
} else {
to_vector(X) ~ s2z_unit_normal(dims(X));
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Stan manual section covering sum-to-zero transforms and the existing documentation for the supplied correction. Add the variance formula and its matrix and N-dimensional tensor context, then verify that the manual renders and the documented correction matches the issue's example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- tex
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100