6626070
2997924

MATH05, Distribution

Back to the previous pageStatistics
List of posts to read before reading this article


Contents


$$Parameters(loc,\ scale)\ :\ y=\frac{x-loc}{scale}$$ $$Parameter(df)\ :\ a\ shape\ parameter$$

Discrete distribution

Objective :

When something is important enough, you do it even if the odds are not in your favor.


Geometric


Poisson


Logarithmic


NegativeBinomial


YuleSimon


Zeta


Continous distribution

Objective :

When something is important enough, you do it even if the odds are not in your favor.


Beta

Another programming language code

mathematica code, Beta.nb


$$f(x; a, b) = \frac{\Gamma(a+b) x^{a-1} (1-x)^{b-1}}{\Gamma(a) \Gamma(b)}\qquad for\ 0\le x \le 1,\ \ \ \ a>0,\ b>0$$

Main code

# [] : 
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

# [] : 
X = stats.beta(a=5, b=0.1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100)

# [] : 
fig,ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.beta, kde=False, ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.beta(a=5, b=0.1,loc=1, scale=1)
sns.distplot(X.rvs(100), fit=stats.beta, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.beta(a=5, b=0.1,loc=1, scale=1)
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.beta(a=5, b=0.1,loc=1, scale=1)
x = np.linspace(*X.interval(0.999), num=100)

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 a, b, loc, scale \(\xrightarrow{stats.beta}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





ChiSquared

Another programming language code

mathematica code, ChiSquared.nb


$$f(x; k) = \frac{1}{2^{k/2} \Gamma \left( k/2 \right)}x^{k/2-1} \exp \left( -x/2 \right)\qquad for\ x>0\ and\ k>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.chi2(df=1,loc=1, scale=1)      # df : parameter k
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.chi2, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (1)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.chi2(df=1,loc=1, scale=1)      # df : parameter k
sns.distplot(X.rvs(100), fit=stats.chi2, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.chi2(df=1,loc=1, scale=1)      # df : parameter k
sns.distplot(X.rvs(100))  
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.chi2(df=1,loc=1, scale=1)      # df : parameter k
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 df, loc, scale \(\xrightarrow{stats.chi2}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





Exponential

Another programming language code

mathematica code, Exponential.nb


$$f(x) = \lambda*\exp(-\lambda*x)\qquad for\ x\ge0$$ $$scale\ =\ 1/\lambda$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.expon(scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig, ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.expon, kde=False, ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (2)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.expon(scale=1) 
sns.distplot(X.rvs(100), fit=stats.expon, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.expon(scale=1) 
sns.distplot(X.rvs(100))  
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.expon(scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 scale \(\xrightarrow{stats.expon}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





FDistribution

Another programming language code

mathematica code, FDistribution.nb


$$f(x; df_1, df_2) = \frac{df_2^{df_2/2} df_1^{df_1/2} x^{df_1 / 2-1}}{(df_2+df_1 x)^{(df_1+df_2)/2}B(df_1/2, df_2/2)}\qquad for\ x>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.f(dfn=1, dfd=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.f, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (3)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.f(dfn=1, dfd=1) 
sns.distplot(X.rvs(100), fit=stats.f, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.f(dfn=1, dfd=1) 
sns.distplot(X.rvs(100))  
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.f(dfn=1, dfd=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 dfn, dfd \(\xrightarrow{stats.f}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





FisherZ

Another programming language code

mathematica code, FisherZ.nb






Gamma

Another programming language code

mathematica code, Gamma.nb


$$f(x; a) = \frac{x^{a-1} \exp(-x)}{\Gamma(a)}\qquad for\ x\ge0,\ a>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.gamma(a=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.gamma, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (4)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.gamma(a=1,loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.gamma, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.gamma(a=1,loc=1, scale=1) 
sns.distplot(X.rvs(100))  
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.gamma(a=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 a, loc, scale \(\xrightarrow{stats.gamma}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting




Laplace

Another programming language code

mathematica code, Laplace.nb


$$f(x) = \frac{1}{2} \exp(-|x|)\qquad for\ a\ real\ number\ x$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.laplace() 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.laplace, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (5)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.laplace() 
sns.distplot(X.rvs(100), fit=stats.laplace, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.laplace() 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.laplace() 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1   \(\xrightarrow{stats.laplace}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





Logistic

Another programming language code

mathematica code, Logistic.nb


$$f(x) = \frac{\exp(-x)}{(1+\exp(-x))^2}$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.logistic(loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.logistic, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (6)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.logistic(loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.logistic, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.logistic(loc=1, scale=1) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.logistic(loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 loc, scale \(\xrightarrow{stats.logistic}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





LogNormal

Another programming language code

mathematica code, LogNormal.nb


$$f(x; s) = \frac{1}{s x \sqrt{2\pi}}\exp\left(-\frac{\log^2(x)}{2s^2}\right)\qquad for\ x>0,\ s>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.lognorm(s=1, loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1, figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.lognorm, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (7)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.lognorm(s=1, loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.lognorm, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.lognorm(s=1, loc=1, scale=1) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.lognorm(s=1, loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 s, loc, scale \(\xrightarrow{stats.lognorm}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





Normal

Another programming language code

mathematica code, Normal.nb


$$f(x;\mu,\sigma) = \frac{\exp(-(x-\mu)^2/2)}{\sqrt{2\pi\sigma}}\qquad for\ a\ real\ number\ x$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.norm(loc=100, scale=10) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.norm, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (8)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.norm(loc=100, scale=10) 
sns.distplot(X.rvs(100), fit=stats.norm, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.norm(loc=100, scale=10) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.norm(loc=100, scale=10) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 loc, scale \(\xrightarrow{stats.norm}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





StudentT

Another programming language code

mathematica code, StudentT.nb


$$f(x; \nu) = \frac{\Gamma((\nu+1)/2)}{\sqrt{\pi \nu} \Gamma(\nu)}(1+x^2/\nu)^{-(\nu+1)/2}$$ $$ where\ x\ is\ a\ real\ number\ and\ degrees\ of\ freedom\ parameter\ \nu>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.t(df=4,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig,ax= plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.t, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (9)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.t(df=4,loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.t, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.t(df=4,loc=1, scale=1) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.t(df=4,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 df, loc, scale \(\xrightarrow{stats.t}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





Uniform

Another programming language code

mathematica code, Uniform.nb


$$ [𝑙𝑜𝑐,𝑙𝑜𝑐 + 𝑠𝑐𝑎𝑙𝑒] $$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.uniform(loc=2, scale=10) 
x = np.linspace(*X.interval(0.999), num=100) 

fig, ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.uniform, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (10)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.uniform(loc=2, scale=10) 
sns.distplot(X.rvs(100), fit=stats.uniform, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.uniform(loc=2, scale=10) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.uniform(loc=2, scale=10) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 loc, scale \(\xrightarrow{stats.uniform}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





Weibull

Another programming language code

mathematica code, Weibull.nb


$$Weibull\ min\ :\ f(x; c) = c x^{c-1} \exp(-x^c)\qquad for\ x\ge0,\ c>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.weibull_min(c=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig, ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.weibull_min, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (11)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.weibull_min(c=1,loc=1, scale=1)
sns.distplot(X.rvs(100), fit=stats.weibull_min, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.weibull_min(c=1,loc=1, scale=1)
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.weibull_min(c=1,loc=1, scale=1)
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 c, loc, scale \(\xrightarrow{stats.weibull\_min}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting




$$Weibull\ max\ :\ f(x; c) = c (-x)^{c-1} \exp(-(-x)^c)\qquad for\ x<0,\ c>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.weibull_max(c=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig, ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.weibull_max, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (12)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.weibull_max(c=1,loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.weibull_max, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.weibull_max(c=1,loc=1, scale=1) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.weibull_max(c=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 c, loc, scale \(\xrightarrow{stats.weibull\_max}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting




$$Weibull\ double\ :\ f(x; c) = c / 2 |x|^{c-1} \exp(-|x|^c)\qquad for\ a\ real\ numbers,\ x\ and\ c>0$$

Main code

from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set(style="whitegrid")

X = stats.dweibull(c=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

fig, ax = plt.subplots(3,1,figsize=(10, 8))

sns.distplot(X.rvs(100), fit=stats.dweibull, kde=False,ax=ax[0])
sns.distplot(X.rvs(100),ax=ax[1])  
ax[2].plot(x, X.pdf(x))

ax[0].set_title("model fitting")
ax[1].set_title("data fitting")
ax[2].set_title("PDF")

plt.tight_layout()
plt.show()
OUTPUT

download (13)


SUPPLEMENT

model fitting

from scipy import stats
import seaborn as sns

X = stats.dweibull(c=1,loc=1, scale=1) 
sns.distplot(X.rvs(100), fit=stats.dweibull, kde=False)
OUTPUT

download



data fitting

from scipy import stats
import seaborn as sns

X = stats.dweibull(c=1,loc=1, scale=1) 
sns.distplot(X.rvs(100))
OUTPUT

download (1)



PDF

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

X = stats.dweibull(c=1,loc=1, scale=1) 
x = np.linspace(*X.interval(0.999), num=100) 

plt.plot(x, X.pdf(x))
OUTPUT

download (2)



Sub-code

Sub-code

# Random variables
print(X.rvs(size=10, random_state=None))
# Probability density function
x = np.linspace(*X.interval(0.999), num=5) 
print(X.pdf(x))
# Log of the probability density function.
print(X.logpdf(x))
# Cumulative distribution function.
print(X.cdf(x))
# Log of the cumulative distribution function.
print(X.logcdf(x))
# Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
print(X.sf(x))
# Log of the survival function.
print(X.logsf(x))
# Percent point function (inverse of cdf — percentiles).
q = np.linspace(0.01,0.99, num=5) 
print(X.ppf(q))
# Inverse survival function (inverse of sf).
print(X.isf(q))
# Non-central moment of order n
for n in [1,2]:
    print(X.moment(n))    
# Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
print(X.stats(moments='mvsk'))
# (Differential) entropy of the RV.
print(X.entropy())
# Parameter estimates for generic data.
data = X.rvs(size=10, random_state=None)

# loc : mean, scale : standard deviation
print(stats.beta.fit(data, 1, 2, loc=0, scale=1))
# Median
print(X.median())
# Mean
print(X.mean())
# Variance
print(X.var())
# Standard deviation
print(X.std())
# Interval
print(X.interval(0.05))

$$ random\ variable\ :\ X \xrightarrow{function} distribution\ :\ X.pdf(x) $$
STEP INPUT FUNCTION OUTPUT
1 c, loc, scale \(\xrightarrow{stats.dweibull}\) X
2 x \(\xrightarrow{X.pdf}\) X.pdf(x)
3 x, X.pdf(x) \(\xrightarrow{ax.plot}\) graph : X.pdf(x)
4 X.rvs(#) \(\xrightarrow{sns.distplot}\) graph : fitting





List of posts followed by this article


Reference