--- title: "fingers" author: "Chris Parrish" date: "January 20, 2016" output: pdf_document --- fingers references: - Cannon, et al., chapter 6, ex. 6.1 - Cannon, et al., Student R Manual, chapter 6 Import the data. ```{r} data <- read.table("Fingers.csv", header=TRUE, sep=",") head(data, 4) dim(data) ``` Scatterplot matrix. ```{r} pairs(~ TapRate + Subject + Drug, data=data, col="darkred") ``` Create a table. ```{r} fingers.table <- with(data, tapply(TapRate, list(Subject, Drug), mean)) fingers.table ``` Add marginal means to the table. Compare with Table 6.1, page 274 ```{r} row.means <- with(data, tapply(TapRate, Subject, mean)) col.means <- with(data, tapply(TapRate, Drug, mean)) fingers.table <- rbind(cbind(fingers.table, row.means), c(col.means, 34)) rownames(fingers.table)[5] <- "Mean" colnames(fingers.table)[4] <- "Mean" fingers.table <- fingers.table[ , c(2, 1, 3, 4)] # permute the first two columns fingers.table ``` One-way ANOVA. ```{r} options(show.signif.stars=FALSE) summary(aov(TapRate ~ Drug, data=data)) ``` Two-way additive ANOVA. ```{r} fingers.aov <- aov(TapRate ~ Subject + Drug, data=data) summary(fingers.aov) ``` Residuals. ```{r} qqnorm(resid(fingers.aov), col="cadetblue") qqline(resid(fingers.aov), col="orange") plot(predict(fingers.aov), resid(fingers.aov), pch=20, col="darkred") abline(h=0, col="orange") ``` Effect plots: without interaction. ```{r message=FALSE} fingers.lm1 <- lm(TapRate ~ Subject + Drug, data=data) library(alr4) plot(allEffects(fingers.lm1)) ```