We can use the function scipy.stats.t for the Student t-Distribution. The function t is renamed as st. We use the st.pdf function for the probability density function.
The Student t-Distribution is for the case the sample comes from a normal population, however the number of samples is less than 30.
The t-Distribution goes very near the normal as n becomes 30. It is hard to spot the difference in the graph.
# ex18.py
from __future__ import print_function, division
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm, t as st
x = np.linspace(-3, +3, num = 500)
n = 5
y = st.pdf(x, n-1)
plt.plot(x, y, 'r')
plt.xlabel('x')
plt.ylabel('Probability Density Function')
plt.title('t dist, n=5:red, n=10:green, n=30:blue, norm:magenta')
n = 10
y = st.pdf(x, n-1)
plt.plot(x, y, 'g')
n = 30
y = st.pdf(x, n-1)
plt.plot(x, y, 'b')
y = norm.pdf(x)
plt.plot(x, y, 'm')
plt.show()
Output:
No comments:
Post a Comment