This report covers part 2 of the course project of the Statistical Inference course of the John Hopkins University, for which data is analyzed and some basic, inferential analyses are performed. To do so, the ToothGrowth dataset is used, which is available in the datasets package. After analysing the dataset, multiple hypotheses are formulated and tested using the Student’s T-test, of which the results are subsequently reported in the conclusion.
Below you can find an overview of the packages which were used to generate the results in this report. Make sure you have these installed and loaded, before running the rest of this document’s code in R (or R Studio).
library(datasets)
library(ggplot2)
For the second part of the course project, the ToothGrowth dataset will be used. Before analyzing the data itself, it is important to know what it is about. Using the information contained in the datasets package, the following is known about the data:
[Of the variables found in the dataset …] the response is 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).
Given this information, a first step is to take a look at 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 ...
As can be seen above, the data frame consists of 60 observations over 3 variables. The len variable is the response variable, used to measure tooth growth. supp is a factor variable with two levels, OJ and VC, indicating the two delivery methods. Lastly, dose is a numeric variable which indicates the supplied dose, which is either 0.5, 1 or 2 mg/day. As this variable describes groups, it can best be changed to a factor variable.
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
To get a further understandig of the data, the summary() function can be used.
summary(ToothGrowth)
## len supp dose
## Min. : 4.20 OJ:30 0.5:20
## 1st Qu.:13.07 VC:30 1 :20
## Median :19.25 2 :20
## Mean :18.81
## 3rd Qu.:25.27
## Max. :33.90
As the output of the call to summary() shows, the length variable ranges from 4.20 to 33.90, with its mean at 18.81. Furthermore, it can be seen that the sample of 60 guinea pigs has been evenly divided over the delivery methods and dosage levels. To see if the amount of pigs per dosage level per delivery method are equal, the following code can be run:
table(ToothGrowth$supp, ToothGrowth$dose)
##
## 0.5 1 2
## OJ 10 10 10
## VC 10 10 10
As is apparent from the table, the sample has been equally divided over its multiple groups. Before moving on to the testing section of this report, the following graph depicts boxplots of the length variable per dosage level, per delivery method. This graph can be used to obtain an initial idea of potential differences between the multiple treatments in the data. ggplot2 has been used to plot the graph, for which the code is as follows (note that the methodnames vector is used as a labelling function to adjust the labels in the plots, without affecting the underlying data):
methodnames <- c(`OJ` = "Orange Juice (OJ)", `VC` = "Ascorbic Acid (VC)")
g <- ggplot(data=ToothGrowth, aes(x=dose, y=len, group=dose))
g +
geom_boxplot(aes(fill=dose)) +
facet_grid(.~as.factor(supp), labeller=as_labeller(methodnames)) +
labs(x="Dosage levels of vitamin C (mg/day)", y="Length of odontoblasts",
title="Boxplots of toothgrowth per dosage level per delivery method in guinea pigs") +
theme(strip.background = element_rect(fill="Black")) +
theme(strip.text = element_text(color="White", face="bold", size=11)) +
scale_fill_discrete(guide=FALSE)
Based on the graphs, several expectations can be formed. First of all, it seems that dosage has a strong effect on tooth growth, indepent of its delivery method. Furthermore, it seems that the delivery method also has some effect, especially so for the 0.5 and 1 mg/day dosage levels. Given these expectations, the following effects may be of interest:
Accordingly, tests shall be performed to analyse these multiple comparisons in the following section.
To analyze if a potential difference exists between applying vitamin C through orange juice or ascorbic acid on toothgrowth, the t.test() function is used to perform a non-paired, non-equal variance T-test. The hypotheses for this test are as follows:
Null hypothesis - Mean tooth growth using orange juice is equal to mean tooth growth using ascorbic acid
Alternative hypothesis - Mean tooth growth using orange juice is not equal to mean tooth growth using ascorbic acid
The code to run the test is as follows:
# T.test Orange Juice vs Ascorbic Acid
t.test(len ~ supp, data=ToothGrowth, paired=FALSE, var.equal=FALSE, alternative="two.sided")
##
## 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
As can be seen from the resulting output, 0 is within the 95 percent confidence interval and the estimated p-value is larger than 0.05. Hence, the null hypothesis can not be rejected.
To analyze if potential differences exist between applying vitamin C in different dosages per day on toothgrowth, the same function is used to perform T-tests. As 3 dosage levels exist, 3 different tests will be performed. The hypotheses for these tests (generalized) are as follows:
Null hypothesis - Mean tooth growth using a dosage level of X mg/day is equal to mean tooth growth using a dosage level of Y mg/day
Alternative hypothesis - Mean tooth growth using a dosage level of X mg/day is not equal to mean tooth growth using a dosage level of Y mg/day
Where both X and Y are an element of the set {0.5, 1, 2}, with the restriction that they cannot be the same.
The code to perform the three tests is as follows:
# T.test dose 0,5 vs dose 1
t.test(len ~ dose, data=subset(ToothGrowth, ToothGrowth$dose!=2), paired=FALSE, var.equal=FALSE, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -6.4766, df = 37.986, p-value = 1.268e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.983781 -6.276219
## sample estimates:
## mean in group 0.5 mean in group 1
## 10.605 19.735
# T.test dose 0,5 vs dose 2
t.test(len ~ dose, data=subset(ToothGrowth, ToothGrowth$dose!=1), paired=FALSE, var.equal=FALSE, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -11.799, df = 36.883, p-value = 4.398e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.15617 -12.83383
## sample estimates:
## mean in group 0.5 mean in group 2
## 10.605 26.100
# T.test dose 1 vs dose 2
t.test(len ~ dose, data=subset(ToothGrowth, ToothGrowth$dose!=.5), paired=FALSE, var.equal=FALSE, alternative="two.sided")
##
## Welch Two Sample t-test
##
## data: len by dose
## t = -4.9005, df = 37.101, p-value = 1.906e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -8.996481 -3.733519
## sample estimates:
## mean in group 1 mean in group 2
## 19.735 26.100
As can be seen from the output of the tests, none of the confidence intervals contain 0, while all tests have a very small p-level. Accordingly, the tests are significant at an alpha level of 0.05. As multiple tests are conducted with similar hypotheses, applying an adjustment (such as the Bonferroni correction) might be appropriate, which would in this case result in an adjusted alpha of 0.0167. This would not affect the significance of any of the tests, however.
Accordingly, the null hypotheses must be rejected in favor of the alternative hypotheses, which means that tooth growth significantly differs between the multiple dosage levels of vitamin C.
For the last set of tests, the difference between mean tooth growth per delivery method is analyzed per dosage level, to test if the interaction between these two treatments influences mean tooth growth. As before, the same code will be used, while the hypotheses (generalized) for these tests are:
Null hypothesis - Mean tooth growth using orange juice at a dosage level of X mg/day is equal to mean tooth growth using ascorbic acid at a dosage level of Y mg/day
Null hypothesis - Mean tooth growth using orange juice at a dosage level of X mg/day is not equal to mean tooth growth using ascorbic acid at a dosage level of Y mg/day
Where both X and Y are an element of the set {0.5, 1, 2}, with the restriction that they must be the same.
The code to perform the three tests is as follows:
# T.test interaction, dosage = .5
t.test(len ~ supp, data=subset(ToothGrowth, ToothGrowth$dose==.5), 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
# T.test interaction, dosage = 1
t.test(len ~ supp, data=subset(ToothGrowth, ToothGrowth$dose==1), 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
# T.test interaction, dosage = 2
t.test(len ~ supp, data=subset(ToothGrowth, ToothGrowth$dose==2), 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
As is apparent from the output of the tests, the confidence intervals when the dosage is set to .5 or 1 mg/day do not contain 0, and have an alpha level which is smaller than 0.05. Even if the Bonferroni correction is applied, which would lower the alpha level to 0.0167, both results remain significant. Conversely, the confidence interval does contain zero and the result is not significant if the dosage level is set to 2 mg/day.
Accordingly, it appears that mean tooth growth does significantly differ between the usage of orange juice and ascorbic acid as delivery methods at the lower dosage levels of 0.5 and 1 mg/day, whereas the difference becomes non-significant when the dosage level is increased to 2 mg/day.
Under the assumption of normality and that the variables are indepent and identically distributed random variables, the following conclusions can be made:
As the null hypotheses for the other tests could not be rejected, no further statements can be made regarding these hypotheses.