hw stat
##10.3.7 hospital = read.table("ds10.3.7-hospital-emergency-room.txt", header = T) #n is the sample size n = sum(hospital$Frequency) #This creates a vector (x) of the numbers 0 to 12 x = seq(0:12)-1 #Probabilities calculated - creates a vector with all of them in there. probs = dpois(x,7) #Last entry in probs vector is for anything greater than 13 probs[14] = 1-(ppois(12,7)) #Check that probabilites sum to 1. sum(probs) #vector expected values (exp). probabilities * sample size exp = probs*n #view expected values exp #observed values (obs): read straight from the table obs = hospital$Frequency #Calculate X2 (chi-square) statistic X2 = ((obs-exp)^2)/exp X2 = sum(X2) #calculate p-value pchisq(102.3199,13, lower.tail = F)