diff options
| author | zhang <zch921005@126.com> | 2020-02-29 23:07:55 +0800 |
|---|---|---|
| committer | zhang <zch921005@126.com> | 2020-02-29 23:07:55 +0800 |
| commit | 7cbbd04247f24cac4baa0e8d0f0979aa058856e7 (patch) | |
| tree | a7287f550e286dc94be7e13a1329511038b96cb3 /stats/student_t_distribution.py | |
| parent | 920e07a6a7fe9c7982083900f08fbf4b23d2e66a (diff) | |
numpy实现t检验
Diffstat (limited to 'stats/student_t_distribution.py')
| -rw-r--r-- | stats/student_t_distribution.py | 19 |
1 files changed, 19 insertions, 0 deletions
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() + |
