Part 2: Inferential Analysis

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

library(datasets)
str(ToothGrowth) #look at variables in dataset
## '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 ...
dim(ToothGrowth) #dimensions of dataset
## [1] 60  3

2. Provide a basic summary of the data.

#look at each variable
table(ToothGrowth$supp)
## 
## OJ VC 
## 30 30
table(ToothGrowth$dose)
## 
## 0.5   1   2 
##  20  20  20
summary(ToothGrowth$len)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.20   13.08   19.25   18.81   25.28   33.90
library(ggplot2)
#boxplots of means by dose and supp
ggplot(aes(supp, len), data=ToothGrowth) + geom_boxplot(aes(fill=supp)) 

ggplot(aes(factor(dose), len), data=ToothGrowth) + geom_boxplot(aes(fill=factor(dose)))

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

#subset data by supplement type
dataOJ <- subset(ToothGrowth, supp == "OJ")
dataVC <- subset(ToothGrowth, supp == "VC")

#H0: mean length with OJ == mean length with VC
#HA: mean length with OJ != mean length with VC
t.test(dataOJ$len, dataVC$len)$conf #fail to reject H0
## [1] -0.1710156  7.5710156
## attr(,"conf.level")
## [1] 0.95
#subset data by dose
data.5 <- subset(ToothGrowth, dose == .5)
data1 <- subset(ToothGrowth, dose == 1)
data2 <- subset(ToothGrowth, dose == 2)

#H0: mean length with dose of 1 == mean length with dose of .5
#HA: mean length with dose of 1 != mean length with dose of .5
t.test(data1$len, data.5$len)$conf #reject H0
## [1]  6.276219 11.983781
## attr(,"conf.level")
## [1] 0.95
#H0: mean length with dose of 2 == mean length with dose of .5
#HA: mean length with dose of 2 != mean length with dose of .5
t.test(data2$len, data.5$len)$conf #reject H0
## [1] 12.83383 18.15617
## attr(,"conf.level")
## [1] 0.95
#H0: mean length with dose of 2 == mean length with dose of 1
#HA: mean length with dose of 2 != mean length with dose of 1
t.test(data2$len, data1$len)$conf #reject H0
## [1] 3.733519 8.996481
## attr(,"conf.level")
## [1] 0.95

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

Based on assumptions of unequal variances, alpha=.05, a sample of guinea pigs that represent a larger population of guinea pigs, and that these guinea pigs were similar in all respects except for randomization of supplement and dosage, we can state the following conclusions:

  1. Supplement type (orange juice vs. ascorbic acid) was not significantly related to length of tooth growth in guinea pigs.

  2. Dosage amount was significantly related to length of tooth growth in guinea pigs, with increasing tooth length for increasing dose.