Created
September 12, 2022 18:06
-
-
Save JakeJing/4bd3cd6bd72e07417d158f997783c372 to your computer and use it in GitHub Desktop.
multinomial logistic regression model in stan
This file contains hidden or 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 J; // number of predictors or features | |
int K; // outcome classes | |
int N; | |
array[N] int y; | |
matrix[N, J] X; | |
} | |
parameters { | |
matrix[J, K-1] beta; // number of predictor * number of classes-1 | |
} | |
transformed parameters { | |
// last class as the reference | |
matrix[J, K] beta_new = append_col(beta, rep_vector(0, J)); | |
} | |
model { | |
matrix[N, K] Z = X * beta_new; | |
to_vector(beta_new) ~ normal(0, 10); | |
for (n in 1:N) { | |
// y[n] ~ categorical(softmax(x[n] * beta)); | |
y[n] ~ categorical_logit(Z[n]'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment