This is an old version, view current version.

14.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 \(\beta\). 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.

14.6.1 Probability mass functions

If \(N,M,K \in \mathbb{N}\), \(N,M,K > 0\), and if \(x\in \mathbb{R}^{M\times K}, \alpha \in \mathbb{R}^N, \beta\in \mathbb{R}^{K\cdot N}\), then for \(y \in \{1,\ldots,N\}^M\), \[ \text{CategoricalLogitGLM}(y~|~x,\alpha,\beta) = \\[5pt] \prod_{1\leq i \leq M}\text{CategoricalLogit}(y_i~|~\alpha+x_i\cdot\beta) = \\[15pt] \prod_{1\leq i \leq M}\text{Categorical}(y_i~|~softmax(\alpha+x_i\cdot\beta)). \] See the definition of softmax for the definition of the softmax function.

14.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).
Available since 2.23

14.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.
Available since 2.23

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.
Available since 2.25

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.
Available since 2.23

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.
Available since 2.25

real categorical_logit_glm_lpmf(array[] 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.
Available since 2.23

real categorical_logit_glm_lupmf(array[] 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.
Available since 2.25

real categorical_logit_glm_lpmf(array[] 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.
Available since 2.23

real categorical_logit_glm_lupmf(array[] 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.
Available since 2.25