Skip to main content

The skew student t distribution

Project description

Downloads

Skew student $t$ distribution

Skewt-Scipy is a Python package for skew student $t$ distribution.

Skew student $t$ distribution

We employ the definition of the skew-t distribution from Azzalini (2014, Section 4.3.1). Firstly, we need two density functions: $t$ distribution and skew-normal distribution respectively. The $t$ distribution is defined as:

$$ f_{t}(x|\nu) = \frac{\Gamma(\frac{\nu+1}{2})}{\sqrt{\nu\pi}\Gamma(\frac{\nu}{2})}\left(1+\frac{x^{2}}{\nu}\right)^{-\frac{\nu+1}{2}}, \quad x\in \mathbb{R},\quad \nu>0, $$

where $\nu$ denotes the degree of freedom. The skew-normal distribution is defined as:

$$ f_{sn}(x|\xi,\omega,\alpha) = \frac{2}{\omega}\phi\left(\frac{x-\xi}{\omega}\right)\Phi\left(\alpha \left( \frac{x-\xi}{\omega} \right)\right), \quad x\in \mathbb{R},\quad \omega>0,\quad \alpha\in \mathbb{R}, $$

where $\xi, \omega$ are the location and scale parameters respectively. $\alpha$ is the skewness parameter. $\phi(\cdot)$ and $\Phi(\cdot)$ are the standard normal density function and cumulative distribution function respectively.

The skew-t variable can be defined as:

$$ Z= \frac{Z_{0}}{\sqrt{V}}, $$

where $Z_{0}\sim f_{sn}(x|0,1,\alpha)$ and $V\sim \chi^{2}_{\nu}/\nu$ are independent. Then, the density function of $Z$ is

$$ f_{st}(\alpha,\nu)= 2f_{t}(x|\nu)F_{t}\left(\alpha x\sqrt{\frac{\nu+1}{\nu+x^{2}}}\Big|\nu+1\right), $$

where $F_{t}(\cdot|\nu+1)$ represent the $t$ cumulative density function with degree of freedom $\nu+1$. As $\alpha\in \mathbb{R}$ and $\nu>0$, then skew-t distribution can degenerate several special distributions.

Installation

Install via pip with

python3 -m pip install skewt_scipy

Usage

As the class skewt inherits from the class rv_continuous of Scipy, many methods are available. The shape parameters a and df represent $\alpha$ and $\nu$ (the degree of freedom).

Method Description
rvs(a, df, loc=0, scale=1, size=1, random_state=None) Random variates.
pdf(x, a, df, loc=0, scale=1) Probability density function.
logpdf(x, a, df, loc=0, scale=1) Log of the probability density function.
cdf(x, a, df, loc=0, scale=1) Cumulative distribution function.
logcdf(x, a, df, loc=0, scale=1) Log of the cumulative distribution function.
ppf(q, a, df, loc=0, scale=1) Percent point function (inverse of cdf).
stats(a, df, loc=0, scale=1, moments='mvsk') Mean('m'), variance('v'), skew('s'), and/or kurtosis('k').
fit(data) Parameter estimates for generic data.

Note that the parameters $\alpha =\pm\infty$ and $\nu=+\infty$ are valid for the above methods.

Examples

import numpy as np

from skewt_scipy.skewt import skewt

# random number generator
skewt.rvs(a=10, df=6, loc=3, scale=2, size=10)

# probability distribution
x = (np.linspace(-50, 50, 100),)
skewt.pdf(x=x, a=-10, df=6, loc=3, scale=2)

# log of probability distribution
skewt.logpdf(x=x, a=-10, df=6, loc=3, scale=2)

# cumulative distribution
skewt.cdf(x=x, a=8, df=10, loc=3, scale=2)

# log of cumulative distribution
skewt.logcdf(x=x, a=8, df=10, loc=3, scale=2)

# percent point function
skewt.ppf(np.array([0.5, 0.9, 0.99]), a=3, df=6, loc=3, scale=2)

a = 3
df = 5
loc = 3
scale = 2
data = skewt.rvs(a=a, scale=scale, df=df, loc=loc, size=10000, random_state=123)
skewt.fit(data)
skewt.fit(data, fdf=df)  # fixed df
skewt.fit(data, fa=a, fdf=df)  # fixed a and df

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skewt_scipy-0.1.2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skewt_scipy-0.1.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file skewt_scipy-0.1.2.tar.gz.

File metadata

  • Download URL: skewt_scipy-0.1.2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for skewt_scipy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 46316dfaa77b64f46f814cc29ea881a85c9e4b665ac64452e698e3b547b81bba
MD5 3420e656e7291e0d5d60579ce224e985
BLAKE2b-256 1cbd51db26f916db8663fcb60b6e405763b2604a6ca3dbb0235818238dba8a4c

See more details on using hashes here.

File details

Details for the file skewt_scipy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: skewt_scipy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for skewt_scipy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93c97eb16816dcc33dbe637cc44dc40e411c7e2be6623b94834f97d75771da98
MD5 bf0e5a092fa4fb844178f5f403f9ef00
BLAKE2b-256 17f59665f4ccc01d0c99df08eee2e8c0d74b81c38fb18cd78aa3f6e77205e6b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page