Last active
May 29, 2020 16:56
-
-
Save teddygroves/695f32519707288d2e4413a6158b3320 to your computer and use it in GitHub Desktop.
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
import cmdstanpy | |
MODEL_FILE = "likert_comparison.stan" | |
DATA = { | |
"K": 3, | |
"N_pre": 30, | |
"N_post": 29, | |
"pre": [1] * 14 + [2] * 12 + [3] * 4, | |
"post": [1] * 6 + [2] * 13 + [3] * 10 | |
} | |
if __name__ == "__main__": | |
model = cmdstanpy.CmdStanModel(stan_file=MODEL_FILE) | |
fit = model.sample(data=DATA) | |
print(fit.diagnose()) | |
print(fit.summary()) |
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
data { | |
int N_pre; | |
int N_post; | |
int K; | |
int<lower=1,upper=K> pre[N_pre]; | |
int<lower=1,upper=K> post[N_post]; | |
} | |
parameters { | |
ordered[K-1] cutpoints; | |
vector[2] eta; | |
} | |
model { | |
eta ~ normal(0, 3); | |
cutpoints[1] ~ normal(0, 3); | |
cutpoints[2] - cutpoints[1] ~ normal(0, 3); | |
for (n in 1:N_pre) | |
pre[n] ~ ordered_logistic(eta[1], cutpoints); | |
for (n in 1:N_post) | |
post[n] ~ ordered_logistic(eta[2], cutpoints); | |
} | |
generated quantities { | |
int<lower=0,upper=1> post_greater_than_pre = eta[2] > eta[1] ? 1 : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment