--- title: "babies" author: "Chris Parrish" date: "January 22, 2016" output: pdf_document --- babies reference: - Cannon, et al., Stat2, chapter 07, example 7.10 Import the data. {r} data <- read.csv("WalkingBabies.csv", header=TRUE) head(data) dim(data)  Scatterplot matrix. {r} pairs(~ Age + Group, data=data, col="darkred")  Use Lattice graphics to view the data. {r} library(lattice) xyplot(Age ~ Group, data=data)  Standard deviations. {r} sd <- with(data, round(tapply(Age, Group, sd), 3)) sd max(sd) / min(sd)  Linear model. {r} babies.aov <- aov(Age ~ Group, data=data) options(show.signif.stars=FALSE) summary(babies.aov)  Residuals. {r} qqnorm(resid(babies.aov), col="cadetblue") qqline(resid(babies.aov), col="orange") plot(predict(babies.aov), resid(babies.aov), pch=20, col="darkred")  Comparison. HT: $$H_0 : \mu_{se} - \mu_{ce} = 0$$ $$H_a : \mu_{se} - \mu_{ce} \not= 0$$ {r} means <-with(data,round(tapply(Age, Group, mean), 3)) means y.bar.se <- means[3] y.bar.ec <- means[1] mse <- 2.22 # from babies.aov df <- 20 n.se <- n.ec <- 6 se <- sqrt(mse * (1^2 / n.se + (-1)^2 / n.ec)) t <- as.numeric((y.bar.se - y.bar.ec) / se) t p.value <- 2 * pt(t, df=df) p.value  Contrast. HT: $$H_0 : \frac{1}{2}(\mu_{se} + \mu_{ce}) - \frac{1}{2}(\mu_{wr} + \mu_{fr}) = 0$$ $$H_a : \frac{1}{2}(\mu_{se} + \mu_{ce}) - \frac{1}{2}(\mu_{wr} + \mu_{fr}) \not= 0$$ {r} y.bar.wr <- means[4] y.bar.fr <- means[2] n.wr <- n.fr <- 6 contrast.estimate <- (1 / 2) * (y.bar.se + y.bar.ec) - (1 / 2) * (y.bar.wr + y.bar.fr) se <- sqrt(mse * (1 / 2)^2 * (1 / n.se + 1 / n.ec + 1 / n.wr + 1 / n.fr)) t <- as.numeric(contrast.estimate / se) t p.value <- 2 * pt(t, df=df) p.value