## Section 4.5 examples ## Example 1: sport.table <- c(37,12,17,8,5,16) probs.null <- c(.4, .1, .2, .06, .06, .18) expec.counts <- sum(sports.table)*probs.null; print (expec.counts) chisq.test(sport.table, p=probs.null) ## Example 2: hits <- c(18,17,16,15,14,14,13,12,11,11,10,10,10,10,10,9,8,7) p.hat <- sum(hits)/(45*18); print(p.hat) # calculating expected cell counts under the Binom(45, p.hat) distribution: exp.counts <- 18*dbinom(0:45, size=45, prob=p.hat) print( cbind(0:45,round(exp.counts,2)) ) ## Should combine some cells because of the low expected cell counts ## before calculating the test statistic ... # P-value for this example: pchisq(6.73, df=10, lower=F) ## Example 3: my.data.445 <- c(23,23,24,27,29,31,32,33,33,35,36,37,40,42,43,43,44,45,48,48,54,54,56,57,57,58,58,58,58,59,61,61,62,63,64,65,66,68,68,70,73,73,74,75,77,81,87,89,93,97) mean(my.data.445) sd(my.data.445) ## Probabilities of falling into each interval under the normal distribution: probs.null <- diff(c(0,pnorm(c(20,40,60,80),mean=55.04,sd=19),1)) N <- length(my.data.445) expect.counts <- N*probs.null; print(expect.counts) Oj <- c(0,12,18,15,5) # Test statistic: test.stat <- sum(Oj^2 / expect.counts) - sum(Oj); print(test.stat)