t分布の確率密度関数・累積分布関数のグラフをPythonで描く
確率密度関数のグラフ。
import numpy as np import scipy.stats as stats import matplotlib.pyplot as plt x = np.linspace(-5, +5, 101) y1 = stats.t.pdf(x, 1) y2 = stats.t.pdf(x, 2) y3 = stats.t.pdf(x, 4) y4 = stats.norm.pdf(x) plt.plot(x, y1) # 青 plt.plot(x, y2) # 橙 plt.plot(x, y3) # 緑 plt.plot(x, y4) # 赤
stats.t.pdf
の2つ目の引数はt分布の自由度 を表す。 を大きくすると正規分布に近づくのがわかる。赤が正規分布。
次は累積分布関数のグラフ。
x = np.linspace(-5, +5, 101) y1 = stats.t.cdf(x, 1) y2 = stats.t.cdf(x, 2) y3 = stats.t.cdf(x, 4) y4 = stats.norm.cdf(x) plt.plot(x, y1) # 青 plt.plot(x, y2) # 橙 plt.plot(x, y3) # 緑 plt.plot(x, y4) # 赤