## MB Baseball data ## March 10, 2008 ## humid, dry, control dry <- c(103, 111, 100, 112, 106) dry.50 <- c(101, 102, 99, 92, 90) humid <- c(93, 85, 94, 95, 87) y <- c(dry, dry.50, humid) x <- c(rep("dry", 5), rep("dry.50", 5), rep("humid", 5)) ## do the F-test anova(lm(y~as.factor(x))) ## check the assumptions # normality options(contrasts = c("contr.sum", "contr.poly")) mod.lm <- lm(y~as.factor(x)) par(mfrow=c(1,2)) hist(mod.lm$res) qqnorm(mod.lm$res); qqline(mod.lm$res) ## variances s.sq.i <- tapply(y,x,var) max(s.sq.i)/min(s.sq.i) ## Get 95% CIs mu.i <- tapply(y,x,mean) s.sq <- anova(lm(y~as.factor(x)))[2,3] se <- sqrt(s.sq/5) cbind(mu.i - se*qt(1-0.05/2, 15-3), mu.i + se*qt(1-0.05/2, 15-3)) ## Get all pairwise comparisons K <- matrix(c(1,-1,0, 1,0,-1, 0,1,-1),3,3, byrow=T) K C.hat <- K%*%mu.i se.1 <- sqrt(s.sq*sum(K[1,]^2/5)) se.2 <- sqrt(s.sq*sum(K[2,]^2/5)) se.3 <- sqrt(s.sq*sum(K[3,]^2/5)) cbind(C.hat - c(se.1,se.2,se.3)*qt(1-(0.05/3)/2, 15-3), C.hat + c(se.1,se.2,se.3)*qt(1-(0.05/3)/2, 15-3)) ## check assumptions par(mfrow=c(2,2)) qqnorm(dry); qqline(dry) qqnorm(humid); qqline(humid) boxplot(dry, col="yellow", ylim=c(80,115)) boxplot(humid, col="yellow", ylim=c(80,115)) ## do the test t.test(dry, humid, var=T) t.test(dry, humid, var=T, alt="greater") ## Corked Bat uncorked <- c(77.2, 79.7, 79.7, 80.4) corked <- c(39.3, 37.4, 38.8, 37.8) par(mfrow=c(2,2)) qqnorm(corked); qqline(corked) qqnorm(uncorked); qqline(uncorked) boxplot(corked, col="yellow", ylim=c(35,81)) boxplot(uncorked, col="yellow", ylim=c(35,81)) ## do the test t.test(corked, uncorked, var=T) ## (paired t-test) ## The Slide run <- c(3.624, 4.076, 4.13) slide <- c(3.572, 3.976, 3.93) id <- c(Tory, Jamie, Grant) t.test(run,slide,paired=T, var.equal=T)