Boxplot is used to have a look at how the data is distributed. Here the data frame is grouped by supp and dose. It is easily seen that the length increases as the dosage increases for both supplement methods, although it is still not sure yet whether the two methods are as effective which will be explored in the next section.
## load the data
data("ToothGrowth")
## use boxplot to plot the VC group
boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2,
subset = supp == "VC", col = "yellow", main = "Guinea Pigs' Tooth Growth",
xlab = "dose/mg", ylab = "tooth length", xlim = c(0.5, 3.5), ylim = c(0, 35),
yaxs = "i")
## use boxplot to plot the OJ group and add to the previous plot
boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2,
subset = supp == "OJ", col = "orange")
legend("bottomright", legend=c("VC", "OJ"), col=c("yellow", "orange"), lwd = 4, lty = 2)
Since it is still a question as to whether the two methods are as effective, it is useful to perform students’ t-test on both groups of data at each level of dosage. 0.95 confidence interval with the hypothesis that the mean of the two methods are the same are given as follow.
dose0.5<-subset(ToothGrowth, dose == 0.5 )
VC<-dose0.5[dose0.5$supp=="VC","len"]
OJ<-dose0.5[dose0.5$supp=="OJ","len"]
t.test(VC, OJ)$conf
## [1] -8.780943 -1.719057
## attr(,"conf.level")
## [1] 0.95
The confidence interval is totally below zero which means the VC group is less effective as OJ group at this dosage level.
dose1<-subset(ToothGrowth, dose == 1 )
VC<-dose1[dose1$supp=="VC","len"]
OJ<-dose1[dose1$supp=="OJ","len"]
t.test(VC, OJ)$conf
## [1] -9.057852 -2.802148
## attr(,"conf.level")
## [1] 0.95
The confidence interval is below zero, so VC group is not as effective as OJ group again.
dose2<-subset(ToothGrowth, dose == 2 )
VC<-dose2[dose2$supp=="VC","len"]
OJ<-dose2[dose2$supp=="OJ","len"]
t.test(VC, OJ)$conf
## [1] -3.63807 3.79807
## attr(,"conf.level")
## [1] 0.95
The confidence interval is approximately symmetric about zero, so it is safe to say that the two groups are as effective at this level.
As the experiments are carried out for different pigs, independent groups assumption is used, that is, the paired option is set to false in the test. The assumption should be justified considering the fact that the pigs in the two groups are not the same.
Based on the given data, it is safe to claim that VC group is not as effective as OJ group at dosage level of 0.5 and 1 and starts to catch up, however, at the dosage level of 2.