Overview

This project analyzes the ToothGrowth data in the R datasets package. The response of the ToothGrowth data 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).

Loading and Summarizing Data

library(datasets); data(ToothGrowth); library(reshape2)
head(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 ...
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
unique(ToothGrowth$dose)
## [1] 0.5 1.0 2.0
ToothGrowth$dose <- factor(ToothGrowth$dose)
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: Factor w/ 3 levels "0.5","1","2": 1 1 1 1 1 1 1 1 1 1 ...
unique(ToothGrowth$dose)
## [1] 0.5 1   2  
## Levels: 0.5 1 2

A data frame with 60 observations on 3 variables.

Assumptions

As Figure-1 in Appendix indicates, it appears that for both supplement types, the increase dose effects the teeth growth Also, it appears that for the dose 0.5 and 1, orange juice has a more siginificant effects than vitamin C, meanwhile for dose 2, supplement type is not correlated with tooth growth.

Hypothesis Tests

Refer the Hypothesis Tests section in Appendix.

Conclusions

Appendix

Exploratory data analysis

library(ggplot2)
g <- ggplot(ToothGrowth, aes(x = dose, y = len, 
                             colour = supp))
g <- g + geom_boxplot()
g <- g + stat_summary(aes(group = 1), geom = "line", fun.y = median, size = 1, col = "black")
g <- g + facet_grid(. ~ supp)+
  labs(x="Dose in milligrams/day", y= "Tooth length", 
       title="Figure-1: The Effect of Vitamin C on Tooth Growth in Guinea Pigs")
g

Hypothesis Tests

Test-1

OJ <- subset(ToothGrowth, supp == "OJ")
OJ_d05_1 <- subset(OJ, dose %in% c(0.5,1))
OJ_d05_1_test.eq.true = t.test(len ~ dose, paired = FALSE, var.equal = TRUE, data = OJ_d05_1)
OJ_d05_1_test.eq.false = t.test(len ~ dose, paired = FALSE, var.equal = FALSE, data = OJ_d05_1)
rbind(
  list(OJ_d05_1_test.eq.true$p.value, 
       OJ_d05_1_test.eq.true$conf.int[1], OJ_d05_1_test.eq.true$conf.int[2]),
  list(OJ_d05_1_test.eq.false$p.value, 
       OJ_d05_1_test.eq.false$conf.int[1], OJ_d05_1_test.eq.false$conf.int[2])
)
##      [,1]         [,2]      [,3]     
## [1,] 8.357559e-05 -13.41081 -5.529186
## [2,] 8.784919e-05 -13.41563 -5.524366

Test-2

OJ_d1_2 <- subset(OJ, dose %in% c(1,2))
OJ_d1_2_test.eq.true = t.test(len ~ dose, paired = FALSE, var.equal = TRUE, data = OJ_d1_2)
OJ_d1_2_test.eq.false = t.test(len ~ dose, paired = FALSE, var.equal = FALSE, data = OJ_d1_2)
rbind(
  list(OJ_d1_2_test.eq.true$p.value, 
       OJ_d1_2_test.eq.true$conf.int[1], OJ_d1_2_test.eq.true$conf.int[2]),
  list(OJ_d1_2_test.eq.false$p.value, 
       OJ_d1_2_test.eq.false$conf.int[1], OJ_d1_2_test.eq.false$conf.int[2])
)
##      [,1]       [,2]      [,3]      
## [1,] 0.0373628  -6.500502 -0.2194983
## [2,] 0.03919514 -6.531443 -0.1885575

Test-3

VC <- subset(ToothGrowth, supp == "VC")
VC_d05_1 <- subset(VC, dose %in% c(0.5,1))
VC_d05_1_test.eq.true = t.test(len ~ dose, paired = FALSE, var.equal = TRUE, data = VC_d05_1)
VC_d05_1_test.eq.false = t.test(len ~ dose, paired = FALSE, var.equal = FALSE, data = VC_d05_1)
rbind(
  list(VC_d05_1_test.eq.true$p.value, 
       VC_d05_1_test.eq.true$conf.int[1], VC_d05_1_test.eq.true$conf.int[2]),
  list(VC_d05_1_test.eq.false$p.value, 
       VC_d05_1_test.eq.false$conf.int[1],  VC_d05_1_test.eq.false$conf.int[2])
)
##      [,1]         [,2]      [,3]     
## [1,] 6.492265e-07 -11.26435 -6.315654
## [2,] 6.811018e-07 -11.26571 -6.314288

Test-4

VC_d1_2 <- subset(VC, dose %in% c(1,2))
VC_d1_2_test.eq.true = t.test(len ~ dose, paired = FALSE, var.equal = TRUE, data = VC_d1_2)
VC_d1_2_test.eq.false = t.test(len ~ dose, paired = FALSE, var.equal = FALSE, data = VC_d1_2)
rbind(
  list(VC_d1_2_test.eq.true$p.value, 
       VC_d1_2_test.eq.true$conf.int[1], VC_d1_2_test.eq.true$conf.int[2]),
  list(VC_d1_2_test.eq.false$p.value, 
       VC_d1_2_test.eq.false$conf.int[1], VC_d1_2_test.eq.false$conf.int[2])
)
##      [,1]         [,2]      [,3]     
## [1,] 3.397578e-05 -12.96896 -5.77104 
## [2,] 9.155603e-05 -13.05427 -5.685733

Test-5

dose05 <- subset(ToothGrowth, dose %in% 0.5)
d05_test.eq.true = t.test(len ~ supp, paired = FALSE, var.equal = TRUE, data = dose05)
d05_test.eq.false = t.test(len ~ supp, paired = FALSE, var.equal = FALSE, data = dose05)
rbind(
  list(d05_test.eq.true$p.value, 
       d05_test.eq.true$conf.int[1], d05_test.eq.true$conf.int[2]),
  list(d05_test.eq.false$p.value, 
       d05_test.eq.false$conf.int[1], d05_test.eq.false$conf.int[2])
)
##      [,1]        [,2]     [,3]    
## [1,] 0.005303661 1.770262 8.729738
## [2,] 0.006358607 1.719057 8.780943

Test-6

dose1 <- subset(ToothGrowth, dose %in% 1)
d1_test.eq.true = t.test(len ~ supp, paired = FALSE, var.equal = TRUE, data = dose1)
d1_test.eq.false = t.test(len ~ supp, paired = FALSE, var.equal = FALSE, data = dose1)
rbind(
  list(d1_test.eq.true$p.value, 
       d1_test.eq.true$conf.int[1], d1_test.eq.true$conf.int[2]),
  list(d1_test.eq.false$p.value, 
       d1_test.eq.false$conf.int[1], d1_test.eq.false$conf.int[2])
)
##      [,1]         [,2]     [,3]    
## [1,] 0.0007807262 2.840692 9.019308
## [2,] 0.001038376  2.802148 9.057852

Test-7

dose2 <- subset(ToothGrowth, dose %in% 2)
d2_test.eq.true = t.test(len ~ supp, paired = FALSE, var.equal = TRUE,  data = dose2)
d2_test.eq.false = t.test(len ~ supp, paired = FALSE, var.equal = FALSE, data = dose2)
rbind(
  list(d2_test.eq.true$p.value, 
       d2_test.eq.true$conf.int[1], d2_test.eq.true$conf.int[2]),
  list(d2_test.eq.false$p.value, 
       d2_test.eq.false$conf.int[1], d2_test.eq.false$conf.int[2])
)
##      [,1]      [,2]      [,3]    
## [1,] 0.9637098 -3.722999 3.562999
## [2,] 0.9638516 -3.79807  3.63807