def sampling_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function df = 10 x=np.linspace(t.ppf(0.01, df), t.ppf(0.99, df), 100) ax.plot(x, t.pdf(x, df)) #simulate the sampling distribution y = [] for i in range(1000): r = norm.rvs(loc=5, scale=2, size=df+1) rt =(np.mean(r)-5)/np.sqrt(np.var(r)/df) y.append(rt) ax.hist(y, normed=True, alpha=0.2) plt.savefig('sampling_distribution.png')
def t_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function df = 10 x=np.linspace(-4, 4, 100) ax.plot(x, t.pdf(x,df)) #simulate the t-distribution y = [] for i in range(1000): rx = norm.rvs() ry = chi2.rvs(df) rt = rx/np.sqrt(ry/df) y.append(rt) ax.hist(y, normed=True, alpha=0.2) plt.savefig('t_distribution.png')
def sampling_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function dfn, dfm = 10, 5 x=np.linspace(f.ppf(0.01, dfn, dfm), f.ppf(0.99, dfn, dfm), 100) ax.plot(x, f.pdf(x, dfn, dfm)) #simulate the sampling distribution y = [] for i in range(1000): r1 = norm.rvs(loc=5, scale=2, size=dfn+1) r2 = norm.rvs(loc=3, scale=2, size=dfm+1) rf =np.var(r1)/np.var(r2) y.append(rf) ax.hist(y, normed=True, alpha=0.2) plt.savefig('sampling_distribution.png')
def sampling_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function x = np.linspace(-4, 4, 100) ax.plot(x, norm.pdf(x)) #simulate the sampling distribution y = [] n=100 for i in range(1000): r = expon.rvs(scale=1, size=n) rsum=np.sum(r) z=(rsum-n)/np.sqrt(n) y.append(z) ax.hist(y, normed=True, alpha=0.2) plt.savefig('sampling_distribution.png')
def F_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function dfn, dfm = 10, 5 x = np.linspace(f.ppf(0.01, dfn, dfm), f.ppf(0.99, dfn, dfm), 100) ax.plot(x, f.pdf(x, dfn, dfm)) #simulate the F-distribution y = [] for i in range(1000): rx = chi2.rvs(dfn) ry = chi2.rvs(dfm) rf = np.sqrt(rx/dfn)/np.sqrt(ry/dfm) y.append(rf) ax.hist(y, normed=True, alpha=0.2) plt.savefig('F_distribution.png')
def chi2_distribution(): fig, ax = plt.subplots(1, 1) #display the probability density function df = 10 x=np.linspace(chi2.ppf(0.01, df), chi2.ppf(0.99, df), 100) ax.plot(x, chi2.pdf(x,df)) #simulate the chi2 distribution y = [] n=10 for i in range(1000): chi2r=0.0 r = norm.rvs(size=n) for j in range(n): chi2r=chi2r+r[j]**2 y.append(chi2r) ax.hist(y, normed=True, alpha=0.2) plt.savefig('chi2_distribution.png')