Tooth growth data from datasets library records different tooth length when the subject is given differnt dosages(0.5,1.0,2.0) of supplement orange juice or Vitamin C. To find whether supplement affects tooth length, a t test is carried out on tooth length of different dosages(low-0.5 high-2.0) of orange juice/vitamin C.
library(datasets)
library(ggplot2)
data("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 ...
qplot(x=supp,y=len,data = ToothGrowth,facets = .~dose,geom = "boxplot",main="Length by supp and dose")
Dosage affects tooth length more significantly than supp type. Orange juice helps tooth growth more than Vitamin C.
Null hypothesis: Tooth growth is not affected by Orange Juice. Alternative hypothesis: Tooth growth is affected by Orange Juice. T test between tooth length of different dosages(OJ):
orange_0.5 <- ToothGrowth$len[ToothGrowth$supp=="OJ"&ToothGrowth$dose==0.5]
orange_2 <- ToothGrowth$len[ToothGrowth$supp=="OJ"&ToothGrowth$dose==2]
t.test(orange_2,orange_0.5,paired = FALSE,var.equal = TRUE,conf.level = .95)
##
## Two Sample t-test
##
## data: orange_2 and orange_0.5
## 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:
## 9.381777 16.278223
## sample estimates:
## mean of x mean of y
## 26.06 13.23
The p-value is extremly small. So we can be very confident to reject the null hypothesis.
Null hypothesis: Tooth growth is not affected by Vitamin C. Alternative hypothesis: Tooth growth is affected by vitamin C. T test between tooth length of different dosages(VC):
vitamin_0.5 <- ToothGrowth$len[ToothGrowth$supp=="VC"&ToothGrowth$dose==0.5]
vitamin_2 <- ToothGrowth$len[ToothGrowth$supp=="VC"&ToothGrowth$dose==2]
t.test(vitamin_2,vitamin_0.5,paired = FALSE,var.equal = TRUE,conf.level = .95)
##
## Two Sample t-test
##
## data: vitamin_2 and vitamin_0.5
## 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:
## 14.48716 21.83284
## sample estimates:
## mean of x mean of y
## 26.14 7.98
The p-value extremly small. So we can be very confident to reject the null hypothesis.
According to the t test, we reject the null hypothesis(tooth length is not affected by orange juice/Vitamin C). Tooth length increases as the dosage of orange juice/Vitamin C increases.