1. Load the ToothGrowth data and perform some basic exploratory data analyses

library(datasets)
library(ggplot2)

data(ToothGrowth)

dim(ToothGrowth)
## [1] 60  3
names(ToothGrowth)
## [1] "len"  "supp" "dose"
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 ...
ggplot(data=ToothGrowth, aes(x=len, fill=supp)) +geom_bar(stat="bin")+ scale_fill_brewer(palette="Set3")
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.

g <- ggplot(ToothGrowth, aes(dose, len))
g + geom_point(aes(color = supp), size = 4, alpha = 1/2) + labs(title = "Tooth Growth") + labs(x ="Dose", y="Tooth Length")# + scale_colour_hue(palette="YlGn")

2. Provide a basic summary of the data.

head(ToothGrowth)
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5
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
table(ToothGrowth$dose, ToothGrowth$supp)
##      
##       OJ VC
##   0.5 10 10
##   1   10 10
##   2   10 10

3. Use confidence intervals and/or hypothesis tests to compare tooth growth by supp and dose.

#t test for difference in length due to supplement type
#Assuming unequal variances

t.test(len ~ supp, data = ToothGrowth)
## 
##  Welch Two Sample t-test
## 
## data:  len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1710156  7.5710156
## sample estimates:
## mean in group OJ mean in group VC 
##         20.66333         16.96333

The result of the t test has a p value of 0.06 and the confidence interval contains 0. This means that we cannot reject the null hypothese, thus, the supplement type does not have an impact on the length of teeth.

#difference in length due to different types of dose
#creating groups by dose level

ToothGrowth_0.5_1.0 <- subset (ToothGrowth, dose %in% c(0.5, 1.0)) 
ToothGrowth_0.5_2.0 <- subset (ToothGrowth, dose %in% c(0.5, 2.0)) 
ToothGrowth_1.0_2.0 <- subset (ToothGrowth, dose %in% c(1.0, 2.0)) 

#testing for difference in length due to dose value
#assuming equal variances for all three

t.test(len ~ dose, data = ToothGrowth_0.5_1.0)
## 
##  Welch Two Sample t-test
## 
## data:  len by dose
## t = -6.4766, df = 37.986, p-value = 1.268e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.983781  -6.276219
## sample estimates:
## mean in group 0.5   mean in group 1 
##            10.605            19.735
t.test(len ~ dose, data = ToothGrowth_0.5_2.0)
## 
##  Welch Two Sample t-test
## 
## data:  len by dose
## t = -11.799, df = 36.883, p-value = 4.398e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -18.15617 -12.83383
## sample estimates:
## mean in group 0.5   mean in group 2 
##            10.605            26.100
t.test(len ~ dose, data = ToothGrowth_1.0_2.0)
## 
##  Welch Two Sample t-test
## 
## data:  len by dose
## t = -4.9005, df = 37.101, p-value = 1.906e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.996481 -3.733519
## sample estimates:
## mean in group 1 mean in group 2 
##          19.735          26.100

The p-value for all three tests are very small. Aslo, the confidence intervals for all three does not contain 0. As a result we reject the null hypothesis. This means that the dose value has an effect on teeth growth.

4. State your conclusions and the assumptions needed for your conclusions.

Conclusion From the t tests it can be concluded that the type of supplement has no impact on the lenth of teeth, where as incearing value of dose leads to an increased length of teeth.

Assumptions

  1. Population variances are equal

  2. The sample of pigs selectcted were salected randomly and represent the population

  3. The samples are independent- one sample was not given more than one supplement or a different dose level