This report is a basic analysis of the ToothGrowth dataset in R’s Datasets Package. In the package description, the dataset describes the response as “the length of odontoblasts (cells responsible for tooth growth) in 60 guinea pigs. Each animal received one of three dose levels of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods, orange juice or ascorbic acid (a form of vitamin C and coded as VC)”. First, an exploratory data analysis is performed to summarize the data and produce some hypotheses about the data. Then, these hypotheses are tested more formally with hypothesis testing procedures and confidence intervals. Finally, the assumptions to validate the findings of the hypothesis tests are given.
Load necessary packages for analysis:
# load necessary packages
library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
# load the data
data("ToothGrowth")
Overall Summary of the data:
# explore the structure of the data
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 ...
# get mean, median, and quantiles of the response variable
summary(ToothGrowth$len)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.20 13.08 19.25 18.81 25.28 33.90
Summary groubed by supplement type (OJ or VC):
grouped <- group_by(tbl_df(ToothGrowth),supp)
summarize(grouped, count = length(supp), mean = mean(len), median = median(len), stdev = sd(len))
## Source: local data frame [2 x 5]
##
## supp count mean median stdev
## (fctr) (int) (dbl) (dbl) (dbl)
## 1 OJ 30 20.66333 22.7 6.605561
## 2 VC 30 16.96333 16.5 8.266029
This shows that considering all dose levels, the mean tooth length for OJ is higher at 20.66 and has a smaller standard deviation (6.61) than VC which has a mean and standard deviation of 16.96 and 8.27, respectively.
For the final step of my EDA/summarization of the data, I produce boxplots of tooth length vs dose, for each supplment type
ggplot(grouped, aes(x=factor(dose),y=len,color=factor(dose))) + geom_boxplot()+
facet_grid(. ~ supp) + labs(x="Dose Level") + labs(y="Tooth Length") +
labs(title="Tooth Length by Supplement and Dose")
From this boxplot summary, it appears that Orange Juice affects tooth length to a greater degree than VC, at least for doses 0.5mg and 1.0mg. However, it’s unclear that there is a significant difference at the 2.0mg dose. Therefore, my hypothesis tests will test each supplement and dosage.
This test is to determine if there’s a signifiant difference bewteen the effects of supplement type on tooth growth. Thus, the null hypothesis is that supplement type has no significant effect on tooth growth.
t.test(len ~ supp, data = ToothGrowth, paired = FALSE, var.equal = FALSE)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1710156 7.5710156
## sample estimates:
## mean in group OJ mean in group VC
## 20.66333 16.96333
Interpreting the t-test: Since the p value is above 0.05 and the confidence interval also contains zero, we fail to reject the null hypothesis. This means that the difference in the mean between Orange Juice and Vitamin C is not significant and we cannot draw the conclusion that one supplement has a greater effect on tooth length than the other when considering all dosages in aggregate.
These tests are to determine if there’s a significant difference bewteen the effects of dosage on tooth growth, by supplement type. Thus, the null hypothesis is that dosage does not have a significant effect on tooth growth.
# 0.5 mg dose
halfdose <- filter(ToothGrowth, dose == 0.5)
t.test(len ~ supp, data = halfdose, paired = FALSE, var.equal = FALSE)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = 3.1697, df = 14.969, p-value = 0.006359
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1.719057 8.780943
## sample estimates:
## mean in group OJ mean in group VC
## 13.23 7.98
# 1.0 mg dose
dose1 <- filter(ToothGrowth, dose == 1)
t.test(len ~ supp, data = dose1, paired = FALSE, var.equal = FALSE)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = 4.0328, df = 15.358, p-value = 0.001038
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 2.802148 9.057852
## sample estimates:
## mean in group OJ mean in group VC
## 22.70 16.77
# 2.0 mg dose
dose2 <- filter(ToothGrowth, dose == 2)
t.test(len ~ supp, data = dose2, paired = FALSE, var.equal = FALSE)
##
## Welch Two Sample t-test
##
## data: len by supp
## t = -0.046136, df = 14.04, p-value = 0.9639
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -3.79807 3.63807
## sample estimates:
## mean in group OJ mean in group VC
## 26.06 26.14
Interpreting the t-tests: When testing the supplements according to dosage, we find that doses 0.5mg and 1.0mg are statistically significant. Their p values are less than 0.05 and their confidence intervals do not contain zero. Therefore, we can reject the null hypothesis for doses of 0.5 mg and 1.0 mg. However, in the case of the 2.0mg dose, the p value is above 0.05, the confidence interval contains 0, and thus we fail to reject the null hypothesis. In conclusion, there is a significant difference between the supplements at the 0.5 mg and 1.0 mg dosages, but not the 2.0 mg dosage.
To make inferences, I performed A/B testing which required independent group t-tests due to the small sample sizes involved. This required the assumption that the data were not skewed, and I also made the assumption that the variances were unequal which changes the type of confidence interval produced in each test. These assumptions seem warranted after looking at the summary of the data and the unlikely chance of the variances being equal. Additionally, I assumed that the t-tests were the best tests to perform on the data due to the course project instructions directing us to use techniques taught in the class, even if other techniques are more appropriate. In practice, an ANOVA test would be best for this analysis (a two-way balanced factorial experimental design). Analysis of variance (ANOVA) is a way to make multiple comparisons among means without having to conduct multiple t-tests. For example, to analyze dose, there are 3 pairs of dose factor levels, which means that one must run 3 t-tests to compare all of them. The aov() function makes all the comparisons in one function call, and it has the capability to analyze multiple independent variables as well as their interaction effects. Using the analysis of variance function aov(), one can quickly obtain the statistics for both of the main effects (dose and supp) as well as the interaction effect dose * supp which is crucial here. An interaction is when the values of one variable vary according to the values of another.