One-way ANOVA

Sameer Mathur

One-Way ANOVA

  • Used to compare a dependent variable for two or more groups, defined by a categorical grouping factor

Cholestrol Drug Example

  • 50 patients receive one of five cholestrol-reducing drug regiments (trt)

Cholestrol Drug Example

  • Three of the treatment conditions involved our drug (Drug C)
  • Drug C was administered either 20mg once per day (1time), OR 10mg twice per day (2times) OR 5mg four times per day (4times)

Cholestrol Drug - Competition

  • The two remaining conditions (Drug D, E) represented competing drugs

Cholestrol Drug - Research Question

  • Which drug regimen produced the greatest cholestrol reduction (response)?

Read the inbuilt dataset

library(multcomp)
attach(cholesterol)
head(cholesterol)
    trt response
1 1time   3.8612
2 1time  10.3868
3 1time   5.9059
4 1time   3.0609
5 1time   7.7204
6 1time   2.7139

Data types of columns

str(cholesterol)
'data.frame':   50 obs. of  2 variables:
 $ trt     : Factor w/ 5 levels "1time","2times",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ response: num  3.86 10.39 5.91 3.06 7.72 ...

Descriptive statistics

library(psych)
describe(cholesterol)[,c(2,3,4,5,8,9)]
          n  mean   sd median min   max
trt*     50  3.00 1.43   3.00 1.0  5.00
response 50 12.74 6.09  12.61 2.3 27.24

Group sample size

# group sample size
table(trt)
trt
 1time 2times 4times  drugD  drugE 
    10     10     10     10     10 

Group means

# group means
meanRes <- aggregate(response, by=list(trt), FUN=mean)
colnames(meanRes) <- c("Response","Mean")
meanRes
  Response     Mean
1    1time  5.78197
2   2times  9.22497
3   4times 12.37478
4    drugD 15.36117
5    drugE 20.94752

Group standard deviation

# group standard deviation 
sdRes <- aggregate(response, by=list(trt), FUN=sd)
colnames(sdRes) <- c("Response","SD")
sdRes
  Response       SD
1    1time 2.878113
2   2times 3.483054
3   4times 2.923119
4    drugD 3.454636
5    drugE 3.345003

BoxPlot of Response versus Treatment

boxplot(response ~ trt, data=cholesterol, main="Response versus Treatment", 
    xlab="Treatment", ylab="Response")

plot of chunk unnamed-chunk-7

ANOVA

Test for group diffrences

fit <- aov(response ~ trt)                                  
summary(fit)
            Df Sum Sq Mean Sq F value   Pr(>F)    
trt          4 1351.4   337.8   32.43 9.82e-13 ***
Residuals   45  468.8    10.4                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(gplots)
plotmeans(response ~ trt, xlab="Treatment", ylab="Response", 
          main="Mean Plot\nwith 95% CI")

plot of chunk unnamed-chunk-9

Tukey HSD pairwise group comparisons

TukeyHSD(fit)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = response ~ trt)

$trt
                  diff        lwr       upr     p adj
2times-1time   3.44300 -0.6582817  7.544282 0.1380949
4times-1time   6.59281  2.4915283 10.694092 0.0003542
drugD-1time    9.57920  5.4779183 13.680482 0.0000003
drugE-1time   15.16555 11.0642683 19.266832 0.0000000
4times-2times  3.14981 -0.9514717  7.251092 0.2050382
drugD-2times   6.13620  2.0349183 10.237482 0.0009611
drugE-2times  11.72255  7.6212683 15.823832 0.0000000
drugD-4times   2.98639 -1.1148917  7.087672 0.2512446
drugE-4times   8.57274  4.4714583 12.674022 0.0000037
drugE-drugD    5.58635  1.4850683  9.687632 0.0030633
plot(TukeyHSD(fit))

plot of chunk unnamed-chunk-11

Multiple comparisons the multcomp package

library(multcomp)
tuk <- glht(fit, linfct=mcp(trt="Tukey"))
plot(cld(tuk, level=.05),col="lightgrey")

plot of chunk unnamed-chunk-12

Assessing normality

library(car)
qqPlot(lm(response ~ trt, data=cholesterol), 
       simulate=TRUE, main="Q-Q Plot", labels=FALSE)

plot of chunk unnamed-chunk-13

Assessing homogeneity of variances

bartlett.test(response ~ trt, data=cholesterol)

    Bartlett test of homogeneity of variances

data:  response by trt
Bartlett's K-squared = 0.57975, df = 4, p-value = 0.9653

Assessing outliers

library(car)
outlierTest(fit)

No Studentized residuals with Bonferonni p < 0.05
Largest |rstudent|:
   rstudent unadjusted p-value Bonferonni p
19 2.251149           0.029422           NA