Library for accurate statistical calculations using Python.
Project description
Python Probabilities 🐍
Library for accurate statistical calculations using Python.
Binomial Distributions
Probability mass function
BinomialPD(r, n, p)
For the random variable X
with the binomial distribution B(n, p)
, calculate the probability mass function.
Where r
is the number of successes, n
is the number of trials, and p
is the probability of success.
Example
To calculate P(X=7)
for the binomial distribution X~B(11, 0.33)
:
>>> from python_probabilities import BinomialPD
>>> BinomialPD(7, 11, 0.33)
0.029656979029412885
Cumulative distribution function
BinomialCD(r, n, p)
For the random variable X
with the binomial distribution B(n, p)
, calculate the cumulative distribution function.
Where r
is the number of successes, n
is the number of trials, and p
is the probability of success.
Example
To calculate P(X≤7)
for the binomial distribution X~B(11, 0.33)
:
>>> from python_probabilities import BinomialCD
>>> BinomialCD(7, 11, 0.33)
0.9912362670526581
Inverse cumulative distribution function
InvBinomialCD(q, n, p)
For the random variable X
with the binomial distribution B(n, p)
, calculate the inverse for the cumulative distribution function.
Where q
is the cumulative probability, n
is the number of trials, and p
is the probability of success.
InvBinomialCD(q, n, p)
returns the smallest integer x
such that BinomialCD(x, n, p)
is greater than or equal to q
.
Example
To calculate the corresponding value for r
(the number of successes) given the value for q
(the cumulative probability):
>>> from python_probabilities import BinomialCD, InvBinomialCD
>>> InvBinomialCD(0.9912362670526581, 11, 0.333)
7
>>> BinomialCD(7, 11, 0.333)
0.9912362670526581
Normal Distributions
Probability density function
NormalPD(x, µ, σ)
Probability density function for the normal distribution X~N(µ, σ)
.
Where µ
is the mean, and σ
is the standard deviation.
Cumulative distribution function
NormalCD(x, µ, σ)
Cumulative distribution function for the normal distribution X~N(µ, σ)
.
Where µ
is the mean, and σ
is the standard deviation.
Example
To calculate P(X≤0.891)
for the normal distribution X~N(0.734, 0.114)
:
>>> from python_probabilities import NormalCD
>>> NormalCD(0.891, 0.734, 0.114)
0.9157737045522477
Inverse cumulative distribution function
InvNormalCD(y, µ, σ)
Inverse cumulative distribution function for the normal distribution X~N(µ, σ)
.
Where µ
is the mean, and σ
is the standard deviation.
InvNormalCD(y, µ, σ)
returns the smallest integer x
such that NormalCD(x, µ, σ)
is greater than or equal to y
.
Example
To calculate the corresponding value for x
given the value for y
:
>>> from python_probabilities import NormalCD, InvNormalCD
>>> InvNormalCD(0.9157737045522477, 0.734, 0.114)
0.891
>>> NormalCD(0.891, 0.734, 0.114)
0.9157737045522477
Poisson Distributions
Probability mass function
PoissonPD(r, m)
For the random variable X
with the poisson distribution Po(m)
, calculate the probability mass function.
Where r
is the number of occurrences, and m
is the mean rate of occurrence.
Example
To calculate P(X=7)
for the poisson distribution X~Po(11.556)
:
>>> from python_probabilities import PoissonPD
>>> PoissonPD(11, 23.445)
0.0019380401123575617
Cumulative distribution function
PoissonCD(r, m)
For the random variable X
with the poisson distribution Po(m)
, calculate the cumulative distribution function.
Where r
is the number of occurrences, and m
is the mean rate of occurrence.
Example
To calculate P(X≤7)
for the poisson distribution X~Po(11.556)
:
>>> from python_probabilities import PoissonCD
>>> PoissonCD(11, 23.445)
0.0034549033698374467
Inverse cumulative distribution
InvPoissonCD(q, m)
For the random variable X
with the poisson distribution Po(m)
, calculate the inverse for the cumulative distribution function.
Where q
is the cumulative probability, and m
is the mean rate of occurrence.
InvPoissonCD(q, m)
returns the smallest integer x
such that PoissonCD(x, m)
is greater than or equal to q
.
Example
To calculate the corresponding value for r
(number of occurrences) given the values for q
(cumulative probability):
>>> from python_probabilities import PoissonCD, InvPoissonCD
>>> InvPoissonCD(0.0034549033698374467, 23.445)
11
>>> PoissonCD(11, 23.445)
0.0034549033698374467
Geometric Distributions
Probability mass function
GeometricPD(x, p)
Probability mass function for the geometric distribution X~G(p)
.
Where x
is the number of trials before the first success, and p
is the probability of success.
Example
To calculate P(X=3)
for the geometric distribution X~G(0.491)
:
>>> from python_probabilities import GeometricPD
>>> GeometricPD(3, 0.491)
0.127208771
Cumulative distribution function
GeometricCD(x, p)
Cumulative distribution function for the geometric distribution X~G(p)
.
Where x
is the number of trials before the first success, and p
is the probability of success.
Example
To calculate P(X≤3)
for the geometric distribution X~G(0.491)
:
>>> from python_probabilities import GeometricCD
>>> GeometricCD(3, 0.491)
0.868127771
Inverse cumulative distribution function
InvGeometricCD(area, p)
Inverse cumulative distribution function for the geometric distribution X~G(p)
.
Where x
is the number of trials before the first success, and p
is the probability of success.
InvGeometricCD(area, p)
returns the smallest integer x
such that GeometricCD(x, p)
is greater than or equal to area
.
Example
To calculate the corresponding value for x
given the value for area
:
>>> from python_probabilities import GeometricCD, InvGeometricCD
>>> InvGeometricCD(0.868, 0.491)
3
>> GeometricCD(3, 0.491)
0.868127771
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
Built Distribution
Hashes for python_probabilities-0.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5c72fffe956bc67c602d4ba9397b6008039c94c55c5eceda690424e4d909a3f |
|
MD5 | 19377051cdde0651f063ae50a6fd4214 |
|
BLAKE2b-256 | ef8d5ae2c1dcb4f36346cfbf4ca75ada0ac22d44dd5f52b418279bf9508ba8b0 |
Hashes for python_probabilities-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d29993042c033e585a2a2b54922e101928940baaeff7baebe14b3817ff6d8acd |
|
MD5 | 199931bf16ac035082bb97c6e545b484 |
|
BLAKE2b-256 | 28c5c6d781fb819513ef04313efd669fe7e25b4039a5a9c9e95cbb11eaf902c9 |