Helpful Stan Functions
Quantile Functions also known as Inverse Cumulative Distribution Functions

Modules

 Johnson Quantile Parameterized Distributions (J-QPD) functions
 
 Student T Quantile functions
 

Functions

real lognormal_qf (real p, real mu, real sigma)
 
real skew_generalized_t_qf (real x, real mu, real sigma, real lambda, real p, real q)
 
real unit_johnson_qf (real p, real mu, real sigma)
 

Detailed Description

In probability and statistics, the quantile function - also known as
an inverse cumulative distribution function - is, associated with a probability distribution of a random variable, specifies the value of the random variable such that the probability of the variable being less than or equal to that value equals the given probability.

See https://en.wikipedia.org/wiki/Quantile_function for more information.

Function Documentation

◆ lognormal_qf()

real lognormal_qf ( real  p,
real  mu,
real  sigma 
)

Lognormal Quantile Function

\begin{aligned} F^{-1}(p) &= \exp(\mu + \sqrt{2} \, \sigma \, \text{inv_erf}(2p - 1)) \\ &= \exp(\mu + \sigma \, \Phi^{−1}(x)) \end{aligned}

because

\begin{aligned} \Phi(x) &= \frac{1}{2\pi} \int_{-\infty}^x e^{-t^2}dt \\ &= \frac{1}{2} + \frac{1}{2}\text{erf}\bigg( \frac{x}{\sqrt{2}} \bigg) \end{aligned}

implies that \( \Phi^{-1}(x) = \sqrt{2} \, \text{inv_erf}(2x - 1) \).

real lognormal_qf(real p, real mu, real sigma) {
if (is_nan(p) || p < 0 || p > 1)
reject("lognormal_icdf: p must be between 0 and 1; ", "found p = ", p);
if (is_nan(mu) || is_inf(mu))
reject("lognormal_icdf: mu must be finite; ", "found mu = ", mu);
if (is_nan(sigma) || is_inf(sigma) || sigma <= 0)
reject("lognormal_icdf: sigma must be finite and > 0; ", "found sigma = ", sigma);
return exp(mu + sigma * inv_Phi(p));
}
real lognormal_qf(real p, real mu, real sigma)
Definition: lognormal_qf.stanfunctions:25
Author
Sean Pinkney
Parameters
pReal on \([0,\,1]\)
muReal \((-\infty, +\infty)\)
sigmaReal \((0, +\infty)\)
Returns
inverse CDF value
Exceptions
rejectif \( p \notin [0, 1] \)

◆ skew_generalized_t_qf()

real skew_generalized_t_qf ( real  x,
real  mu,
real  sigma,
real  lambda,
real  p,
real  q 
)

Skewed Generalized T Quantile Function

For more information, please see Skew Generalized T distribution functions.

Author
Sean Pinkney
Parameters
quantReal on \([0,\,1]\)
muReal
sigmaReal \(\in (0, \infty)\) scale parameter
lambdaReal \(-1 < \lambda < 1\)
rReal \(\in (0, \infty)\) kurtosis parameter
qReal \(\in (0, \infty)\) kurtosis parameter
Returns
quantile of skew_generalized_t

◆ unit_johnson_qf()

real unit_johnson_qf ( real  p,
real  mu,
real  sigma 
)

Unit Johnson SU Quantile Function

\begin{aligned} F^{-1}(p, \, \mu, \, \sigma) &= \text{inv_logit}\bigg[ \sinh\bigg(\frac{\Phi^{-1}(p) - \mu}{\sigma}\bigg) \bigg]\\ \end{aligned}

real unit_johnson_qf(real p, real mu, real sigma) {
if (is_nan(p) || p < 0 || p > 1)
reject("unit_johnson_icdf: p must be between 0 and 1; ", "found p = ", p);
if (is_nan(mu) || is_inf(mu))
reject("unit_johnson_icdf: mu must be finite; ", "found mu = ", mu);
if (is_nan(sigma) || is_inf(sigma) || sigma <= 0)
reject("unit_johnsonl_icdf: sigma must be finite and > 0; ", "found sigma = ", sigma);
real x = sinh((inv_Phi(p) - mu) / sigma);
return inv_logit(x);
}
real unit_johnson_qf(real p, real mu, real sigma)
Definition: unit_johnson_su_qf.stanfunctions:17
Author
Sean Pinkney
Parameters
pReal on \([0,\,1]\)
muReal \((-\infty, +\infty)\)
sigmaReal \((0, +\infty)\)
Returns
inverse CDF value
Exceptions
rejectif \( p \notin [0, 1] \)