## Supplement to Lec1.r code. Example for Project 1 Q#4 ## Ex. Kenton Food Company ## Read in the data; name the variables kenton <- read.table("Datasets/CH16TA01.txt", col.names=c("Y","package","id")) kenton$package <- as.factor(kenton$package) ## Summary statistics: For Q#4 you need to add "$x" to end of each line cellmeans <- aggregate(kenton$Y, by=list(package=kenton$package), FUN=mean)$x cellsds <- aggregate(kenton$Y, by=list(package=kenton$package), FUN=sd)$x cellsizes <- aggregate(kenton$Y, by=list(package=kenton$package), FUN=length)$x cellmeans; cellsds; cellsizes ## Fit the one-way ANOVA model fit <- aov(Y ~ package, data=kenton) ## Sample code for Project 1 Q#4 ## Get individual CIs for the means superimposed on the aligned dotplots ## First gather the ingredients for the CIs df.res <- fit$df.residual mse <- sum((fit$residuals)^2)/df.res se.of.mean <- sqrt(mse)/sqrt(cellsizes) cc <- qt(.975, df=df.res) # for 95% confidence level allow <- se.of.mean*cc ## ## The code snippet below is taken from Dalgaard's book on R stripchart(Y ~ package, method="jitter", jitter=0.05,pch=16,vert=TRUE, ylim=c(8,35), data=kenton) arrows(1:4,cellmeans+allow,1:4,cellmeans-allow,angle=90, code=3,length=.1) lines(1:4,cellmeans,pch=4,type="p",cex=2) title(main="Individual confidence intervals for the means", sub="Package Design") ###