This is research of ToothGrowth data where I analyse how tooth length depends on dose of Vitamin C and its delivery method.

#Loading data
data(ToothGrowth)

coplot(len ~ dose | supp, data = ToothGrowth, panel = panel.smooth, xlab = "ToothGrowth data: length vs dose, given type of supplement")

From the plot we can assume that there is an increase in tooth length for doses 0.5 and 1.0 when delivery method is orange juice over ascorbic acid. And for dose 2.0 milligram tooth length is equal regardless of delivery method. Let’s check these assumptions using T confidence intervals.

Prepare data for each dose and supplement type.

g_VC_05 <- ToothGrowth[ToothGrowth$supp == 'VC' & ToothGrowth$dose == 0.5, ]$len
g_OJ_05 <- ToothGrowth[ToothGrowth$supp == 'OJ' & ToothGrowth$dose == 0.5, ]$len
g_VC_10 <- ToothGrowth[ToothGrowth$supp == 'VC' & ToothGrowth$dose == 1.0, ]$len
g_OJ_10 <- ToothGrowth[ToothGrowth$supp == 'OJ' & ToothGrowth$dose == 1.0, ]$len
g_VC_20 <- ToothGrowth[ToothGrowth$supp == 'VC' & ToothGrowth$dose == 2.0, ]$len
g_OJ_20 <- ToothGrowth[ToothGrowth$supp == 'OJ' & ToothGrowth$dose == 2.0, ]$len

Perform T tests for doses equal to 0.5 and 1.0 milligram.

t.test(g_OJ_05, g_VC_05, paired = FALSE, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  g_OJ_05 and g_VC_05
## t = 3.1697, df = 14.969, p-value = 0.006359
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1.719057 8.780943
## sample estimates:
## mean of x mean of y 
##     13.23      7.98
t.test(g_OJ_10, g_VC_10, paired = FALSE, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  g_OJ_10 and g_VC_10
## t = 4.0328, df = 15.358, p-value = 0.001038
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  2.802148 9.057852
## sample estimates:
## mean of x mean of y 
##     22.70     16.77

Confidence intervals do not contain zero in both cases, so my assumptions that there is an increase in tooth length when supplement type is orange juice is correct.

Perform T test for dose equals to 2.0 milligram.

t.test(g_OJ_20, g_VC_20, paired = FALSE, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  g_OJ_20 and g_VC_20
## t = -0.0461, df = 14.04, p-value = 0.9639
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.79807  3.63807
## sample estimates:
## mean of x mean of y 
##     26.06     26.14

In this case confidence interval contains zero, so that means there is no advantage one supplement type over the other.