This is an old version, view current version.

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,KN, N,M,K>0, and if xRMK,αRN,βRKN, then for y{1,,N}M, CategoricalLogitGLM(y | x,α,β)=1iMCategoricalLogit(yi | α+xiβ)=1iMCategorical(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.