Created
March 30, 2018 12:55
-
-
Save bnicenboim/752504f9ccfaf05552ee8373f3b40af4 to your computer and use it in GitHub Desktop.
function for creating a Helmert matrix in Stan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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