This project explores the ToothGrowth data set in R and investigates the effect of two types of supplements with different doses on the teeth length. According to the descripton if the data set, “For 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)”. The following sections provide a summary of the data set and a boxplot that gives more insights into the data. In addition, two hypotheses are tested, the first hypothesis is about the effect of the different doses on the teeth length and the second hypothesis is about the effect of the type of supplement on the teeth length.
#Loading libraries
library(ggplot2)
library(dplyr)
#load dataset
data(ToothGrowth)
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 ...
-ToothGrowth data frame consists of three columns with 60 observations. Supplement type (VC or OJ) is listed under r supp and dose in milligrams/day is listed under dose.
-supp has two levels corresponding to the two supplement types and dose consists of three numeric values (0.5, 1, and 2 mg/day).
table(ToothGrowth$supp, ToothGrowth$dose)
##
## 0.5 1 2
## OJ 10 10 10
## VC 10 10 10
-Each supplement type is given to 30 animals, divided to three groups (10 for each dose).
ToothGrowth %>%
group_by(supp,dose) %>%
summarize(mean_len=mean(len),std_len=sd(len),min_len=min(len),max_len=max(len))
## Source: local data frame [6 x 6]
## Groups: supp [?]
##
## supp dose mean_len std_len min_len max_len
## (fctr) (dbl) (dbl) (dbl) (dbl) (dbl)
## 1 OJ 0.5 13.23 4.459709 8.2 21.5
## 2 OJ 1.0 22.70 3.910953 14.5 27.3
## 3 OJ 2.0 26.06 2.655058 22.4 30.9
## 4 VC 0.5 7.98 2.746634 4.2 11.5
## 5 VC 1.0 16.77 2.515309 13.6 22.5
## 6 VC 2.0 26.14 4.797731 18.5 33.9
ggplot(ToothGrowth,aes(x=supp,y=len))+
facet_grid(~dose)+
geom_boxplot(aes(color=supp),outlier.colour = "black", outlier.shape = 1)+
labs(x="Supplement",y="Length",title="Supplement Effect on Teeth Growth")+geom_point()
According to the previous figure, two hypotheses are formulated to be tested. It is known that “the null hypothesis is assumed true and statistical evidence is required to reject it in favor of a research or alternative hypothesis” For both hypotheses testing, it is assumed that:
the two vectors do not have equal values
the confidence interval is 95%
The null hypothesis H0 is that the teeth growth increase with supplement dose. The alternative hypothesis Ha is that the teeth growth does not increase with supplement dose.
For this, t-test is used and p-value is checked.
#separate the length corresponding to the 3 doses
d0.5<-filter(ToothGrowth,dose==0.5)$len
d1<-filter(ToothGrowth,dose==1)$len
d2<-filter(ToothGrowth,dose==2)$len
#test the alternative hypothesis
#0.5 Vs. 1 mg/day
pv05_1<-t.test(d0.5,d1, paired = FALSE, alternative="less",conf.level = 0.95)$p.value
#1 Vs. 2 mg/day
pv1_2<-t.test(d1,d2, paired = FALSE, alternative="less",conf.level = 0.95)$p.value
By testing the alternative hypothesis, we find p-value:
\(6.3415036\times 10^{-8}\) for 0.5 Vs. 1 mg/day
\(9.5321476\times 10^{-6}\) for 1 Vs. 2 mg/day.
Both values are larger than 0.05, consequently we fail to reject the null hypothesis.
The null hypothesis H0 is that, at a dose of 2 mg/day, there is no significant effect of the supplement’s type on the teeth growth (as the mean for both seems equal in the boxplot). In other words, the teeth growth is not necessarily higher when using OJ compared to VC. The alternative hypothesis is that the teeth growth is higher with OJ compared to VC.
#select the lengths corresponding to 2 mg/day, each supplement in a vector
SOJ<-filter(ToothGrowth,supp=="OJ" & dose==2)$len
SVC<-filter(ToothGrowth,supp=="VC" & dose==2)$len
#test the alternative hypothesis (OJ effect > VC effect)
pv_supp<-t.test(SOJ,SVC, paired = FALSE, alternative="greater",conf.level = 0.95)$p.value
By testing the alternative hypothesis, we find p-value= 0.5180742 which is larger than 0.05, so we fail to reject the null hypothesis.
Testing the two hypothesis regarding the effect of both the supplement type and the dose on the teeth length, we didn’t have enough evidence to reject the null hypotheses. COnsequently we can say that:
The teeth length increases with the increase of the supplement’s dose.
The teeth growth is not always higher with OJ compared to VC.