--- title: "putts" author: "Chris Parrish" date: "January 24, 2016" output: pdf_document --- putts reference: - Cannon, et al., Stat2, chapter 09, example 9.10, 9.16 - Cannon, et al., Student R Manual, chapter 9 Import the data. {r} data <- read.csv("Putts1.csv", header=TRUE) head(data) dim(data) data.table <- read.csv("Putts2.csv", header=TRUE) data.table  Putt statistics. {r} prop.successes <- with(data.table, Made / (Made + Missed)) odds.success <- prop.successes / (1 - prop.successes) empirical.logit <- with(data.table, log(Made / Missed)) putting.prowess <- round(rbind(prop.successes, odds.success, empirical.logit), 3) colnames(putting.prowess) <- 3:7 putting.prowess  Empirical odds ratios. Compare with table on p.469. {r} slope <- empirical.logit[2:5] - empirical.logit[1:4] empirical.odds.ratio <- exp(slope) fitted.odds.ratio <- rep(0.5677116, 4) putt.table <- round(rbind(slope, empirical.odds.ratio, fitted.odds.ratio), 3) colnames(putt.table) <- c("4 to 3", "5 to 4", "6 to 5", "7 to 6") putt.table  Illustration. {r} plot(3:7, empirical.logit, pch=20, col="darkred", type="b", xlim=c(2, 8), ylim=c(-2, 3), xlab="Distance (ft)") putts.glm <- glm(Made ~ Length, data=data, family=binomial) abline(putts.glm, col="orange") legend("topright", legend=c("data", "fitted"), lty=1, col=c("darkred", "orange"), inset=0.02)  glm. Compare with table on p.481. {r} options(show.signif.stars=FALSE) summary(putts.glm)  Odds ratio. $\beta_1 = log(OR)$ $exp(\beta_1) = OR$ {r} coef(putts.glm) beta1 <- coef(putts.glm)[2] OR <- exp(beta1) OR  CI for odds ratio. $\beta_1 = log(OR)$ $exp(\beta_1) = OR$ {r} exp(confint(putts.glm))  Formal inference: tests and intervals. {r} summary(putts.glm)  HT: $H_0 : \beta_1 = 0$ $H_a : \beta_1 \not= 0$ {r} null.deviance <-800.21 residual.deviance <- 719.89 G <- null.deviance - residual.deviance df <- 586 - 585 p.value <- 1 - pchisq(G, df=df) p.value