This is an old version, view current version.

12.3 Bernoulli-logit generalized linear model (Logistic Regression)

Stan also supplies a single function for a generalized linear model with Bernoulli likelihood and logit link function, i.e. a function for a logistic regression. This provides a more efficient implementation of logistic regression than a manually written regression in terms of a Bernoulli likelihood and matrix multiplication.

12.3.1 Probability mass function

If \(x\in \mathbb{R}^{n\cdot m}, \alpha \in \mathbb{R}^n, \beta\in \mathbb{R}^m\), then for \(y \in {\{0,1\}}^n\), \[\begin{align*} &\text{BernoulliLogitGLM}(y~|~x, \alpha, \beta) = \prod_{1\leq i \leq n}\text{Bernoulli}(y_i~|~\text{logit}^{-1}(\alpha_i + x_i\cdot \beta))\\ &= \prod_{1\leq i \leq n} \left\{ \begin{array}{ll} \text{logit}^{-1}(\alpha_i + \sum_{1\leq j\leq m}x_{ij}\cdot \beta_j) & \text{if } y_i = 1, \text{ and} \\ 1 - \text{logit}^{-1}(\alpha_i + \sum_{1\leq j\leq m}x_{ij}\cdot \beta_j) & \text{if } y_i = 0. \end{array} \right. \end{align*}\]

12.3.2 Sampling statement

y ~ bernoulli_logit_glm(x, alpha, beta)

Increment target log probability density with bernoulli_logit_glm_lupmf(y | x, alpha, beta).

12.3.3 Stan Functions

real bernoulli_logit_glm_lpmf(int y | matrix x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int y | matrix x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.

real bernoulli_logit_glm_lpmf(int y | matrix x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int y | matrix x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.

real bernoulli_logit_glm_lpmf(int[] y | row_vector x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int[] y | row_vector x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.

real bernoulli_logit_glm_lpmf(int[] y | row_vector x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int[] y | row_vector x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.

real bernoulli_logit_glm_lpmf(int[] y | matrix x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int[] y | matrix x, real alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.

real bernoulli_logit_glm_lpmf(int[] y | matrix x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta).

real bernoulli_logit_glm_lupmf(int[] y | matrix x, vector alpha, vector beta)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha + x * beta) dropping constant additive terms.