Skip to content

Distributions

This serves as reference for all distribution objects that we implement in the ROLCH package.

Note

This page is somewhat under construction, since MkDocs does not support docstring inheritance at the moment.

All distributions are based on scipy.stats distributions. We implement the probability density function (PDF), the cumulative density function (CDF), the percentage point or quantile function (PPF) and the random variates (RVS) accordingly as pass-through. The link functions are implemented in the same way as in GAMLSS (Rigby & Stasinopoulos, 2005). The link functions and their derivatives derive from the LinkFunction base class.

Base Class

rolch.abc.Distribution

Bases: ABC

cdf abstractmethod

cdf(y: np.ndarray, theta: np.ndarray) -> np.ndarray

The cumulative density function.

dl1_dp1 abstractmethod

dl1_dp1(y: np.ndarray, theta: np.ndarray, param: int) -> np.ndarray

Take the first derivative of the likelihood function with respect to the param.

dl2_dp2 abstractmethod

dl2_dp2(y: np.ndarray, theta: np.ndarray, param: int) -> np.ndarray

Take the second derivative of the likelihood function with respect to the param.

dl2_dpp abstractmethod

dl2_dpp(y: np.ndarray, theta: np.ndarray, params: Tuple[int, int]) -> np.ndarray

Take the first derivative of the likelihood function with respect to both parameters.

initial_values abstractmethod

initial_values(y: np.ndarray, param: int = 0, axis: int = None) -> np.ndarray

Calculate the initial values for the GAMLSS fit.

link_derivative(y: np.ndarray, param: int = 0) -> np.ndarray

Apply the derivative of the link function for param on y.

link_function(y: np.ndarray, param: int = 0) -> np.ndarray

Apply the link function for param on y.

link_inverse(y: np.ndarray, param: int = 0) -> np.ndarray

Apply the inverse of the link function for param on y.

pdf abstractmethod

pdf(y: np.ndarray, theta: np.ndarray) -> np.ndarray

The density function.

ppf abstractmethod

ppf(q: np.ndarray, theta: np.ndarray) -> np.ndarray

The percentage point or quantile function of the distribution.

rvs abstractmethod

rvs(size: Union[int, Tuple], theta: np.ndarray) -> np.ndarray

Draw random samples of shape size.

theta_to_params abstractmethod

theta_to_params(theta: np.ndarray) -> Tuple

Take the fitted values and return tuple of vectors for distribution parameters.

API Reference

rolch.DistributionNormal

Bases: Distribution

Corresponds to GAMLSS NO() and scipy.stats.norm()

rolch.DistributionT

Bases: Distribution

Corresponds to GAMLSS TF() and scipy.stats.t()

rolch.DistributionJSU

Bases: Distribution

Corresponds to GAMLSS JSUo() and scipy.stats.johnsonsu()

Distribution parameters: 0 : Location 1 : Scale (close to standard deviation) 2 : Skewness 3 : Tail behaviour

rolch.DistributionGamma

Bases: Distribution

The Gamma Distribution for GAMLSS.

The distribution function is defined as in GAMLSS as: $$ f(y|\mu,\sigma)=\frac{y^{(1/\sigma^2-1)}\exp[-y/(\sigma^2 \mu)]}{(\sigma^2 \mu)^{(1/\sigma^2)} \Gamma(1/\sigma^2)} $$

with the location and shape parameters \(\mu, \sigma > 0\).

Note

The function is parameterized as GAMLSS' GA() distribution.

This parameterization is different to the scipy.stats.gamma(alpha, loc, scale) parameterization.

We can use DistributionGamma().gamlss_to_scipy(mu, sigma) to map the distribution parameters to scipy.

The scipy.stats.gamma() distribution is defined as: $$ f(x, \alpha, \beta) = \frac{\beta^\alpha x^{\alpha - 1} \exp[-\beta x]}{\Gamma(\alpha)} $$

with the paramters \(\alpha, \beta >0\). The parameters can be mapped as follows: $$ \alpha = 1/\sigma^2 \Leftrightarrow \sigma = \sqrt{1 / \alpha} $$ and $$ \beta = 1/(\sigma^2\mu). $$

Parameters:

Name Type Description Default
loc_link LinkFunction

The link function for \(\mu\). Defaults to LogLink().

LogLink()
scale_link LinkFunction

The link function for \(\sigma\). Defaults to LogLink().

LogLink()

gamlss_to_scipy staticmethod

gamlss_to_scipy(mu: np.ndarray, sigma: np.ndarray)

Map GAMLSS Parameters to scipy parameters.

Parameters:

Name Type Description Default
mu ndarray

mu parameter

required
sigma ndarray

sigma parameter

required

Returns:

Name Type Description
tuple

Tuple of (alpha, loc, scale) for scipy.stats.gamma(alpha, loc, scale)