Practical -6 2 tests for goodness of fit using Python 1. For the arrival of the patients at a doctor’s clinic has obtained the following distribution for 445 days. Fit a Binomial distribution for the following data and test for its goodness of fit. No. Of patients 0 1 2 3 4 5 6 No. Of days 153 169 72 31 12 6 2 import pandas as pd import numpy as np from scipy.stats import binom import scipy.stats as stats table = pd.read_excel("C:/Users/Naveen/OneDrive/Desktop/Binomial_distribution.xlsx") table x = table[' No. Of patients '] x f = table[‘No. Of days’] f n= max(x) fx =f*x m = sum(fx)/sum(f) p = m/n px = binom.pmf(x, n, p) px1 = np.round(px,4) px1 ef =sum(f)*px ef ef1 = np.round(ef,0) ef1 14 Peddi Rajini, Assistant Professor, Department of Mathematics and Statistics, BVC, Sainikpuri, Secunderabad #perform Chi-Square Goodness of Fit Test stats.chisquare(f_obs=f, f_exp=ef1) if pval <0.05: print("reject null hypothesis") else: print("accept null hypothesis")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter