Skip to content

Instantly share code, notes, and snippets.

@bnicenboim
Created March 30, 2018 12:55
Show Gist options
  • Save bnicenboim/752504f9ccfaf05552ee8373f3b40af4 to your computer and use it in GitHub Desktop.
Save bnicenboim/752504f9ccfaf05552ee8373f3b40af4 to your computer and use it in GitHub Desktop.
function for creating a Helmert matrix in Stan
functions {
matrix helmert(int levels) {
matrix[levels, levels - 1] m = rep_matrix(-1, levels, levels - 1);
real k = 0;
for(j in 1:(levels - 1))
for(i in 1:levels)
if(j <= i - 2)
m[i, j] = 0;
else if(j == i - 1) {
k = k + 1;
m[i, j] = k;
}
return m;
}
}
data {
}
parameters {
}
model {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment