#ANOVA in Splus Data: The Kenton Food Example in Chapter 16 New Splus functions: tapply: can be used to calculate summary statistics by group aov: one of several ways to fit an ANOVA model in Splus multicomp: do multiple comparisons in Splus (only available in Splus version 4 and later) ________________________________________________________________________ >kenton<-read.table("CH16TA01.DAT",header=T) >kenton$design<-factor(kenton$design) >kenton$store<-factor(kenton$store) >kenton num.cases design store 1 11 1 1 2 17 1 2 3 16 1 3 4 14 1 4 5 15 1 5 6 12 2 1 7 10 2 2 8 15 2 3 9 19 2 4 10 11 2 5 11 23 3 1 12 20 3 2 13 18 3 3 14 17 3 4 15 27 4 1 16 33 4 2 17 22 4 3 18 26 4 4 19 28 4 5 #____________________________________________________________________________ #Some EDA > summary(kenton) num.cases design store Min. :10.00 1:5 1:4 1st Qu.:14.50 2:5 2:4 Median :17.00 3:4 3:4 Mean :18.63 4:5 4:4 3rd Qu.:22.50 5:3 Max. :33.00 > tapply(kenton$num.cases,kenton$design,mean) 1 2 3 4 14.6 13.4 19.5 27.2 > sqrt(tapply(kenton$num.cases,kenton$design,var)) 1 2 3 4 2.302173 3.646917 2.645751 3.962323 motif() par(mfrow=c(2,2)) boxplot(split(kenton$num.cases,kenton$design),xlab="Design", ylab="# of cases") title("Figure 1") NOTES: 1. Why didn't I draw a boxplot split on store number? 2. See also the command: plot.factor #__________________________________________________________ #ANOVA #There are many ways to fit ANOVA models in Splus. The command aov is #one possibility: >ken.aov<-aov(num.cases~design,kenton) > print(summary(ken.aov),digits=4) Df Sum of Sq Mean Sq F Value Pr(F) design 3 588.2 196.1 18.59 0.00002585 Residuals 15 158.2 10.5 #The multicomp command computes simultaneous confidence intervals. #This command is only available in Splus version 4 and later, so it is #not currently available in our Unix version of Splus > multicomp(ken.aov,plot=T) 95 % simultaneous confidence intervals for specified linear combinations, by the Tukey method critical point: 2.8822 response variable: num.cases intervals excluding 0 are flagged by '****' Estimate Std.Error Lower Bound Upper Bound 1-2 1.2 2.05 -4.72 7.120 1-3 -4.9 2.18 -11.20 1.380 1-4 -12.6 2.05 -18.50 -6.680 **** 2-3 -6.1 2.18 -12.40 0.179 2-4 -13.8 2.05 -19.70 -7.880 **** 3-4 -7.7 2.18 -14.00 -1.420 **** #__________________________________________________________ #Some diagnostics #see page 757 of NKNW (using semi-studentized residuals here) e.star<-ken.aov$residual/sqrt(sum(ken.aov$residual^2)/ken.aov$df.residual) plot(kenton$design,e.star) abline(h=0) title("Figure 2") plot(unclass(kenton$design),e.star) abline(h=0) title("Figure 3") qqnorm(e.star) title("Figure 4") #__________________________________________________________