Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created May 3, 2021 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvladeck/6d7659056a5a21da14497669dad7968c to your computer and use it in GitHub Desktop.
Save tvladeck/6d7659056a5a21da14497669dad7968c to your computer and use it in GitHub Desktop.
vaccine threshold price model
data {
int n_respondents;
int n_choices;
int n_vaccines;
int responses[n_choices];
int respondent[n_choices];
int vaccine[n_choices];
vector[n_choices] money;
}
parameters {
real intercept;
vector[n_respondents] a_respondent;
real<lower=0> b_money;
vector[n_vaccines] a_vaccine;
}
transformed parameters {
vector[n_respondents] respondent_intercept = intercept + a_respondent;
vector[n_choices] phi;
for(i in 1:n_choices) {
phi[i] = respondent_intercept[respondent[i]] +
b_money * money[i] +
a_vaccine[vaccine[i]];
}
}
model {
intercept ~ normal(0, 1);
a_respondent ~ normal(0, .5);
a_vaccine ~ normal(0, .5);
b_money ~ exponential(1);
responses ~ bernoulli_logit(phi);
}
generated quantities {
matrix[n_respondents, n_vaccines] threshold_payment;
for(i in 1:n_respondents) {
for(j in 1:n_vaccines) {
threshold_payment[i, j] = -(respondent_intercept[respondent[i]] + a_vaccine[j]) / b_money;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment