t分布,随着自由度的增加,而逐渐接近于正态分布
1 #!/usr/bin/env python3 2 #-*- coding:utf-8 -*- 3 ############################################# 4 #File Name: t.py 5 #Brief: 6 #Author: frank 7 #Email: [email protected] 8 #Created Time:2018-08-17 23:07:24 9 #Blog: http://www.cnblogs.com/black-mamba 10 #Github: https://github.com/xiaomagejunfu0903/statistic_notes 11 ############################################# 12 13 from scipy.stats import t 14 from scipy.stats import norm 15 import matplotlib.pyplot as plt 16 import numpy as np 17 18 df = 2 19 rv_t = t(df) 20 x = np.linspace(-4,4, 100) 21 plt.plot(x,rv_t.pdf(x),‘y-‘,label=‘df=2‘) 22 23 x2 = np.linspace(-4,4, 100) 24 plt.plot(x2,t.pdf(x2,5),‘g--‘,label=‘df=5‘) 25 26 x3 = np.linspace(-4,4, 100) 27 plt.plot(x3,t.pdf(x3,10),‘b--‘,label=‘df=10‘) 28 29 x4 = np.linspace(-4,4, 100) 30 plt.plot(x4,t.pdf(x4,120),‘r--‘,label=‘df=120‘) 31 32 x5 = np.linspace(-4,4, 100) 33 plt.plot(x5,norm.pdf(x5),‘m--‘,label=‘std norm‘,alpha=0.5) 34 35 plt.legend() 36 37 plt.show()
从上图可以看出,当df=120时,t曲线几乎与正态分布曲线重合。
原文地址:https://www.cnblogs.com/black-mamba/p/9495854.html
时间: 2024-10-10 01:19:41