Cauchy Distribution

Table of contents


Density Function

The density function of the Cauchy distribution:

\[f(x; \mu, \sigma) = \dfrac{1}{\pi \sigma \left[ 1 + \left( \frac{x - \mu}{\sigma} \right)^2 \right]}\]

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.dcauchy(x: float, mu: float = 0.0, sigma: float = 1.0, log: bool = False) float

Density function of the Cauchy distribution.

Example

>>> pystats.dcauchy(2.5, 1.0, 3.0)
0.084883
Parameters
  • x (float) – A real-valued input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

The density function evaluated at x.

List Input

pystats.dcauchy(x: List[float], mu: float = 0.0, sigma: float = 1.0, log: bool = False) List[float]

Density function of the Cauchy distribution.

Example

>>> pystats.dcauchy([0.0, 1.0, 2.0], 1.0, 2.0)
[0.12732395447351627, 0.15915494309189535, 0.12732395447351627]
Parameters
  • x (List[float]) – A standard list input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

A list of density values corresponding to the elements of x.


Cumulative Distribution Function

The cumulative distribution function (CDF) of the Cauchy distribution:

\[F(x; \mu, \sigma) = \int_{-\infty}^x f(z; \mu, \sigma) dz = 0.5 + \dfrac{1}{\pi} \text{arctan}\left( \frac{x - \mu}{\sigma} \right)\]

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.pcauchy(p: float, mu: float = 0.0, sigma: float = 1.0, log: bool = False) float

Distribution function of the Cauchy distribution.

Example

>>> pystats.pcauchy(2.5, 1.0, 3.0)
0.647584
Parameters
  • p (float) – A real-valued input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

The cumulative distribution function evaluated at p.

List Input

pystats.pcauchy(p: List[float], mu: float = 0.0, sigma: float = 1.0, log: bool = False) List[float]

Distribution function of the Cauchy distribution.

Example

>>> pystats.pcauchy([0.0, 1.0, 2.0], 1.0, 2.0)
[0.35241638234956674, 0.5, 0.6475836176504333]
Parameters
  • p (List[float]) – A standard list input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

A list of CDF values corresponding to the elements of p.


Quantile Function

The quantile function of the Cauchy distribution:

\[q(p; \mu, \sigma) = \mu + \gamma \text{tan} \left( \pi (p - 0.5) \right)\]

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.qcauchy(q: float, mu: float = 0.0, sigma: float = 1.0) float

Quantile function of the Cauchy distribution.

Example

>>> pystats.qcauchy(0.5, 1, 3.0)
0.647584
Parameters
  • q (float) – A real-valued input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

Returns

The quantile function evaluated at q.

List Input

pystats.qcauchy(q: List[float], mu: float = 0.0, sigma: float = 1.0) List[float]

Quantile function of the Cauchy distribution.

Example

>>> pystats.qcauchy([0.1, 0.3, 0.7], 1.0, 2.0)
[-5.155367074350508, -0.45308505601072185, 2.453085056010721]
Parameters
  • q (List[float]) – A standard list input.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

Returns

A list of quantiles values corresponding to the elements of q.


Random Sampling

Random sampling for the Cauchy distribution is achieved via the inverse probability integral transform.

Scalar Output

pystats.rcauchy(mu: float = 0.0, sigma: float = 1.0) float

Random sampling function for the Cauchy distribution.

Example

>>> pystats.rcauchy(1.0, 2.0)
9.93054237677352
Parameters
  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

Returns

A pseudo-random draw from the Cauchy distribution.

List Output

pystats.rcauchy(n: int, mu: float = 0.0, sigma: float = 1.0) List[float]

Random sampling function for the Cauchy distribution.

Example

>>> pystats.rcauchy(1.0, 2.0)
[-2.383182638662492, 1.0766564460128407, -20.367599105297693, -0.9512379893292959, -0.17185207327053853]
Parameters
  • n (int) – The number of output values.

  • mu (float) – The location parameter, a real-valued input.

  • sigma (float) – The scale parameter, a real-valued input.

Returns

A list of pseudo-random draws from the Cauchy distribution.