### R code for Section 7.1 ## Example 7.1-1: Popcorn ## The yield (in cups of popped corn from 1/4 cup of corn) is the variable of interest ## Wish to test the effects of two factors: ## Factor A is the type of popcorn maker, oil-based or air-based ## Factor B is popcorn brand, gourmet-type and a national brand data=read.table("http://homepages.math.uic.edu/~wangjing/stat481/table715.dat", head=T) yield = data$Yield popper = factor(data$Popper) brand = factor(data$Brand) # linear regression fit1 = lm(yield ~ popper + brand + popper*brand) summary(fit1) par(mfrow=c(2,2)) # residual plot plot(fit1, 1) # residual vs fitted value plot(fit1, 2) # QQ-plot plot(fit1, 3) # sqrt(|standardized residual|) vs FItted value plot(fit1, 4) # cook's distance # ANOVA table anova(fit1) # check row means tapply(yield, popper, mean) # check column means tapply(yield, brand, mean) # interaction plot par(mfrow=c(1,1)) interaction.plot(brand, popper, yield) # Strip chart (dotplot) stripchart(yield ~ brand, method = "stack", pch=1) stripchart(yield ~ popper, method = "stack", pch=1)