library(datasets)
library(ggplot2)
head(ToothGrowth)
tail(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
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 ...
Plotting boxplot of toothlength per dosages & supplement:
data <- ToothGrowth
levels(data$supp) <- c("OrangeJuice", "AscorbicAcid")
g <- ggplot(data, aes(x = factor(dose), y = len))
g <- g + facet_grid(.~supp)
g <- g + geom_boxplot(aes(fill = supp))
g <- g + labs(title = "Tooth Length")
g <- g + labs(x = "Dose (mg/day)", y = "Tooth Length")
print(g)
We observe Orange juice shows better results for 0.5 and 1 mg/day dosages however 2 mg/day results are quite similar
We assume from here, ToothGrowth data follows normal distribution.
h0.5 <- t.test(len ~ supp, data = subset(data, dose == 0.5))
h0.5$conf.int
## [1] 1.719057 8.780943
## attr(,"conf.level")
## [1] 0.95
h0.5$p.value
## [1] 0.006358607
We reject null hypothesis as the p-value is smaller than significant level of 0.05. Therefore orange juice results in more tooth growth than absorbic acid.
h1 <- t.test(len ~ supp, data = subset(data, dose == 1))
h1$conf.int
## [1] 2.802148 9.057852
## attr(,"conf.level")
## [1] 0.95
h1$p.value
## [1] 0.001038376
We again reject null hypothesis as the p-value is smaller than significant level of 0.05. Therefore orange juice results in more tooth growth than absorbic acid.
h2 <- t.test(len ~ supp, data = subset(data, dose == 2))
h2$conf.int
## [1] -3.79807 3.63807
## attr(,"conf.level")
## [1] 0.95
h2$p.value
## [1] 0.9638516
Now, p-value is larger than the significance level of 0.05. therefore we cannot reject null hypothesis. Therefor orange juice and absorbic acid have same effect now.
We conducted three hypothesis tests. We inferred that Orange juice is better for tooth growth in guinea pigs in doses of 0.5 and 1 mg/day. however no difference between orange juice and absorbic acid for 2 mg/day dosage.