The data set contains observations of 60 guinea pigs after they received different dosages of vitamin C per day (0.5, 1 and 2 mg/day). They received this dosage via orange juice (OJ) or ascorbic acid (VC).
# Loading data set
data(ToothGrowth)
The first 6 rows of the data set:
head(ToothGrowth)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
Details of the data set:
str(ToothGrowth)
## 'data.frame': 60 obs. of 3 variables:
## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
## $ dose: num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
Summary of the data set:
summary(ToothGrowth)
## len supp dose
## Min. : 4.20 OJ:30 Min. :0.500
## 1st Qu.:13.07 VC:30 1st Qu.:0.500
## Median :19.25 Median :1.000
## Mean :18.81 Mean :1.167
## 3rd Qu.:25.27 3rd Qu.:2.000
## Max. :33.90 Max. :2.000
Tooth length increases with higher doses for both supplements.
ggplot(ToothGrowth, aes(x = dose, y = len, color = supp)) +
geom_point(position = position_jitter(width = 0.05), size = 2, alpha = 0.7) + geom_smooth(method = "lm", se = FALSE, color = "red")+
labs( x = "Dose (mg/day)", y = "Tooth Length (cm)",
color = "Supplement") +
theme_minimal()
linear model
lm(len ~ dose, data = ToothGrowth)
##
## Call:
## lm(formula = len ~ dose, data = ToothGrowth)
##
## Coefficients:
## (Intercept) dose
## 7.422 9.764
OJ is more effective than VC at lower doses (0.5 and 1 mg/day), but both supplement types are equally effective at the dose of 2 mg/day.
The effectiveness of OJ decreases as dosage increases, in which the rate of increase in tooth length decreases. On the other hand, increasing VC dosage leads to a steady rate of increase of tooth length.
ggplot(ToothGrowth,
aes(x = factor(dose),
y = len,
fill = supp)) +
geom_boxplot(position = position_dodge(width = 0.8)) +
labs(x = "Dose (mg/day)",
y = "Tooth length",
fill = "Supplement",
title = "Tooth Length by Dose and Supplement") +
theme_minimal()
aggregate(len ~ supp, data=ToothGrowth, median)
## supp len
## 1 OJ 22.7
## 2 VC 16.5
A 2-way ANOVA was conducted to explore interaction between supplement with dose as the main factor.
supp_int <- aov(len ~ factor(dose) * supp, data = ToothGrowth)
summary(supp_int)
## Df Sum Sq Mean Sq F value Pr(>F)
## factor(dose) 2 2426.4 1213.2 92.000 < 2e-16 ***
## supp 1 205.3 205.3 15.572 0.000231 ***
## factor(dose):supp 2 108.3 54.2 4.107 0.021860 *
## Residuals 54 712.1 13.2
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Since there was a statistically significant result, a Tukey-test was conducted.
TukeyHSD(supp_int)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = len ~ factor(dose) * supp, data = ToothGrowth)
##
## $`factor(dose)`
## diff lwr upr p adj
## 1-0.5 9.130 6.362488 11.897512 0.0e+00
## 2-0.5 15.495 12.727488 18.262512 0.0e+00
## 2-1 6.365 3.597488 9.132512 2.7e-06
##
## $supp
## diff lwr upr p adj
## VC-OJ -3.7 -5.579828 -1.820172 0.0002312
##
## $`factor(dose):supp`
## diff lwr upr p adj
## 1:OJ-0.5:OJ 9.47 4.671876 14.2681238 0.0000046
## 2:OJ-0.5:OJ 12.83 8.031876 17.6281238 0.0000000
## 0.5:VC-0.5:OJ -5.25 -10.048124 -0.4518762 0.0242521
## 1:VC-0.5:OJ 3.54 -1.258124 8.3381238 0.2640208
## 2:VC-0.5:OJ 12.91 8.111876 17.7081238 0.0000000
## 2:OJ-1:OJ 3.36 -1.438124 8.1581238 0.3187361
## 0.5:VC-1:OJ -14.72 -19.518124 -9.9218762 0.0000000
## 1:VC-1:OJ -5.93 -10.728124 -1.1318762 0.0073930
## 2:VC-1:OJ 3.44 -1.358124 8.2381238 0.2936430
## 0.5:VC-2:OJ -18.08 -22.878124 -13.2818762 0.0000000
## 1:VC-2:OJ -9.29 -14.088124 -4.4918762 0.0000069
## 2:VC-2:OJ 0.08 -4.718124 4.8781238 1.0000000
## 1:VC-0.5:VC 8.79 3.991876 13.5881238 0.0000210
## 2:VC-0.5:VC 18.16 13.361876 22.9581238 0.0000000
## 2:VC-1:VC 9.37 4.571876 14.1681238 0.0000058
par(mfrow=c(2,2))
plot(supp_int)