--- title: "jurors" author: "Chris Parrish" date: "January 8, 2016" output: pdf_document --- jurors references: - Cannon, et al., Stat2, chapter 03, examples 3.8 Import the data. ```{r} data <- read.csv("Jurors.csv", header=TRUE) head(data) dim(data) ``` Scatterplot matrix. ```{r} pairs(~ PctReport + Period + I2000, data=data, col="darkred") ``` Separate linear models for each year. ```{r} jury1998.lm <- lm(PctReport[I2000==0] ~ Period[I2000==0], data=data) ``` \$\widehat{PctReport} =\$ `r round(coef(jury1998.lm)[1], 3)` + `r round(coef(jury1998.lm)[2], 3)` \$Period\$ ```{r} coef(jury1998.lm) ``` ```{r} jury2000.lm <- lm(PctReport[I2000==1] ~ Period[I2000==1], data=data) ``` \$\widehat{PctReport} =\$ `r round(coef(jury2000.lm)[1], 3)` + `r round(coef(jury2000.lm)[2], 3)` \$Period\$ ```{r} coef(jury2000.lm) ``` View the data (separate linear models for each year). ```{r} plot(PctReport ~ Period, data=data, pch=16 - 15 * data\$I2000) legend("topright", legend=c("1998", "2000"), pch=c(16, 1)) abline(jury1998.lm, col="orange") abline(jury2000.lm, col="orangered") ``` Multiple regression with interaction (allowing different slopes and intercepts). ```{r} jury.lm1 <- lm(PctReport ~ Period * I2000, data=data) options(show.signif.stars=FALSE) summary(jury.lm1) ``` Multiple regression without interaction (allowing different intercepts but enforcing identical slopes). ```{r} jury.lm2 <- lm(PctReport ~ Period + I2000, data=data) summary(jury.lm2) ``` Residuals. ```{r} hist(resid(jury.lm2), col="wheat") qqnorm(resid(jury.lm2), col="orchid") qqline(resid(jury.lm2), col="orange") plot(predict(jury.lm2), resid(jury.lm2), pch=20, col="darkred") abline(h=0, col="orange") plot(data\$Period, resid(jury.lm2), pch=20, col="darkred") abline(h=0, col="orange") ``` CI. ```{r} confint(jury.lm2) ```