library(ggplot2)
ToothGrowth dataset contains the data about the effect of Vitamin C on Tooth Growth in Guinea Pigs. The response is the length of odontoblasts (teeth) in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (Orange Juice (OJ) or Ascorbic Acid (VC)).
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
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 ...
unique(ToothGrowth$dose)
## [1] 0.5 1.0 2.0
as.table(by(ToothGrowth[,1], ToothGrowth[,-1], mean))
## dose
## supp 0.5 1 2
## OJ 13.23 22.70 26.06
## VC 7.98 16.77 26.14
It looks like the bigger dose causes the bigger growth for both suppliments, Orange Juice (OJ) seems to be more effective on lower doses though. Let’s see it on a plot.
qplot(supp, len, data = ToothGrowth, geom = 'boxplot', facets = . ~ dose,
ylab='Length (microns)', xlab='Dose (mg)',
main = 'Effect of supplements on tooth growth')
dose05 <- subset(ToothGrowth, dose == .5)
dose10 <- subset(ToothGrowth, dose == 1)
dose20 <- subset(ToothGrowth, dose == 2)
t <- t.test(dose05$len, dose10$len)
t$conf.int
## [1] -11.983781 -6.276219
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 1.268301e-07
Confidence interval doesn’t contain zero and p-value is very small, so we can reject mu0.
t <- t.test(dose10$len, dose20$len)
t$conf.int
## [1] -8.996481 -3.733519
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 1.90643e-05
Confidence interval doesn’t contain zero and p-value is very small, so we can reject mu0.
supOJ <- subset(ToothGrowth, supp == 'OJ')
supVC <- subset(ToothGrowth, supp == 'VC')
t <- t.test(supOJ$len, supVC$len)
t$conf.int
## [1] -0.1710156 7.5710156
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 0.06063451
Confidence interval contains zero and p-value is bigger than 5%, so we failed to reject mu0.
OJ05 <- subset(ToothGrowth, supp == 'OJ' & dose == .5)
VC05 <- subset(ToothGrowth, supp == 'VC' & dose == .5)
t <- t.test(OJ05$len, VC05$len)
t$conf.int
## [1] 1.719057 8.780943
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 0.006358607
Confidence interval doesn’t contain zero and p-value is very small, so we can reject mu0.
OJ10 <- subset(ToothGrowth, supp == 'OJ' & dose == 1)
VC10 <- subset(ToothGrowth, supp == 'VC' & dose == 1)
t <- t.test(OJ10$len, VC10$len)
t$conf.int
## [1] 2.802148 9.057852
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 0.001038376
Confidence interval doesn’t contain zero and p-value is very small, so we can reject mu0.
OJ20 <- subset(ToothGrowth, supp == 'OJ' & dose == 2)
VC20 <- subset(ToothGrowth, supp == 'VC' & dose == 2)
t <- t.test(OJ20$len, VC20$len)
t$conf.int
## [1] -3.79807 3.63807
## attr(,"conf.level")
## [1] 0.95
t$p.value
## [1] 0.9638516
Confidence interval contains zero and p-value is bigger than 5%, so we failed to reject mu0.
Based on exploratory analysis and hypothesis tests we proved the positive correlation between dosage and tooth growth. We also proved that Orange Juice (OJ) is more effective for .5 mg and 1 mg dosage than Ascorbic Acid (VC), they are equally effective for 2 mg dosage though.