Overview

This assignment will make inferences based on a dataset describing the effects of Ascorbic Acid (Vitamin C) absorption on tooth growth rates in guinea pigs. ## Assignment Objectives - Load the ToothGrowth data and perform some basic exploratory data analyses - Provide a basic summary of the data. - Use confidence intervals and/or hypothesis tests to compare tooth growth by supp and dose. - State your conclusions and the assumptions needed for your conclusions.

R Environment Setup

invisible(lapply(c("data.table","ggplot2",'dplyr',"knitr","xtable",
                   "reshape2","DT","formattable","gt","datasets", "tidyr",
                   "gridExtra","GGally"), library, character.only = TRUE))
data(ToothGrowth)
toothGrowth <- ToothGrowth 
toothGrowth$dose <- as.factor(toothGrowth$dose)

Basic Dataset Summary

Showing the basic summary for the dataset:

summary(toothGrowth$len) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.20   13.07   19.25   18.81   25.27   33.90
table(toothGrowth$supp, toothGrowth$dose)
##     
##      0.5  1  2
##   OJ  10 10 10
##   VC  10 10 10

Now, a series of boxplots to highlight the quantile distributions between all variables:

The lower left plot is of particular interest, as it seems to show that OJ supplementation has a higher impact on tooth growth than VC for doses of 0.5 and 1. This hypothesis will be tested further.

First, the length mean per dosage and supplement will be evidenced:

toothGrowth %>%
    group_by(supp, dose) %>%summarize(length_mean = mean(len), .groups='drop') %>%
    spread(supp, length_mean) %>%     mutate(difference = abs(VC - OJ))
## # A tibble: 3 × 4
##   dose     OJ    VC difference
##   <fct> <dbl> <dbl>      <dbl>
## 1 0.5    13.2  7.98     5.25  
## 2 1      22.7 16.8      5.93  
## 3 2      26.1 26.1      0.0800

While the hypothesis is intuitively positive for the two lower dosages, the behaviour of both supplements at a dosage of 2 is unclear and requires formal testing. For that purpose, we will use t.test to find the p-values and confidence intervals to perform hypothesis testing.

#Hypothesis Testing Consider the following hypothesis: - The null hypothesis is: OJ and VC have no significant difference - The alternative hypothesis is: OJ and VC have a statistically significant difference - \(\alpha\) = 0.05 The hypothesis will be tested independently for each dosage.

dose_05 <- filter(toothGrowth, dose == 0.5)
dose_10 <- filter(toothGrowth, dose == 1)
dose_20 <- filter(toothGrowth, dose == 2)

t.test(len ~ supp, dose_05)
## 
##  Welch Two Sample t-test
## 
## data:  len by supp
## t = 3.1697, df = 14.969, p-value = 0.006359
## alternative hypothesis: true difference in means between group OJ and group VC is not equal to 0
## 95 percent confidence interval:
##  1.719057 8.780943
## sample estimates:
## mean in group OJ mean in group VC 
##            13.23             7.98
t.test(len ~ supp, dose_10)
## 
##  Welch Two Sample t-test
## 
## data:  len by supp
## t = 4.0328, df = 15.358, p-value = 0.001038
## alternative hypothesis: true difference in means between group OJ and group VC is not equal to 0
## 95 percent confidence interval:
##  2.802148 9.057852
## sample estimates:
## mean in group OJ mean in group VC 
##            22.70            16.77
t.test(len ~ supp, dose_20)
## 
##  Welch Two Sample t-test
## 
## data:  len by supp
## t = -0.046136, df = 14.04, p-value = 0.9639
## alternative hypothesis: true difference in means between group OJ and group VC is not equal to 0
## 95 percent confidence interval:
##  -3.79807  3.63807
## sample estimates:
## mean in group OJ mean in group VC 
##            26.06            26.14

Summarizing:

dose <- c(0.5, 1.0, 2.0)
p_value <- c(0.006359, 0.001038, 0.963900)
confidence_low <- c(1.7190,2.802148,-3.79807)
confidence_high <- c(8.780943,9.057852,3.63807)
decision <- c("Reject null hypothesis", "Reject null hypothesis", "Null cannot be rejected")
data.frame(dose, confidence_low,confidence_high, p_value, decision)
##   dose confidence_low confidence_high  p_value                decision
## 1  0.5       1.719000        8.780943 0.006359  Reject null hypothesis
## 2  1.0       2.802148        9.057852 0.001038  Reject null hypothesis
## 3  2.0      -3.798070        3.638070 0.963900 Null cannot be rejected

The smaller difference in mean for each cohort (OJ, VC) when the dosage is either 0.5 or 1 makes for a smaller p-value, much lower than the \(\alpha = 0.05\) threshold, rejecting the null hypothesis and confirming a statistically significant difference between the supplements. On the other hand, the smaller difference in mean and distribution for the dosage 2.0 makes the p-value larger, in fact nearly double the alpha threshold, and thus the null hypothesis cannot be rejected for this cohort.

Conclusion

The main assumptions for the validity of the results are that the sample is unbiased, representative of the population, and that the variables are also random.

For the validity of the t.test, the following assumptions had to be made: - The data must be unpaired, that is, independent (paired data would require it to be normally distributed in order for the t test to work, but that’s not the case) - The cohorts don’t have the same variance

The final conclusion is that supplement OC leads to more tooth growth, in terms of tooth length, than supplement VC - when the dosage is equal or lesser than 1.0. No statistical inferences could be made for larger dosages.