Bounded Discrete Distributions
Bounded discrete probability functions have support on
Binomial distribution
Probability mass function
Suppose
Log probability mass function
Gradient of log probability mass function
Distribution statement
n ~
binomial
(N, theta)
Increment target log probability density with binomial_lupmf(n | N, theta)
.
Stan functions
real
binomial_lpmf
(ints n | ints N, reals theta)
The log binomial probability mass of n successes in N trials given chance of success theta
real
binomial_lupmf
(ints n | ints N, reals theta)
The log binomial probability mass of n successes in N trials given chance of success theta dropping constant additive terms
real
binomial_cdf
(ints n | ints N, reals theta)
The binomial cumulative distribution function of n successes in N trials given chance of success theta
real
binomial_lcdf
(ints n | ints N, reals theta)
The log of the binomial cumulative distribution function of n successes in N trials given chance of success theta
real
binomial_lccdf
(ints n | ints N, reals theta)
The log of the binomial complementary cumulative distribution function of n successes in N trials given chance of success theta
R
binomial_rng
(ints N, reals theta)
Generate a binomial variate with N trials and 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.
Binomial distribution, logit parameterization
Stan also provides a version of the binomial probability mass function distribution with the chance of success parameterized on the unconstrained logistic scale.
Probability mass function
Suppose
Log probability mass function
Gradient of log probability mass function
Distribution statement
n ~
binomial_logit
(N, alpha)
Increment target log probability density with binomial_logit_lupmf(n | N, alpha)
.
Stan functions
real
binomial_logit_lpmf
(ints n | ints N, reals alpha)
The log binomial probability mass of n successes in N trials given logit-scaled chance of success alpha
real
binomial_logit_lupmf
(ints n | ints N, reals alpha)
The log binomial probability mass of n successes in N trials given logit-scaled chance of success alpha dropping constant additive terms
Binomial-logit generalized linear model (Logistic Regression)
Stan also supplies a single function for a generalized linear model with binomial distribution and logit link function, i.e., a function for logistic regression with aggregated outcomes. This provides a more efficient implementation of logistic regression than a manually written regression in terms of a binomial distribution and matrix multiplication.
Probability mass function
Suppose
Distribution statement
n ~
binomial_logit_glm
(N, x, alpha, beta)
Increment target log probability density with binomial_logit_glm_lupmf(n | N, x, alpha, beta)
.
Stan Functions
real
binomial_logit_glm_lpmf
(int n | int N, matrix x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(int n | int N, matrix x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
real
binomial_logit_glm_lpmf
(int n | int N, matrix x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(int n | int N, matrix x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
real
binomial_logit_glm_lpmf
(array[] int n | array[] int N, row_vector x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(array[] int n | array[] int N, row_vector x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
real
binomial_logit_glm_lpmf
(array[] int n | array[] int N, row_vector x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(array[] int n | array[] int N, row_vector x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
real
binomial_logit_glm_lpmf
(array[] int n | array[] int N, matrix x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(array[] int n | array[] int N, matrix x, real alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
real
binomial_logit_glm_lpmf
(array[] int n | array[] int N, matrix x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
.
real
binomial_logit_glm_lupmf
(array[] int n | array[] int N, matrix x, vector alpha, vector beta)
The log binomial probability mass of n given N trials and chance of success inv_logit(alpha + x * beta)
dropping constant additive terms.
Beta-binomial distribution
Probability mass function
If
Distribution statement
n ~
beta_binomial
(N, alpha, beta)
Increment target log probability density with beta_binomial_lupmf(n | N, alpha, beta)
.
Stan functions
real
beta_binomial_lpmf
(ints n | ints N, reals alpha, reals beta)
The log beta-binomial probability mass of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta
real
beta_binomial_lupmf
(ints n | ints N, reals alpha, reals beta)
The log beta-binomial probability mass of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta dropping constant additive terms
real
beta_binomial_cdf
(ints n | ints N, reals alpha, reals beta)
The beta-binomial cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta
real
beta_binomial_lcdf
(ints n | ints N, reals alpha, reals beta)
The log of the beta-binomial cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta
real
beta_binomial_lccdf
(ints n | ints N, reals alpha, reals beta)
The log of the beta-binomial complementary cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta
R
beta_binomial_rng
(ints N, reals alpha, reals beta)
Generate a beta-binomial variate with N trials, prior success count (plus one) of alpha, and prior failure count (plus one) of beta; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Hypergeometric distribution
Probability mass function
If
Distribution statement
n ~
hypergeometric
(N, a, b)
Increment target log probability density with hypergeometric_lupmf(n | N, a, b)
.
Stan functions
real
hypergeometric_lpmf
(int n | int N, int a, int b)
The log hypergeometric probability mass of n successes in N trials given total success count of a and total failure count of b
real
hypergeometric_lupmf
(int n | int N, int a, int b)
The log hypergeometric probability mass of n successes in N trials given total success count of a and total failure count of b dropping constant additive terms
int
hypergeometric_rng
(int N, int a, int b)
Generate a hypergeometric variate with N trials, total success count of a, and total failure count of b; may only be used in transformed data and generated quantities blocks
Categorical distribution
Probability mass functions
If
Distribution statement
y ~
categorical
(theta)
Increment target log probability density with categorical_lupmf(y | theta)
dropping constant additive terms.
Distribution statement
y ~
categorical_logit
(beta)
Increment target log probability density with categorical_logit_lupmf(y | beta)
.
Stan functions
All of the categorical distributions are vectorized so that the outcome y can be a single integer (type int
) or an array of integers (type array[] int
).
real
categorical_lpmf
(ints y | vector theta)
The log categorical probability mass function with outcome(s) y in
real
categorical_lupmf
(ints y | vector theta)
The log categorical probability mass function with outcome(s) y in
real
categorical_logit_lpmf
(ints y | vector beta)
The log categorical probability mass function with outcome(s) y in
real
categorical_logit_lupmf
(ints y | vector beta)
The log categorical probability mass function with outcome(s) y in
int
categorical_rng
(vector theta)
Generate a categorical variate with
int
categorical_logit_rng
(vector beta)
Generate a categorical variate with outcome in range
Categorical logit generalized linear model (softmax regression)
Stan also supplies a single function for a generalized linear model with categorical distribution 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 distribution and matrix multiplication.
Note that the implementation does not put any restrictions on the coefficient matrix
Probability mass functions
If
Distribution statement
y ~
categorical_logit_glm
(x, alpha, beta)
Increment target log probability density with categorical_logit_glm_lupmf(y | x, alpha, beta)
.
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 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 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 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 alpha + x * beta
dropping constant additive terms.
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 alpha + x * beta
.
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 alpha + x * beta
dropping constant additive terms.
real
categorical_logit_glm_lpmf
(array[] int y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in alpha + x * beta
.
real
categorical_logit_glm_lupmf
(array[] int y | matrix x, vector alpha, matrix beta)
The log categorical probability mass function with outcomes y
in alpha + x * beta
dropping constant additive terms.
Discrete range distribution
Probability mass functions
If
Distribution statement
y ~
discrete_range
(l, u)
Increment the target log probability density with discrete_range_lupmf(y | l, u)
dropping constant additive terms.
Stan functions
All of the discrete range distributions are vectorized so that the outcome y
and the bounds l, u
can be a single integer (type int
) or an array of integers (type array[] int
).
real
discrete_range_lpmf
(ints y | ints l, ints u)
The log probability mass function with outcome(s) y in
real
discrete_range_lupmf
(ints y | ints l, ints u)
The log probability mass function with outcome(s) y in
real
discrete_range_cdf
(ints y | ints l, ints u)
The discrete range cumulative distribution function for the given y, lower and upper bounds.
real
discrete_range_lcdf
(ints y | ints l, ints u)
The log of the discrete range cumulative distribution function for the given y, lower and upper bounds.
real
discrete_range_lccdf
(ints y | ints l, ints u)
The log of the discrete range complementary cumulative distribution function for the given y, lower and upper bounds.
ints
discrete_range_rng
(ints l, ints u)
Generate a discrete variate between the given lower and upper bounds; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Ordered logistic distribution
Probability mass function
If
Distribution statement
k ~
ordered_logistic
(eta, c)
Increment target log probability density with ordered_logistic_lupmf(k | eta, c)
.
Stan functions
real
ordered_logistic_lpmf
(ints k | vector eta, vectors c)
The log ordered logistic probability mass of k given linear predictors eta
, and cutpoints c
.
real
ordered_logistic_lupmf
(ints k | vector eta, vectors c)
The log ordered logistic probability mass of k given linear predictors eta
, and cutpoints c
dropping constant additive terms.
int
ordered_logistic_rng
(real eta, vector c)
Generate an ordered logistic variate with linear predictor eta
and cutpoints c
; may only be used in transformed data and generated quantities blocks
Ordered logistic generalized linear model (ordinal regression)
Probability mass function
If
Distribution statement
y ~
ordered_logistic_glm
(x, beta, c)
Increment target log probability density with ordered_logistic_lupmf(y | x, beta, c)
.
Stan functions
real
ordered_logistic_glm_lpmf
(int y | row_vector x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lupmf
(int y | row_vector x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c dropping constant additive terms. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lpmf
(int y | matrix x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lupmf
(int y | matrix x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c dropping constant additive terms. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lpmf
(array[] int y | row_vector x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lupmf
(array[] int y | row_vector x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c dropping constant additive terms. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lpmf
(array[] int y | matrix x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c. The cutpoints c
must be ordered.
real
ordered_logistic_glm_lupmf
(array[] int y | matrix x, vector beta, vector c)
The log ordered logistic probability mass of y, given linear predictors x * beta
, and cutpoints c dropping constant additive terms. The cutpoints c
must be ordered.
Ordered probit distribution
Probability mass function
If
Distribution statement
k ~
ordered_probit
(eta, c)
Increment target log probability density with ordered_probit_lupmf(k | eta, c)
.
Stan functions
real
ordered_probit_lpmf
(ints k | vector eta, vectors c)
The log ordered probit probability mass of k given linear predictors eta, and cutpoints c.
real
ordered_probit_lupmf
(ints k | vector eta, vectors c)
The log ordered probit probability mass of k given linear predictors eta, and cutpoints c dropping constant additive terms.
real
ordered_probit_lpmf
(ints k | real eta, vectors c)
The log ordered probit probability mass of k given linear predictor eta, and cutpoints c.
real
ordered_probit_lupmf
(ints k | real eta, vectors c)
The log ordered probit probability mass of k given linear predictor eta, and cutpoints c dropping constant additive terms.
int
ordered_probit_rng
(real eta, vector c)
Generate an ordered probit variate with linear predictor eta and cutpoints c; may only be used in transformed data and generated quantities blocks