Unbounded Continuous Distributions
The unbounded univariate continuous probability distributions have support on all real numbers.
Normal distribution
Probability density function
If \(\mu \in \mathbb{R}\) and \(\sigma \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{Normal}(y|\mu,\sigma) = \frac{1}{\sqrt{2 \pi} \ \sigma} \exp\left( - \, \frac{1}{2} \left(\frac{y - \mu}{\sigma} \right)^2 \right) \!. \end{equation*}\]
Distribution statement
y ~ normal(mu, sigma)
Increment target log probability density with normal_lupdf(y | mu, sigma).
Stan functions
real normal_lpdf(reals y | reals mu, reals sigma)
The log of the normal density of y given location mu and scale sigma
real normal_lupdf(reals y | reals mu, reals sigma)
The log of the normal density of y given location mu and scale sigma dropping constant additive terms.
real normal_cdf(reals y | reals mu, reals sigma)
The cumulative normal distribution of y given location mu and scale sigma; normal_cdf will underflow to 0 for \(\frac{{y}-{\mu}}{{\sigma}}\) below -37.5 and overflow to 1 for \(\frac{{y}-{\mu}}{{\sigma}}\) above 8.25; the function Phi_approx is more robust in the tails, but must be scaled and translated for anything other than a standard normal.
real normal_lcdf(reals y | reals mu, reals sigma)
The log of the cumulative normal distribution of y given location mu and scale sigma; normal_lcdf will underflow to \(-\infty\) for \(\frac{{y}-{\mu}}{{\sigma}}\) below -37.5 and overflow to 0 for \(\frac{{y}-{\mu}}{{\sigma}}\) above 8.25; log(Phi_approx(...)) is more robust in the tails, but must be scaled and translated for anything other than a standard normal.
real normal_lccdf(reals y | reals mu, reals sigma)
The log of the complementary cumulative normal distribution of y given location mu and scale sigma; normal_lccdf will overflow to 0 for \(\frac{{y}-{\mu}}{{\sigma}}\) below -37.5 and underflow to \(-\infty\) for \(\frac{{y}-{\mu}}{{\sigma}}\) above 8.25; log1m(Phi_approx(...)) is more robust in the tails, but must be scaled and translated for anything other than a standard normal.
R normal_rng(reals mu, reals sigma)
Generate a normal variate with location mu and scale sigma; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Standard normal distribution
The standard normal distribution is so-called because its parameters are the units for their respective operations—the location (mean) is zero and the scale (standard deviation) one. The standard normal is parameter-free, and the unit parameters allow considerable simplification of the expression for the density. \[\begin{equation*} \text{StdNormal}(y) \ = \ \text{Normal}(y \mid 0, 1) \ = \ \frac{1}{\sqrt{2 \pi}} \, \exp \left( \frac{-y^2}{2} \right)\!. \end{equation*}\] Up to a proportion on the log scale, where Stan computes, \[\begin{equation*} \log \text{Normal}(y \mid 0, 1) \ = \ \frac{-y^2}{2} + \text{const}. \end{equation*}\] With no logarithm, no subtraction, and no division by a parameter, the standard normal log density is much more efficient to compute than the normal log density with constant location \(0\) and scale \(1\).
Distribution statement
y ~ std_normal()
Increment target log probability density with std_normal_lupdf(y).
Stan functions
real std_normal_lpdf(reals y)
The standard normal (location zero, scale one) log probability density of y.
real std_normal_lupdf(reals y)
The standard normal (location zero, scale one) log probability density of y dropping constant additive terms.
real std_normal_cdf(reals y)
The cumulative standard normal distribution of y; std_normal_cdf will underflow to 0 for \(y\) below -37.5 and overflow to 1 for \(y\) above 8.25; the function Phi_approx is more robust in the tails.
real std_normal_lcdf(reals y)
The log of the cumulative standard normal distribution of y; std_normal_lcdf will underflow to \(-\infty\) for \(y\) below -37.5 and overflow to 0 for \(y\) above 8.25; log(Phi_approx(...)) is more robust in the tails.
real std_normal_lccdf(reals y)
The log of the complementary cumulative standard normal distribution of y; std_normal_lccdf will overflow to 0 for \(y\) below -37.5 and underflow to \(-\infty\) for \(y\) above 8.25; log1m(Phi_approx(...)) is more robust in the tails.
R std_normal_qf(T x)
Returns the value of the inverse standard normal cdf \(\Phi^{-1}\) at the specified quantile x. The std_normal_qf is equivalent to the inv_Phi function.
R std_normal_log_qf(T x)
Return the value of the inverse standard normal cdf \(\Phi^{-1}\) evaluated at the log of the specified quantile x. This function is equivalent to std_normal_qf(exp(x)) but is more numerically stable.
real std_normal_rng()
Generate a normal variate with location zero and scale one; may only be used in transformed data and generated quantities blocks.
Normal-id generalized linear model (linear regression)
Stan also supplies a single function for a generalized linear model with normal distribution and identity link function, i.e. a function for a linear regression. This provides a more efficient implementation of linear regression than a manually written regression in terms of a normal distribution and matrix multiplication.
Probability distribution function
If \(x\in \mathbb{R}^{n\cdot m}, \alpha \in \mathbb{R}^n, \beta\in \mathbb{R}^m, \sigma\in \mathbb{R}^+\), then for \(y \in \mathbb{R}^n\), \[\begin{equation*} \text{NormalIdGLM}(y|x, \alpha, \beta, \sigma) = \prod_{1\leq i \leq n}\text{Normal}(y_i|\alpha_i + x_i\cdot \beta, \sigma). \end{equation*}\]
Distribution statement
y ~ normal_id_glm(x, alpha, beta, sigma)
Increment target log probability density with normal_id_glm_lupdf(y | x, alpha, beta, sigma).
Stan functions
real normal_id_glm_lpdf(real y | matrix x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(real y | matrix x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(real y | matrix x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(real y | matrix x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(real y | matrix x, real alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(real y | matrix x, real alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(real y | matrix x, vector alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(real y | matrix x, vector alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | row_vector x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | row_vector x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | row_vector x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | row_vector x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | matrix x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | matrix x, real alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | matrix x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | matrix x, vector alpha, vector beta, real sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | matrix x, real alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | matrix x, real alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
real normal_id_glm_lpdf(vector y | matrix x, vector alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma.
real normal_id_glm_lupdf(vector y | matrix x, vector alpha, vector beta, vector sigma)
The log normal probability density of y given location alpha + x * beta and scale sigma dropping constant additive terms.
Exponentially modified normal distribution
Probability density function
If \(\mu \in \mathbb{R}\), \(\sigma \in \mathbb{R}^+\), and \(\lambda \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{ExpModNormal}(y|\mu,\sigma,\lambda) = \frac{\lambda}{2} \ \exp \left(\frac{\lambda}{2} \left(2\mu + \lambda \sigma^2 - 2y\right)\right) \text{erfc}\left(\frac{\mu + \lambda\sigma^2 - y}{\sqrt{2}\sigma}\right) . \end{equation*}\]
Distribution statement
y ~ exp_mod_normal(mu, sigma, lambda)
Increment target log probability density with exp_mod_normal_lupdf(y | mu, sigma, lambda).
Stan functions
real exp_mod_normal_lpdf(reals y | reals mu, reals sigma, reals lambda)
The log of the exponentially modified normal density of y given location mu, scale sigma, and shape lambda
real exp_mod_normal_lupdf(reals y | reals mu, reals sigma, reals lambda)
The log of the exponentially modified normal density of y given location mu, scale sigma, and shape lambda dropping constant additive terms
real exp_mod_normal_cdf(reals y | reals mu, reals sigma, reals lambda)
The exponentially modified normal cumulative distribution function of y given location mu, scale sigma, and shape lambda
real exp_mod_normal_lcdf(reals y | reals mu, reals sigma, reals lambda)
The log of the exponentially modified normal cumulative distribution function of y given location mu, scale sigma, and shape lambda
real exp_mod_normal_lccdf(reals y | reals mu, reals sigma, reals lambda)
The log of the exponentially modified normal complementary cumulative distribution function of y given location mu, scale sigma, and shape lambda
R exp_mod_normal_rng(reals mu, reals sigma, reals lambda)
Generate a exponentially modified normal variate with location mu, scale sigma, and shape lambda; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Skew normal distribution
Probability density function
If \(\xi \in \mathbb{R}\), \(\omega \in \mathbb{R}^+\), and \(\alpha \in \mathbb{R}\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{SkewNormal}(y \mid \xi, \omega, \alpha) = \frac{1}{\omega\sqrt{2\pi}} \ \exp\left( - \, \frac{1}{2} \left( \frac{y - \xi}{\omega} \right)^2 \right) \ \left(1 + \text{erf}\left( \alpha\left(\frac{y - \xi}{\omega\sqrt{2}}\right)\right)\right) . \end{equation*}\]
Distribution statement
y ~ skew_normal(xi, omega, alpha)
Increment target log probability density with skew_normal_lupdf(y | xi, omega, alpha).
Stan functions
real skew_normal_lpdf(reals y | reals xi, reals omega, reals alpha)
The log of the skew normal density of y given location xi, scale omega, and shape alpha
real skew_normal_lupdf(reals y | reals xi, reals omega, reals alpha)
The log of the skew normal density of y given location xi, scale omega, and shape alpha dropping constant additive terms
real skew_normal_cdf(reals y | reals xi, reals omega, reals alpha)
The skew normal distribution function of y given location xi, scale omega, and shape alpha
real skew_normal_lcdf(reals y | reals xi, reals omega, reals alpha)
The log of the skew normal cumulative distribution function of y given location xi, scale omega, and shape alpha
real skew_normal_lccdf(reals y | reals xi, reals omega, reals alpha)
The log of the skew normal complementary cumulative distribution function of y given location xi, scale omega, and shape alpha
R skew_normal_rng(reals xi, reals omega, real alpha)
Generate a skew normal variate with location xi, scale omega, and shape 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.
Student-t distribution
Probability density function
If \(\nu \in \mathbb{R}^+\), \(\mu \in \mathbb{R}\), and \(\sigma \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{StudentT}(y|\nu,\mu,\sigma) = \frac{\Gamma\left((\nu + 1)/2\right)} {\Gamma(\nu/2)} \ \frac{1}{\sqrt{\nu \pi} \ \sigma} \ \left( 1 + \frac{1}{\nu} \left(\frac{y - \mu}{\sigma}\right)^2 \right)^{-(\nu + 1)/2} \! . \end{equation*}\]
Distribution statement
y ~ student_t(nu, mu, sigma)
Increment target log probability density with student_t_lupdf(y | nu, mu, sigma).
Stan functions
real student_t_lpdf(reals y | reals nu, reals mu, reals sigma)
The log of the Student-\(t\) density of y given degrees of freedom nu, location mu, and scale sigma
real student_t_lupdf(reals y | reals nu, reals mu, reals sigma)
The log of the Student-\(t\) density of y given degrees of freedom nu, location mu, and scale sigma dropping constant additive terms
real student_t_cdf(reals y | reals nu, reals mu, reals sigma)
The Student-\(t\) cumulative distribution function of y given degrees of freedom nu, location mu, and scale sigma
real student_t_lcdf(reals y | reals nu, reals mu, reals sigma)
The log of the Student-\(t\) cumulative distribution function of y given degrees of freedom nu, location mu, and scale sigma
real student_t_lccdf(reals y | reals nu, reals mu, reals sigma)
The log of the Student-\(t\) complementary cumulative distribution function of y given degrees of freedom nu, location mu, and scale sigma
R student_t_rng(reals nu, reals mu, reals sigma)
Generate a Student-\(t\) variate with degrees of freedom nu, location mu, and scale sigma; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Cauchy distribution
Probability density function
If \(\mu \in \mathbb{R}\) and \(\sigma \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{Cauchy}(y|\mu,\sigma) = \frac{1}{\pi \sigma} \ \frac{1}{1 + \left((y - \mu)/\sigma\right)^2} . \end{equation*}\]
Distribution statement
y ~ cauchy(mu, sigma)
Increment target log probability density with cauchy_lupdf(y | mu, sigma).
Stan functions
real cauchy_lpdf(reals y | reals mu, reals sigma)
The log of the Cauchy density of y given location mu and scale sigma
real cauchy_lupdf(reals y | reals mu, reals sigma)
The log of the Cauchy density of y given location mu and scale sigma dropping constant additive terms
real cauchy_cdf(reals y | reals mu, reals sigma)
The Cauchy cumulative distribution function of y given location mu and scale sigma
real cauchy_lcdf(reals y | reals mu, reals sigma)
The log of the Cauchy cumulative distribution function of y given location mu and scale sigma
real cauchy_lccdf(reals y | reals mu, reals sigma)
The log of the Cauchy complementary cumulative distribution function of y given location mu and scale sigma
R cauchy_rng(reals mu, reals sigma)
Generate a Cauchy variate with location mu and scale sigma; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Double exponential (Laplace) distribution
Probability density function
If \(\mu \in \mathbb{R}\) and \(\sigma \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{DoubleExponential}(y|\mu,\sigma) = \frac{1}{2\sigma} \exp \left( - \, \frac{|y - \mu|}{\sigma} \right) . \end{equation*}\] Note that the double exponential distribution is parameterized in terms of the scale, in contrast to the exponential distribution (see section exponential distribution), which is parameterized in terms of inverse scale.
The double-exponential distribution can be defined as a compound exponential-normal distribution (Ding and Blitzstein 2018). Using the inverse scale parameterization for the exponential distribution, and the standard deviation parameterization for the normal distribution, one can write \[\begin{equation*} \alpha \sim \mathsf{Exponential}\left( \frac{1}{2 \sigma^2} \right) \end{equation*}\] and \[\begin{equation*} \beta \mid \alpha \sim \mathsf{Normal}(\mu, \sqrt{\alpha}), \end{equation*}\] then \[\begin{equation*} \beta \sim \mathsf{DoubleExponential}(\mu, \sigma ). \end{equation*}\] This may be used to code a non-centered parameterization by taking \[\begin{equation*} \beta^{\text{raw}} \sim \mathsf{Normal}(0, 1) \end{equation*}\] and defining \[\begin{equation*} \beta = \mu + \sqrt{\alpha} \, \beta^{\text{raw}}. \end{equation*}\]
Distribution statement
y ~ double_exponential(mu, sigma)
Increment target log probability density with double_exponential_lupdf(y | mu, sigma).
Stan functions
real double_exponential_lpdf(reals y | reals mu, reals sigma)
The log of the double exponential density of y given location mu and scale sigma
real double_exponential_lupdf(reals y | reals mu, reals sigma)
The log of the double exponential density of y given location mu and scale sigma dropping constant additive terms
real double_exponential_cdf(reals y | reals mu, reals sigma)
The double exponential cumulative distribution function of y given location mu and scale sigma
real double_exponential_lcdf(reals y | reals mu, reals sigma)
The log of the double exponential cumulative distribution function of y given location mu and scale sigma
real double_exponential_lccdf(reals y | reals mu, reals sigma)
The log of the double exponential complementary cumulative distribution function of y given location mu and scale sigma
R double_exponential_rng(reals mu, reals sigma)
Generate a double exponential variate with location mu and scale sigma; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Logistic distribution
Probability density function
If \(\mu \in \mathbb{R}\) and \(\sigma \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{Logistic}(y|\mu,\sigma) = \frac{1}{\sigma} \ \exp\!\left( - \, \frac{y - \mu}{\sigma} \right) \ \left(1 + \exp \!\left( - \, \frac{y - \mu}{\sigma} \right) \right)^{\!-2} \! . \end{equation*}\]
Distribution statement
y ~ logistic(mu, sigma)
Increment target log probability density with logistic_lupdf(y | mu, sigma).
Stan functions
real logistic_lpdf(reals y | reals mu, reals sigma)
The log of the logistic density of y given location mu and scale sigma
real logistic_lupdf(reals y | reals mu, reals sigma)
The log of the logistic density of y given location mu and scale sigma dropping constant additive terms
real logistic_cdf(reals y | reals mu, reals sigma)
The logistic cumulative distribution function of y given location mu and scale sigma
real logistic_lcdf(reals y | reals mu, reals sigma)
The log of the logistic cumulative distribution function of y given location mu and scale sigma
real logistic_lccdf(reals y | reals mu, reals sigma)
The log of the logistic complementary cumulative distribution function of y given location mu and scale sigma
R logistic_rng(reals mu, reals sigma)
Generate a logistic variate with location mu and scale sigma; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Gumbel distribution
Probability density function
If \(\mu \in \mathbb{R}\) and \(\beta \in \mathbb{R}^+\), then for \(y \in \mathbb{R}\), \[\begin{equation*} \text{Gumbel}(y|\mu,\beta) = \frac{1}{\beta} \ \exp\left(-\frac{y-\mu}{\beta}-\exp\left(-\frac{y-\mu}{\beta}\right)\right) . \end{equation*}\]
Distribution statement
y ~ gumbel(mu, beta)
Increment target log probability density with gumbel_lupdf(y | mu, beta).
Stan functions
real gumbel_lpdf(reals y | reals mu, reals beta)
The log of the gumbel density of y given location mu and scale beta
real gumbel_lupdf(reals y | reals mu, reals beta)
The log of the gumbel density of y given location mu and scale beta dropping constant additive terms
real gumbel_cdf(reals y | reals mu, reals beta)
The gumbel cumulative distribution function of y given location mu and scale beta
real gumbel_lcdf(reals y | reals mu, reals beta)
The log of the gumbel cumulative distribution function of y given location mu and scale beta
real gumbel_lccdf(reals y | reals mu, reals beta)
The log of the gumbel complementary cumulative distribution function of y given location mu and scale beta
R gumbel_rng(reals mu, reals beta)
Generate a gumbel variate with location mu and scale 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.
Skew double exponential distribution
Probability density function
If \(\mu \in \mathbb{R}\), \(\sigma \in \mathbb{R}^+\) and \(\tau \in [0, 1]\), then for \(y \in \mathbb{R}\), \[\begin{aligned} & \text{SkewDoubleExponential} (y|\mu,\sigma, \tau) = \\ & \qquad \qquad \frac{2 \tau (1 - \tau) }{\sigma} \exp \left[ - \frac{2}{\sigma} \left[ \left(1 - \tau \right) I(y < \mu) (\mu - y) + \tau I(y > \mu)(y-\mu) \right] \right] \end{aligned}\]
Distribution statement
y ~ skew_double_exponential(mu, sigma, tau)
Increment target log probability density with skew_double_exponential(y | mu, sigma, tau)
Stan functions
real skew_double_exponential_lpdf(reals y | reals mu, reals sigma, reals tau)
The log of the skew double exponential density of y given location mu, scale sigma and skewness tau
real skew_double_exponential_lupdf(reals y | reals mu, reals sigma, reals tau)
The log of the skew double exponential density of y given location mu, scale sigma and skewness tau dropping constant additive terms
real skew_double_exponential_cdf(reals y | reals mu, reals sigma, reals tau)
The skew double exponential cumulative distribution function of y given location mu, scale sigma and skewness tau
real skew_double_exponential_lcdf(reals y | reals mu, reals sigma, reals tau)
The log of the skew double exponential cumulative distribution function of y given location mu, scale sigma and skewness tau
real skew_double_exponential_lccdf(reals y | reals mu, reals sigma, reals tau)
The log of the skew double exponential complementary cumulative distribution function of y given location mu, scale sigma and skewness tau
R skew_double_exponential_rng(reals mu, reals sigma, reals tau)
Generate a skew double exponential variate with location mu, scale sigma and skewness tau; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.