Two-way ANOVA test is used to evaluate simultaneously the e???ect of two grouping variables (for example group (A) and category(B)) on a response variable. Two-way ANOVA test hypotheses 1. There is no di???erence in the means of factor A 2. There is no di???erence in means of factor B 3. There is no interaction between factors A and B (a) The alternative hypothesis for cases 1 and 2 is: the means are not equal. (b) The alternative hypothesis for case 3 is: there is an interaction between A and B. Assumptions of two-way ANOVA test Two-way ANOVA, like all ANOVA tests, assumes that the observations within each cell are normally distributed and have equal variances. Well show you how to check these assumptions after ???tting ANOVA.
attach(ToothGrowth)
d<- (ToothGrowth)
View(d)
names(d)
## [1] "len" "supp" "dose"
str(as.factor(supp))
## Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
str(as.factor(dose))
## Factor w/ 3 levels "0.5","1","2": 1 1 1 1 1 1 1 1 1 1 ...
d$dose <- factor(d$dose,
levels = c(0.5, 1, 2),
labels = c("D0.5", "D1", "D2"))
View(d)
head(d)
## len supp dose
## 1 4.2 VC D0.5
## 2 11.5 VC D0.5
## 3 7.3 VC D0.5
## 4 5.8 VC D0.5
## 5 6.4 VC D0.5
## 6 10.0 VC D0.5
table(d$supp, d$dose)
##
## D0.5 D1 D2
## OJ 10 10 10
## VC 10 10 10
if(!require(devtools)) install.packages("devtools")
## Loading required package: devtools
## Warning: package 'devtools' was built under R version 3.5.3
## Warning: package 'usethis' was built under R version 3.5.3
devtools::install_github("kassambara/ggpubr")
## Skipping install of 'ggpubr' from a github remote, the SHA1 (de26170d) has not changed since last install.
## Use `force = TRUE` to force installation
library("ggpubr")
## Loading required package: ggplot2
## Loading required package: magrittr
ggboxplot(d, x = "dose", y = "len", color = "supp",
palette = c("#00AFBB", "#E7B800"))
library("ggpubr")
ggline(d, x = "dose", y = "len", color = "supp",
add = c("mean_se", "dotplot"),
palette = c("#00AFBB", "#E7B800"))
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
aov(len~supp + dose, data=d)
## Call:
## aov(formula = len ~ supp + dose, data = d)
##
## Terms:
## supp dose Residuals
## Sum of Squares 205.350 2426.434 820.425
## Deg. of Freedom 1 2 56
##
## Residual standard error: 3.82759
## Estimated effects may be unbalanced
aov(len~supp*dose, data=d)
## Call:
## aov(formula = len ~ supp * dose, data = d)
##
## Terms:
## supp dose supp:dose Residuals
## Sum of Squares 205.350 2426.434 108.319 712.106
## Deg. of Freedom 1 2 2 54
##
## Residual standard error: 3.631411
## Estimated effects may be unbalanced
The p-value of dose is < 2e-16, which indicates that the levels of dose are associated with significant different tooth length.
The p-value for the interaction between supp*dose is 0.02, which indicates that the relationships between dose and tooth length depends on the supp method.