Chapter 17: Analysis of Variance

17.1 ANOVA - One Factor

# get summary & structure and create a boxplot of our differences
str(chickwts)
## 'data.frame':    71 obs. of  2 variables:
##  $ weight: num  179 160 136 227 217 168 108 124 143 140 ...
##  $ feed  : Factor w/ 6 levels "casein","horsebean",..: 2 2 2 2 2 2 2 2 2 2 ...
summary(chickwts)
##      weight             feed   
##  Min.   :108.0   casein   :12  
##  1st Qu.:204.5   horsebean:10  
##  Median :258.0   linseed  :12  
##  Mean   :261.3   meatmeal :11  
##  3rd Qu.:323.5   soybean  :14  
##  Max.   :423.0   sunflower:12
with(chickwts,boxplot(weight~feed,
     col= "lightgray",
     main= "",
     xlab= "Feed type", ylab= "Weight (g)", ylim= c(100,450), las= 1)) 

with(chickwts, tapply(weight, feed, mean))
##    casein horsebean   linseed  meatmeal   soybean sunflower 
##  323.5833  160.2000  218.7500  276.9091  246.4286  328.9167
with(chickwts, tapply(weight, feed, sd))
##    casein horsebean   linseed  meatmeal   soybean sunflower 
##  64.43384  38.62584  52.23570  64.90062  54.12907  48.83638
with(chickwts, bartlett.test(weight ~ feed))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  weight by feed
## Bartlett's K-squared = 3.2597, df = 5, p-value = 0.66

Anova Test

Step 1: Set the Null and Alternate Hypotheses

Step 2: Implement Analysis of Variance Test

with(chickwts, oneway.test(weight ~ feed, var.equal = TRUE))
## 
##  One-way analysis of means
## 
## data:  weight and feed
## F = 15.365, num df = 5, denom df = 65, p-value = 5.936e-10

Step 3: Interpret the Results

17.1.1 Pair-wise Comparisons

with(chickwts, pairwise.t.test(weight, feed, pool.sd = TRUE))
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  weight and feed 
## 
##           casein  horsebean linseed meatmeal soybean
## horsebean 2.9e-08 -         -       -        -      
## linseed   0.00016 0.09435   -       -        -      
## meatmeal  0.18227 9.0e-05   0.09435 -        -      
## soybean   0.00532 0.00298   0.51766 0.51766  -      
## sunflower 0.81249 1.2e-08   8.1e-05 0.13218  0.00298
## 
## P value adjustment method: holm