This analysis uses the dataset “ToothGrowth” which measures the effect of supplements at 3 dosage level on the tooth Lengh of 10 Guinea Pigs.
The dataset has 3 variables :-
1.the length of Tooth len
2.Supplements used supp (a)Orange Juice OJ (b) Ascorbic acidVC
3.Dosage dose of Vitamin c at 3 levels0.5mg,1mg and 2mg
#Loading and Analysis of the ToothGrowth dataset
library(datasets)
data(ToothGrowth)
summary(ToothGrowth) #Shows the summary of the dataset
## 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
#Re-arranging the dataset
supp<-unique(ToothGrowth$supp)
dose<-unique(ToothGrowth$dose)
dat<-data.frame()
for (i in 1:length(supp)){
for(j in 1:length(dose)){
rr<-ToothGrowth[ToothGrowth$supp==supp[i] &ToothGrowth$dose==dose[j],1]
dat<-(rbind(dat,rr))
}
}
rownames(dat)<-c("VC0.5","VC1","VC2","OJ0.5","OJ1","OJ2")
colnames(dat)<-NULL
dat<-t(dat)
#Final dataset for performing the test
datdf<-as.data.frame(dat)
datdf
## VC0.5 VC1 VC2 OJ0.5 OJ1 OJ2
## 1 4.2 16.5 23.6 15.2 19.7 25.5
## 2 11.5 16.5 18.5 21.5 23.3 26.4
## 3 7.3 15.2 33.9 17.6 23.6 22.4
## 4 5.8 17.3 25.5 9.7 26.4 24.5
## 5 6.4 22.5 26.4 14.5 20.0 24.8
## 6 10.0 17.3 32.5 10.0 25.2 30.9
## 7 11.2 13.6 26.7 8.2 25.8 26.4
## 8 11.2 14.5 21.5 9.4 21.2 27.3
## 9 5.2 18.8 23.3 16.5 14.5 29.4
## 10 7.0 15.5 29.5 9.7 27.3 23.0
require(graphics)
coplot(len ~ dose | supp, data = ToothGrowth,
panel = panel.smooth,
xlab = "ToothGrowth data: length vs dose, given type of supplement")
From the plot it can be seen that the OJ has better effect on the tooth length than VC at dose levels 0.5mg and 1mg.
t-Test to compare the means of two groups under the assumption that both samples are independent, and come from population with unequal variances
Null Hypothesis:Equality of means signifying similar effect of both supplements on the tooth length
The absolute value of the test statistic is 2.262157 .
#t-test for the supplements for 0.5mg of dose
t.test(datdf$OJ0.5,datdf$VC0.5,paired=F,var.equal=F,)
##
## Welch Two Sample t-test
##
## data: datdf$OJ0.5 and datdf$VC0.5
## 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
The t value is greater than the Test statistic and the p value is not greater than 0.05. Null Hypothesis is rejected as the means differ significantly for 0.5mg of OJ,thus having a higher mean value(higher effect).
#t-test for the supplements for 1mg of dose
t.test(datdf$OJ1,datdf$VC1,paired=F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: datdf$OJ1 and datdf$VC1
## 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
The t value is greater than the Test statistic and the p value is not greater than 0.05. Null Hypothesis is rejected as the means differ significantly for 1 mg of OJ,thus having a higher mean value(higher effect).
#t-test for the supplements for 2mg of dose
t.test(datdf$OJ2,datdf$VC2,paired=F,var.equal=F)
##
## Welch Two Sample t-test
##
## data: datdf$OJ2 and datdf$VC2
## 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
The t value is smaller than the Test statistic and the p value is greater than 0.05. Null Hypothesis is accepted as the means are similar for 2 mg of OJ and VC , thus having similar effect.