source("http://192.38.117.59/~linearpredictors/datafiles/readFever.R") ## Table of fever against fetal deaths. (t1 <- table(fever$episodes,dnn = c("Number of fever episodes"))) ## total no of episodes is the sum of "cases * no of episodes for that case". no.episodes <- sum(t1 * as.numeric(dimnames(t1)[[1]])) no.women <- nrow(fever[!is.na(fever$episodes),]) ## estimated probability p.hat <- no.episodes/(no.women*14) ## expected numbers of episodes exp1 <- round(dbinom(0:10, 14, 0.0143)*no.women, digits=1) ## now we collapse the groups with 3 or more fever episodes O <- c(t1[1:3], sum(t1[4:9])) names(O) <- c("0", "1", "2", "3+") E <- c(exp[1:3], sum(exp[4:9])) names(E) <- c("0", "1", "2", "3+") O-E round((O-E)^2/E, digits = 2)