From 7cbbd04247f24cac4baa0e8d0f0979aa058856e7 Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 29 Feb 2020 23:07:55 +0800 Subject: =?UTF-8?q?numpy=E5=AE=9E=E7=8E=B0t=E6=A3=80=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stats/student_t_distribution.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 stats/student_t_distribution.py (limited to 'stats/student_t_distribution.py') diff --git a/stats/student_t_distribution.py b/stats/student_t_distribution.py new file mode 100644 index 0000000..ddea26c --- /dev/null +++ b/stats/student_t_distribution.py @@ -0,0 +1,19 @@ + +from scipy.special import gamma +import math +import matplotlib.pyplot as plt +import numpy as np + + +def t_dist(t, v): + return gamma((v+1)/2)/(math.sqrt(v*math.pi)*gamma(v/2)) * (1+t**2/v)**(-(v+1)/2) + + +x = np.arange(-4, 4, .1) +plt.plot(x, t_dist(x, 1), label='v=1') +plt.plot(x, t_dist(x, 2), label='v=2') +plt.plot(x, t_dist(x, 5), label='v=5') +# plt.plot(x, t_dist(x, math.inf), label='v=inf') +plt.legend() +plt.show() + -- cgit v1.2.3