13.6 Categorical logit generalized linear model (softmax regression)
Stan also supplies a single function for a generalized linear model with categorical likelihood and logit link function, i.e. a function for a softmax regression. This provides a more efficient implementation of softmax regression than a manually written regression in terms of a Categorical likelihood and matrix multiplication.
Note that the implementation does not put any restrictions on the coefficient matrix β. It is up to the user to use a reference category, a suitable prior or some other means of identifiability. See Multi-logit in the Stan User’s Guide.
13.6.1 Probability mass functions
If N,M,K∈N, N,M,K>0, and if x∈RM⋅K,α∈RN,β∈RK⋅N, then for y∈{1,…,N}M, CategoricalLogitGLM(y | x,α,β)=∏1≤i≤MCategoricalLogit(yi | α+xi⋅β)=∏1≤i≤MCategorical(yi | softmax(α+xi⋅β)). See the definition of softmax for the definition of the softmax function.
13.6.2 Sampling statement
y ~
categorical_logit_glm
(x, alpha, beta)
Increment target log probability density with categorical_logit_glm_lupmf(y | x, alpha, beta)
.
13.6.3 Stan functions
real
categorical_logit_glm_lpmf
(int y | row_vector x, vector alpha, matrix beta)
The log categorical probability mass function with outcome y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
.
real
categorical_logit_glm_lupmf
(int y | row_vector x, vector alpha, matrix beta)
The log categorical probability mass function with outcome y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
dropping constant additive terms.
real
categorical_logit_glm_lpmf
(int y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
.
real
categorical_logit_glm_lupmf
(int y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
dropping constant additive terms.
real
categorical_logit_glm_lpmf
(int[] y | row_vector x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
.
real
categorical_logit_glm_lupmf
(int[] y | row_vector x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
dropping constant additive terms.
real
categorical_logit_glm_lpmf
(int[] y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
.
real
categorical_logit_glm_lupmf
(int[] y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in
1:N given N-vector of log-odds of outcomes alpha + x * beta
dropping constant additive terms.