--- title: "ballot" author: "Chris Parrish" date: "January 16, 2016" output: pdf_document --- ballot references: - Cannon, et al., Stat2, chapter 01, example 1.9 - [ballot, Wikipedia](https://en.wikipedia.org/wiki/Ballot) - [butterfly ballot, Wikipedia](https://upload.wikimedia.org/wikipedia/commons/6/66/Butterfly_large.jpg) Import the data. ```{r} data <- read.csv("PalmBeach.csv", header=TRUE) head(data, 4) dim(data) ``` View the data. ```{r fig.width=6, fig.height=4.2} plot(Buchanan ~ Bush, data=data, pch=20, col="darkred") ballot.lm <- lm(Buchanan ~ Bush, data=data) abline(ballot.lm, col="orange") ``` Linear model. \$\widehat{Buchanan} =\$ `r round(coef(ballot.lm)[1], 3)` + `r round(coef(ballot.lm)[2], 3)` \$Bush\$ ```{r} options(show.signif.stars=FALSE) summary(ballot.lm) ``` Residuals. ```{r} plot(fitted(ballot.lm), resid(ballot.lm), pch=20, col="darkred") abline(h=0, col="orange", lty="dashed") ``` Studentized residuals. ```{r} studentized.residuals <- rstudent(ballot.lm) studentized.residuals[50] # Palm Beach plot(studentized.residuals, pch=20, col="darkred") abline(h=c(2, 1, -1, -2), col="orange", lty="dashed") ``` Remove Palm Beach and refit the data. ```{r} data.withoutPB <- data[data\$County!="PALM BEACH", ] plot(Buchanan ~ Bush, data=data, pch=20, col="darkred") abline(ballot.lm, col="orange") ballot.lm2 <- lm(Buchanan ~ Bush, data=data.withoutPB) abline(ballot.lm2, col="orangered", lty=2) legend(x="topright", legend=c("with PB", "without PB"), lty=1:2, col=c("orange", "orangered"), inset=0.02) summary(ballot.lm2) ``` Linear model with Palm Beach. \$\widehat{Buchanan} =\$ `r round(coef(ballot.lm)[1], 3)` + `r round(coef(ballot.lm)[2], 3)` \$Bush\$ Linear model without Palm Beach. \$\widehat{Buchanan} =\$ `r round(coef(ballot.lm2)[1], 3)` + `r round(coef(ballot.lm2)[2], 3)` \$Bush\$