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
VC<-subset(x = ToothGrowth,subset = supp=="VC")
OJ<-subset(x = ToothGrowth,subset = supp=="OJ")
VC05<-subset(x = VC,subset = VC$dose==0.5)
VC10<-subset(x = VC,subset = VC$dose==1.0)
VC20<-subset(x = VC,subset = VC$dose==2.0)
OJ05<-subset(x = OJ,subset = OJ$dose==0.5)
OJ10<-subset(x = OJ,subset = OJ$dose==1.0)
OJ20<-subset(x = OJ,subset = OJ$dose==2.0)
boxplot(VC05$len,VC10$len,VC20$len,
OJ05$len,OJ10$len,OJ20$len,
names=c("VC0.5","VC1.0","VC2.0",
"OJ0.5","OJ1.0","OJ2.0"),
xlab = "Group by Supp and Dose",ylab = "Len",main = "Len of ToothGrowth Grouped by Supp and Dose")
The figure shows that:
This analysis compared across different supp group, {VC,OJ}, with controlled dose.
t.test(VC05$len,OJ05$len)$p.value;t.test(VC10$len,OJ10$len)$p.value;t.test(VC20$len,OJ20$len)$p.value
## [1] 0.006358607
## [1] 0.001038376
## [1] 0.9638516
By using 5% level of significance with the null hypothesis that len of different supp (but the same dose) is equal, only at dose 2.0 which we cannot reject the null hypothesis (since p-value > 0.05). In other words, OJ0.5 and OJ1.0 increased more len than VC0.5 and VC1.0 respectively. But, OJ2.0 and VC2.0 tended to provide equal effect.