THe length of odontoblasts in Guinea pigs can be influenzed by the Vitamin C. They were significant differences with the delivery methods of viatmine C(orange juice(OJ) or ascorbic acid(VC)). - The ascorbic acid was better than orange juice. And the lengths became taller as the dose of vitamin C.
##### Load the ToothGrowth data & some basic exploratory data analyses #####
workingpath <- "C:\\Users\\MED1\\Stat_Inf"
setwd(workingpath)
library(ggplot2); library(gridExtra)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
attach(ToothGrowth)
summary(ToothGrowth$len)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.20 13.07 19.25 18.81 25.27 33.90
table(ToothGrowth$supp)
##
## OJ VC
## 30 30
table(ToothGrowth$dose)
##
## 0.5 1 2
## 20 20 20
##### basic summary of the data #####
basic.sum <- function(test.vec){
res <- c(mean(test.vec), sd(test.vec), median(test.vec), min(test.vec), max(test.vec))
names(res) <- c("mean", "Std.Dev.", "median", "min", "max")
return ( res )
}
total <- basic.sum(ToothGrowth$len)
supp.OJ <- basic.sum(ToothGrowth[ToothGrowth$supp=="OJ",]$len)
supp.VC <- basic.sum(ToothGrowth[ToothGrowth$supp=="VC",]$len)
dose.05 <- basic.sum(ToothGrowth[ToothGrowth$dose==0.5,]$len)
dose.10 <- basic.sum(ToothGrowth[ToothGrowth$dose==1.0,]$len)
dose.20 <- basic.sum(ToothGrowth[ToothGrowth$dose==2.0,]$len)
basic.mat <- rbind( total, supp.OJ, supp.VC, dose.05, dose.10, dose.20 )
print(basic.mat)
## mean Std.Dev. median min max
## total 18.81333 7.649315 19.25 4.2 33.9
## supp.OJ 20.66333 6.605561 22.70 8.2 30.9
## supp.VC 16.96333 8.266029 16.50 4.2 33.9
## dose.05 10.60500 4.499763 9.85 4.2 21.5
## dose.10 19.73500 4.415436 19.25 13.6 27.3
## dose.20 26.10000 3.774150 25.95 18.5 33.9
TG.supp <- ggplot(ToothGrowth, aes(x=supp, y=len, fill=supp)) +
geom_bar(stat="summary", fun.y="mean", position="dodge")
TG.dose <- ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) +
geom_bar(stat='summary', fun.y='mean', position='dodge')
TG.supp.dose <- ggplot(ToothGrowth, aes(x=supp, y=len, fill=dose)) +
geom_bar(stat='summary', fun.y='mean', position='dodge')
TG.dose.supp <- ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
geom_bar(stat='summary', fun.y='mean', position='dodge')
grid.arrange(TG.supp, TG.dose, ncol=2)
grid.arrange(TG.supp.dose, TG.dose.supp, ncol=2)
t.test(len[supp=="OJ"], len[supp=="VC"])$p.value
## [1] 0.06063451
t.test(len[supp=="OJ"], len[supp=="VC"])$conf.int
## [1] -0.1710156 7.5710156
## attr(,"conf.level")
## [1] 0.95
dose.pvalue <- c(t.test(len[dose==0.5], len[dose==1.0])$p.value,
t.test(len[dose==1.0], len[dose==2.0])$p.value,
t.test(len[dose==0.5], len[dose==2.0])$p.value)
names(dose.pvalue) <- c("0.5 vs 1.0", "1.0 vs 2.0", "0.5 vs 2.0")
print(dose.pvalue)
## 0.5 vs 1.0 1.0 vs 2.0 0.5 vs 2.0
## 1.268301e-07 1.906430e-05 4.397525e-14
p.adjust(dose.pvalue, method="bonferroni")
## 0.5 vs 1.0 1.0 vs 2.0 0.5 vs 2.0
## 3.804902e-07 5.719289e-05 1.319257e-13
p.adjust(dose.pvalue, method="BH")
## 0.5 vs 1.0 1.0 vs 2.0 0.5 vs 2.0
## 1.902451e-07 1.906430e-05 1.319257e-13
dose.CI <- rbind(t.test(len[dose==0.5], len[dose==1.0])$conf.int,
t.test(len[dose==1.0], len[dose==2.0])$conf.int,
t.test(len[dose==0.5], len[dose==2.0])$conf.int)
colnames(dose.CI) <- c("lower CI", "upper CI")
rownames(dose.CI) <- c("0.5 vs 1.0", "1.0 vs 2.0", "0.5 vs 2.0")
print(dose.CI)
## lower CI upper CI
## 0.5 vs 1.0 -11.983781 -6.276219
## 1.0 vs 2.0 -8.996481 -3.733519
## 0.5 vs 2.0 -18.156167 -12.833833