Overview

Here we will explore the ToothGrowth dataset to compare tooth growth by supplement and dose.

Loading Data

1- Loding the required libraries

library(ggplot2)
library(dplyr)

2- Reading data

data(ToothGrowth)

3- Performing some basic exploratory data analysis Introducing a new variable suppDose that combines the supplement and dose. Plotting a bar plot for the suppDose variable and the length growth.

wideTooth <- mutate(ToothGrowth, suppDose = paste(supp,dose,sep="-"))
toothHist <- ggplot(data=wideTooth, aes(x =factor(wideTooth$suppDose) ,y = wideTooth$len, fill = wideTooth$suppDose)) 
toothHist <- toothHist + theme( axis.text.x=element_text(size=16, angle=40, vjust=.8, hjust=1.01))
toothHist = toothHist + geom_bar(stat = "identity") 
toothHist = toothHist + ggtitle("Length Growth by Supplement Dose") 
toothHist = toothHist + xlab("Supplement-Dose")  
toothHist = toothHist + ylab("Length Growth")
toothHist <- toothHist + guides(fill=guide_legend(title="Supplement-Dose"))
print(toothHist)

Provide Basic Summary Of The Data

dim(wideTooth)
## [1] 60  4
colnames(wideTooth)
## [1] "len"      "supp"     "dose"     "suppDose"
summary(wideTooth)
##       len        supp         dose         suppDose        
##  Min.   : 4.20   OJ:30   Min.   :0.500   Length:60         
##  1st Qu.:13.07   VC:30   1st Qu.:0.500   Class :character  
##  Median :19.25           Median :1.000   Mode  :character  
##  Mean   :18.81           Mean   :1.167                     
##  3rd Qu.:25.27           3rd Qu.:2.000                     
##  Max.   :33.90           Max.   :2.000

comparing tooth growth by supp and dose using hypothesis tests

1- Separating variables As you can see there are two types of supplements VC (vitamin c) and OJ (orange juice). Each is taken in a dose of either 0.5, 1 or 2 milligrams. Resulting in a total of 6 variables to compare.

vc05 <- wideTooth[wideTooth$suppDose == "VC-0.5",]
vc10 <- wideTooth[wideTooth$suppDose == "VC-1",]
vc20 <- wideTooth[wideTooth$suppDose == "VC-2",]

oj05 <- wideTooth[wideTooth$suppDose == "OJ-0.5",]
oj10 <- wideTooth[wideTooth$suppDose == "OJ-1",]
oj20 <- wideTooth[wideTooth$suppDose == "OJ-2",]

2- Compare the length growth for the 0.5 milligram dose of Vitamin C and Orange Juice

t.test(vc05$len,oj05$len, paired = TRUE, var.equal = FALSE)
## 
##  Paired t-test
## 
## data:  vc05$len and oj05$len
## t = -2.9791, df = 9, p-value = 0.01547
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -9.236542 -1.263458
## sample estimates:
## mean of the differences 
##                   -5.25

3-Compare the length growth for the 1 milligram dose of Vitamin C and Orange Juice

t.test(vc10$len,oj10$len, paired = TRUE, var.equal = FALSE)
## 
##  Paired t-test
## 
## data:  vc10$len and oj10$len
## t = -3.3721, df = 9, p-value = 0.008229
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -9.908089 -1.951911
## sample estimates:
## mean of the differences 
##                   -5.93

4-Compare the length growth for the 2 milligram dose of Vitamin C and Orange Juice

t.test(vc20$len,oj20$len, paired = TRUE, var.equal = FALSE)
## 
##  Paired t-test
## 
## data:  vc20$len and oj20$len
## t = 0.042592, df = 9, p-value = 0.967
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.168976  4.328976
## sample estimates:
## mean of the differences 
##                    0.08

We assume the variables are paired since the experiment is done on the same 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid). We assume non equal variances.

Conclusions

1- For the 0.5 milligram dose of Vitamin C and Orange Juice. The sample means are not equal. Since the t-statistic is -2.9791 and pvalue is 0.01547 therefore we reject the null hypothesis since the pvalue is too small there is a difference in the average tooth growth length when taking 0.5 milligram of vc and oj supplements. This could also be seen in the above bar plot that the tooth length gain is higher when using orange juice

2- For the 1 milligram dose of Vitamin C and Orange Juice. The sample means are not equal. Since t-statistic is -3.3721 and pvalue is 0.008229 therefore we reject the null hypothesis since the pvalue is too small there is a difference in the average tooth growth length when taking 1.0 milligram of vc and oj supplements This could also be seen in the above bar plot that the tooth length gain is higher when using orange juice.

3- For the 2 milligram dose of Vitamin C and Orange Juice. The sample means are indeed equal. Since T-statistic is 0.042592 and pvalue is 0.967. We accept the null hypothesis since the pvalue is large. The averae tooth growth length when taking 2.0 milligram of vc and oj supplements has a 96% chance of being equal. This could also be seen in the above bar plot that the tooth length gain is approximately equal for both supplements when using 2 milligrams dose.