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分布の自由度  \displaystyle  \nu を表す。  \displaystyle  \nu を大きくすると正規分布に近づくのがわかる。赤が正規分布

f:id:suzuki-navi:20200814232701p:plain

次は累積分布関数のグラフ。

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) # 赤

f:id:suzuki-navi:20200814232718p:plain