Prev: The normal distribution | Next: The f distribution
gamma((df+1)/2)
t.pdf(x, df) = ---------------------------------------------------
sqrt(pi*df) * gamma(df/2) * (1+x**2/df)**((df+1)/2)
- For example, when calculating the mean value M of a sample with size N, then considering that M remains constant only the N-1 values in the sample can vary. The N-th value is dependent on the other N-1 values.
from scipy.stats import t
# Freeze for df=20, loc=0, scale=1 and get the first four moments from stats()
rv = t(df=20, loc=0, scale=1)
mean, var, skew, kurt = rv.stats(moments='mvsk')
mean, var, skew, kurt
import numpy as np
from scipy.stats import t
import matplotlib.pyplot as plt
%matplotlib inline
rv = t(df=20, loc=0, scale=1)
x = np.linspace(rv.ppf(0.0001), rv.ppf(0.9999), 100)
y = rv.pdf(x)
plt.xlim(-5,5)
plt.plot(x,y)
a = 0.05 # set the cutoff
rv = t(df=20, loc=0, scale=1)
x = np.random.normal(size=1)
p = rv.sf(x) # equal but sometimes more accurate than '1-rv.cdf(x)'
if p < a:
print('Cutoff at: ', x, p)
else:
print('No cutoff', x, p)
. Free learning material
. See full copyright and disclaimer notice