Now, the markdown file will show how to analyze the ToothGrowth data in the R datasets package. #Load the ToothGrowth data
library(datasets)
As we can see from dim function , the size about the data and there are 3 rows :
dim(ToothGrowth)
## [1] 60 3
let s check out more detail from the head:
head(ToothGrowth)
then use table function to see supp and dose :
table(ToothGrowth$supp)
##
## OJ VC
## 30 30
table(ToothGrowth$dose)
##
## 0.5 1 2
## 20 20 20
After viewing the info. up there , we will gather the basic detail from this data. To know more , #Provide a basic summary of the data. So, if we can seperate the data from “dose”, it will give us a better understanding of the data:
ggplot(ToothGrowth, aes(factor(dose), len, fill = factor(dose))) +
geom_boxplot() +
facet_grid(.~supp, labeller = as_labeller(c("OJ" = "Orange juice", "VC" = "Ascorbic Acid"))) +
labs(title = "Tooth growth of 60 guinea pigs by dosage and\nby delivery method of vitamin C",
x = "Dose in milligrams/day",
y = "Tooth Lengh") +
scale_fill_discrete(name = "Dosage of\nvitamin C\nin mg/day")
g2 <- ggplot(ToothGrowth, aes(x = dose, y = len, dose = factor(supp)))
g2 <- g2 + geom_line(size = 1, aes(colour = supp)) + geom_point(size =10, pch = 21, alpha = .5)
g2
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 ...
supp.t1 <- t.test(len~supp, paired=F, var.equal=T, data=ToothGrowth)
supp.t2 <- t.test(len~supp, paired=F, var.equal=F, data=ToothGrowth)
supp.result <- data.frame("p-value"=c(supp.t1$p.value, supp.t2$p.value),
"Conf-Low"=c(supp.t1$conf[1],supp.t2$conf[1]),
"Conf-High"=c(supp.t1$conf[2],supp.t2$conf[2]),
row.names=c("Equal Var","Unequal Var"))
supp.result
-For lower dosages (0.5 and 1.0 mg), OJ provides more tooth growth than VC;
-For 2.0mg dosage tooth growth is teh same for both supplement methods;
-Higher dosages give more growth, indepedent of supplemetn method