Load the ToothGrowth data and perform some basic exploratory data analyses

library(datasets)
data("ToothGrowth")
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 ...
with(ToothGrowth, table(dose))
## dose
## 0.5   1   2 
##  20  20  20
with(ToothGrowth, hist(len))

the data is dataframe with 60 observations and 3 variables, the first col is len which varies from 4.2 to 33.90 with mean 18.81. the second vairable is supp which has two levels of OJ and VC of 30. the third variable is dose which has 3 levels of .5, 1 and 2, 20 observations for each level.

use confidence interval and hypothesis test to compare tooth growth by supp and dose

attach(ToothGrowth)
g1 <- len[1 : 30]
g2 <- len[31 : 60]
t.test(g1,g2, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g1 and g2
## t = -1.9153, df = 58, p-value = 0.06039
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -7.5670064  0.1670064
## sample estimates:
## mean of x mean of y 
##  16.96333  20.66333
detach(ToothGrowth)

The 95 percent confidence interval is [1.408659, 5.991341]. It shows that there is difference between the len grouped by supp under the assumptions that those observation are identically independent distributed with normal distribution.

attach(ToothGrowth)
g1 <- len[1 : 10]
g2 <- len[11 : 20]
g3 <- len[21 : 30]
t.test(g1,g2, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g1 and g2
## t = -7.4634, df = 18, p-value = 6.492e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.264346  -6.315654
## sample estimates:
## mean of x mean of y 
##      7.98     16.77
t.test(g3,g2, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g3 and g2
## t = 5.4698, df = 18, p-value = 3.398e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   5.77104 12.96896
## sample estimates:
## mean of x mean of y 
##     26.14     16.77
t.test(g1,g3, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g1 and g3
## t = -10.388, df = 18, p-value = 4.957e-09
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -21.83284 -14.48716
## sample estimates:
## mean of x mean of y 
##      7.98     26.14
detach(ToothGrowth)

It show dose has impacts on len for supp group OJ under the assumptions that those observation are identically independent distributed with normal distribution and the data is not paired.

attach(ToothGrowth)
g1 <- len[1 : 10+30]
g2 <- len[11 : 20+30]
g3 <- len[21 : 30+30]
t.test(g1,g2, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g1 and g2
## t = -5.0486, df = 18, p-value = 8.358e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -13.410814  -5.529186
## sample estimates:
## mean of x mean of y 
##     13.23     22.70
t.test(g3,g2, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g3 and g2
## t = 2.2478, df = 18, p-value = 0.03736
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.2194983 6.5005017
## sample estimates:
## mean of x mean of y 
##     26.06     22.70
t.test(g1,g3, paired = F, var.equal= T)
## 
##  Two Sample t-test
## 
## data:  g1 and g3
## t = -7.817, df = 18, p-value = 3.402e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -16.278223  -9.381777
## sample estimates:
## mean of x mean of y 
##     13.23     26.06
detach(ToothGrowth)

It show dose has impacts on len for supp group VC too under the assumptions that those observation are identically independent distributed with normal distribution and the data is not paired.