Binary Distributions
Binary probability distributions have support on \(\{0,1\}\), where 1 represents the value true and 0 the value false.
Bernoulli distribution
Probability mass function
If \(\theta \in [0,1]\), then for \(y \in \{0,1\}\), \[\begin{equation*} \text{Bernoulli}(y~|~\theta) = \left\{ \begin{array}{ll} \theta & \text{if } y = 1, \text{ and} \\ 1 - \theta & \text{if } y = 0. \end{array} \right. \end{equation*}\]
Sampling statement
y ~
bernoulli
(theta)
Increment target log probability density with bernoulli_lupmf(y | theta)
.
Stan Functions
real
bernoulli_lpmf
(ints y | reals theta)
The log Bernoulli probability mass of y given chance of success theta
real
bernoulli_lupmf
(ints y | reals theta)
The log Bernoulli probability mass of y given chance of success theta dropping constant additive terms
real
bernoulli_cdf
(ints y | reals theta)
The Bernoulli cumulative distribution function of y given chance of success theta
real
bernoulli_lcdf
(ints y | reals theta)
The log of the Bernoulli cumulative distribution function of y given chance of success theta
real
bernoulli_lccdf
(ints y | reals theta)
The log of the Bernoulli complementary cumulative distribution function of y given chance of success theta
R
bernoulli_rng
(reals theta)
Generate a Bernoulli variate with chance of success theta
; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Bernoulli distribution, logit parameterization
Stan also supplies a direct parameterization in terms of a logit-transformed chance-of-success parameter. This parameterization is more numerically stable if the chance-of-success parameter is on the logit scale, as with the linear predictor in a logistic regression.
Probability mass function
If \(\alpha \in \mathbb{R}\), then for \(y \in \{0,1\}\), \[\begin{equation*} \text{BernoulliLogit}(y~|~\alpha) = \text{Bernoulli}(y | \text{logit}^{-1}(\alpha)) = \left\{ \begin{array}{ll} \text{logit}^{-1}(\alpha) & \text{if } y = 1, \text{ and} \\ 1 - \text{logit}^{-1}(\alpha) & \text{if } y = 0. \end{array} \right. \end{equation*}\]
Sampling statement
y ~
bernoulli_logit
(alpha)
Increment target log probability density with bernoulli_logit_lupmf(y | alpha)
.
Stan Functions
real
bernoulli_logit_lpmf
(ints y | reals alpha)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha)
real
bernoulli_logit_lupmf
(ints y | reals alpha)
The log Bernoulli probability mass of y given chance of success inv_logit(alpha)
dropping constant additive terms
R
bernoulli_logit_rng
(reals alpha)
Generate a Bernoulli variate with chance of success \(\text{logit}^{-1}(\alpha)\); may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
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.
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*}\]
Sampling statement
y ~
bernoulli_logit_glm
(x, alpha, beta)
Increment target log probability density with bernoulli_logit_glm_lupmf(y | x, alpha, beta)
.
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
(array[] 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
(array[] 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
(array[] 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
(array[] 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
(array[] 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
(array[] 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
(array[] 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
(array[] 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.
array[] int
bernoulli_logit_glm_rng
(matrix x, vector alpha, vector beta)
Generate an array of Bernoulli variates with chances of success inv_logit(alpha + x * beta)
; may only be used in transformed data and generated quantities blocks.
array[] int
bernoulli_logit_glm_rng
(row_vector x, vector alpha, vector beta)
Generate an array of Bernoulli variates with chances of success inv_logit(alpha + x * beta)
; may only be used in transformed data and generated quantities blocks.