Overview

In this document, we will discuss the effect of supplement type and dose amount on the growth of teeth to know which of them has the great effect on tooth growth. The data used is ToothGrowth database.

Loading and preprocessing the data

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(datasets)
data <- ToothGrowth

Summary of the Data

str(data)
## '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 ...
summary(data)
##       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
head(data)
##    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
ggplot(aes(x=supp, y=len), data=ToothGrowth) + geom_boxplot(aes(fill=supp)) + xlab("Supplement Delivery") + ylab("Tooth Length") + facet_grid(~ dose) + ggtitle("Tooth Length vs Delivery Method for different dosages") +
theme(plot.title = element_text(lineheight=.6))

Mean of Data Based on Dose Amount and Supplement Type

mean <- aggregate(len ~ ., data = data, FUN=mean)
meanTabs <- xtabs(len ~ ., data = mean)
meanTabs
##     dose
## supp   0.5     1     2
##   OJ 13.23 22.70 26.06
##   VC  7.98 16.77 26.14

Comparing Tooth Growth by Supp and Dose

Comparing Tooth Growth by Supp

suppTest <- t.test(data$len ~ data$supp)
suppTest$p.value
## [1] 0.06063451

Comparing Tooth Growth by Dose

g1 <- subset(ToothGrowth, data$dose == 0.5)
g2 <- subset(ToothGrowth, data$dose == 1.0)
g3 <- subset(ToothGrowth, data$dose == 2.0)
doseTest12 <- t.test(g1$len, g2$len)
doseTest12$p.value
## [1] 1.268301e-07
doseTest13 <- t.test(g1$len, g3$len)
doseTest13$p.value
## [1] 4.397525e-14
doseTest23 <- t.test(g2$len, g3$len)
doseTest23$p.value
## [1] 1.90643e-05

Conclusion

The dose p-values does not exceed 0.05 so they are statistically significance. While supplement p-value exceeds 0.05. This implies that dose amount has more effect on the teeth growth as by increasing dose amount, the teeth growth rate increases.