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∈Rn⋅m,α∈Rn,β∈Rm, then for y∈{0,1}n, BernoulliLogitGLM(y | x,α,β)=∏1≤i≤nBernoulli(yi | logit−1(αi+xi⋅β))=∏1≤i≤n{logit−1(αi+∑1≤j≤mxij⋅βj)if yi=1, and1−logit−1(αi+∑1≤j≤mxij⋅βj)if yi=0.
12.3.2 Sampling Statement
y ~
bernoulli_logit_glm
(x, alpha, beta)
Increment target log probability density with bernoulli_logit_glm_lpmf(y | x, alpha, beta)
dropping constant additive terms.
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)
, where the same intercept alpha
and dependant variable value y
are used
for all observations. The number of columns of x
needs to match the size of the
coefficient vector beta
.
If x
and y
are data (not parameters) this function can be executed on a GPU.
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)
, where an intercept alpha
is used that is
allowed to vary by observation. The dependant variable
value y
is used for all observations.
The number of rows of x
must match the size of alpha
and
the number of columns of x
needs to match the size of the coefficient vector beta
.
If x
and y
are data (not parameters) this function can be executed on a GPU.
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)
, where the same intercept alpha
and
same independent variables values x
are used for all observations.
The number of columns of x
needs to match the size of the coefficient vector beta
.
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)
, where an intercept alpha
is used that is
allowed to vary by observation.
The same independent variables values x
are used for all observations.
The size of y
must match the size of alpha
and
the number of columns of x
needs to match the size of the coefficient vector beta
.
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)
, where the same intercept alpha
is used
for all observations. The number of rows of the independent variable
matrix x
needs to match the size of the dependent variable vector
y
and the number of columns of x
needs to match the size of the
coefficient vector beta
.
If x
and y
are data (not parameters) this function can be executed on a GPU.
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)
, where an intercept alpha
is used that is
allowed to vary by observation. The number of rows of
the independent variable matrix x
needs to match the size of the
dependent variable vector y
and alpha
and the number of columns of
x
needs to match the size of the coefficient vector beta
.
If x
and y
are data (not parameters) this function can be executed on a GPU.