Skip to content

Instantly share code, notes, and snippets.

@demodw
Created September 30, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demodw/20d95f0fdd54624d14aa2983e14d71f5 to your computer and use it in GitHub Desktop.
Save demodw/20d95f0fdd54624d14aa2983e14d71f5 to your computer and use it in GitHub Desktop.
data {
int<lower=1> K; // Number of classes
int<lower=1> N; // Total number of data points
int<lower=1> D; // Number of combinations
int<lower=1> Di[N]; // Data point to combination index
// Outcome
int<lower=0> Count[N,K]; // Number of samples at data point N for class K
// Covariates
vector[N] Age; // Age at data point N
}
parameters {
matrix[D, K] beta_0;
matrix[D, K] beta_A;
}
model {
/* Prior specification */
// Combination priors
to_vector(beta_0) ~ normal(0, 1);
to_vector(beta_A) ~ normal(0, 1);
/* Calculate theta hat for each combination, and increment likelihood */
{
vector[K] theta;
theta[1] = 0;
for (n in 1:N) {
// Increment likelihood
for (k in 1:K) {
theta[k] = beta_0[Di[n], k] + beta_A[Di[n], k] * AgeZ[n];
}
Count[n] ~ multinomial(softmax(theta));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment