The dataset of ‘ToothGrowth’ is loaded from the R dataset packages.
Data Decription: 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))
1- NcNeil,D.R.(1977) Interactive Data Analysis. New York:Wiley
2- Crampton, E. W. (1947) The growth of the odontoblast of the incisor teeth as a criterion of vitamin C intake of the guinea pig. The Journal of Nutrition 33(5): 491–504.
library(plyr)
data(ToothGrowth)
As show below, the data frame ‘ToothGrowth’ consists of 60 objects with 3 variables.
1- len: Tooth length
2- supp: Supplement type (VC or OJ)
3- dose: Dose in milligrams/day
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
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(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
The Mean of Tooth Growth Length for VC supp is 16.96333.
The Mean of Tooth Growth Length for OJ supp is 20.66333.
mn_by_supp<-ddply(ToothGrowth,.(supp), function(x) mean(x$len));colnames(mn_by_supp)<-c("supp","mean")
mn_by_supp
## supp mean
## 1 OJ 20.66333
## 2 VC 16.96333
The Standard Deviation of Tooth Growth Length for VC supp is 8.266029.
The Standard Deviation of Tooth Growth Length for OJ supp is 6.605561.
sd_by_supp<-ddply(ToothGrowth,.(supp), function(x) sd(x$len));colnames(sd_by_supp)<-c("supp","sd")
sd_by_supp
## supp sd
## 1 OJ 6.605561
## 2 VC 8.266029
ToothGrowth$supp<-as.character(ToothGrowth$supp)
par(mfrow=c(2,1))
p1<-hist(ToothGrowth$len[ToothGrowth$supp=="VC"],col=rgb(0,0,1,1/4),xlab="The length of tooth growth with VC group",main="The Histogram of Tooth Growth Length for 'VC' supp group");abline(v=mn_by_supp$mean[2],col="red")
p2<-hist(ToothGrowth$len[ToothGrowth$supp=="OJ"],col=rgb(1,0,0,1/4),xlab="The length of tooth growth with OJ group",main="The Histogram of Tooth Growth Length for 'OJ' supp group");abline(v=mn_by_supp$mean[1],col="red")
The Mean of Tooth Growth Length for 0.5 milligrams/day dose is 10.605.
The Mean of Tooth Growth Length for 1.0 milligrams/day dose is 19.735.
The Mean of Tooth Growth Length for 2.0 milligrams/day dose is 26.100.
mn_by_dose<-ddply(ToothGrowth,.(dose), function(x) mean(x$len));colnames(mn_by_dose)<-c("dose","mean")
mn_by_dose
## dose mean
## 1 0.5 10.605
## 2 1.0 19.735
## 3 2.0 26.100
The Standard Deviation of Tooth Growth Length for 0.5 milligrams/day dose is 4.499763.
The Standard Deviation of Tooth Growth Length for 1.0 milligrams/day dose is 4.415436.
The Standard Deviation of Tooth Growth Length for 2.0 milligrams/day dose is 3.774150.
sd_by_dose<-ddply(ToothGrowth,.(dose), function(x) sd(x$len));colnames(sd_by_dose)<-c("dose","Sd")
sd_by_dose
## dose Sd
## 1 0.5 4.499763
## 2 1.0 4.415436
## 3 2.0 3.774150
par(mfrow=c(3,1))
p1<-hist(ToothGrowth$len[ToothGrowth$dose==0.5],col=rgb(0,0,1,1/4),xlab="The length of tooth growth with 0.5 dose group",main="The Histogram of Tooth Growth Length for 0.5 dose group");abline(v=mn_by_dose$mean[1],col="red")
p2<-hist(ToothGrowth$len[ToothGrowth$dose==1.0],col=rgb(1,0,0,1/4),xlab="The length of tooth growth with 1.0 dose group",xlim=c(10,30),main="The Histogram of Tooth Growth Length for 1.0 dose group");abline(v=mn_by_dose$mean[2],col="red")
p3<-hist(ToothGrowth$len[ToothGrowth$dose==1.0],col=rgb(0,1,0,1/4),xlab="The length of tooth growth with 2.0 dose group",xlim=c(10,30),main="The Histogram of Tooth Growth Length for 2.0 dose group");abline(v=mn_by_dose$mean[3],col="red")
t.test(len~supp,data=ToothGrowth)
##
## 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
The Null Hypothesis: Assume the mean of tooth growth length is the same. According to the result of t-test, the p-value is 0.061, which is higher than the significant value 0.05. So the Null Hypothesis is accepted and the conclusion that there is no difference between mean of tooth growth length is arrived.
len_dose1<-ToothGrowth$len[ToothGrowth$dose==0.5];len_dose2<-ToothGrowth$len[ToothGrowth$dose==1.0];len_dose3<-ToothGrowth$len[ToothGrowth$dose==2.0]
t.test(len_dose1,len_dose2)
##
## Welch Two Sample t-test
##
## data: len_dose1 and len_dose2
## 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 of x mean of y
## 10.605 19.735
The Null Hypothesis: Assume the mean of tooth growth length is the same. According to the result of t-test, the p-value is 1.268e-07, which is less than the significant value 0.05. So the Null Hypothesis is rejected and the conclusion that there is difference between mean of tooth growth length is arrived.
t.test(len_dose1,len_dose3)
##
## Welch Two Sample t-test
##
## data: len_dose1 and len_dose3
## 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 of x mean of y
## 10.605 26.100
The Null Hypothesis: Assume the mean of tooth growth length is the same. According to the result of t-test, the p-value is 4.398e-14, which is less than the significant value 0.05. So the Null Hypothesis is rejected and the conclusion that there is difference between mean of tooth growth length is arrived.
t.test(len_dose2,len_dose3)
##
## Welch Two Sample t-test
##
## data: len_dose2 and len_dose3
## 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 of x mean of y
## 19.735 26.100
The Null Hypothesis: Assume the mean of tooth growth length is the same. According to the result of t-test, the p-value is 1.906e-05, which is less than the significant value 0.05. So the Null Hypothesis is rejected and the conclusion that there is difference between mean of tooth growth length is arrived.
To do the two-sample t test for different groups, we have to assume that the data of two populations must be independently obtained, the variance of the two groups is the same and the two populations should follow a normal distribution.
1- There is no significant effect on the tooth growth length for different supplments.
2- The increasing dose levels of vitamin C has positive effect on the tooth growth length.