Each animal received one of three dose levels of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods, (orange juice or ascorbic acid (a form of vitamin C and coded as VC). The response is the length of odontoblasts (cells responsible for tooth growth) in 60 guinea pigs. The aim here is to compare the tooth growth by supplement and dose.
library(ggplot2)
set.seed(100)
l <- 0.2
n <- 40
sim_num <- 1000
sim <- replicate(sim_num, rexp(n,l))
means<- apply(sim,2, mean)
hist(means, breaks = 20, xlim = c(0,10), main = "Means of Simulated Exponential Function", col = 'purple')
hist(means, main = "Sample Mean vs Theoretical Mean", xlim = c(0,10), breaks = 20, xlab = "Means", col = 'purple')
abline(v = mean(means), lwd = "3", col = "red")
mean(means)
## [1] 4.999702
The sample mean is 4.999 and the theoretical mean is 1/lambda, where lambda = 0.2, so the theoretical mean is 5. Therefore, there is no variance between the means.
#theoretical
tv<-round((1/l)^2/n, 3)
tv
## [1] 0.625
#sample
av<-round(var(means),3)
av
## [1] 0.643
The standard deviation of the theoretical distribution is (1/lambda)/sqrt(n) and is equal to 0.625, whereas the sample variance is 0.643. Therefore, the sample variance is greater than the calculated theoretical variance.
hist(means, prob=TRUE, main = "Checking for Normal Distribution Pattern", breaks = 20, xlim = c(0,10), xlab = "Means", col = 'purple')
lines(density(means), lwd=3, col="red")
x <- seq(min(means), max(means), length = 2*n)
y <- dnorm(x, mean = 1/l, sd = sqrt(((1/l)/sqrt(n))^2))
lines(x,y, pch = 20, lwd = 3, lty = 1, col='green')
The simulated sample distribution (red) follows a normal distribution pattern (green), which is in agreement with the cental limit theorem, which states that the sum of independent random variables normalize towards a normal distribution even in circumstances in which the original variables are not normally distributed.
Loading the data and basic summary stats
data("ToothGrowth")
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
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 ...
unique(ToothGrowth$dose)
## [1] 0.5 1.0 2.0
The dataset contains 60 observations on 3 variables, with a total of two delivery methods and unique doses of 0.5, 1.0 & 2.0 (mg/day).
g <- ggplot(aes(x = supp, y = len), data = ToothGrowth) +
geom_boxplot(aes(fill = supp)) + facet_wrap(~ dose)
g <- g + labs(title="Tooth Length vs Supplement & Dosage")
g
The boxplot shows that the delivery method plays a major role in the enhancement of tooth growth at low doses of 0.5 and 1.0 (mg/day), with OJ being more effective as compared to VC. At higher doses the effectiveness between the two delivery methods is questionable, however both contribute to greater length than lower doses.
supplement<-t.test(len ~ supp, paired = F, data = ToothGrowth)
supplement
##
## 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
Statistical significance supports the Null hypothesis, which we fail to reject. The delivery type by itself has no influence on tooth growth.
d0.5<-subset(ToothGrowth, ToothGrowth$dose <= 1.0)
d1<-subset(ToothGrowth, ToothGrowth$dose > 0.5)
d2<-subset(ToothGrowth, ToothGrowth$dose != 1.0)
d3<-subset(ToothGrowth, ToothGrowth$dose > 1.0)
#effect at 0.5mg/day vs 1.0 md/day
t.test(len ~ dose, paired = F, data = d0.5)
##
## 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
#effect at 1.0 mg/day vs 2.0 md/day
t.test(len ~ dose, paired = F, data = d1)
##
## 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
#effect at 0.5mg/day vs 2.0 md/day
t.test(len ~ dose, paired = F, data = d2)
##
## 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
#supplement variance at 2.0 mg/day
t.test(len ~ supp, paired = F, data = d3)
##
## 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 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
Tooth growth is significantly influenced by the dose and seems to increase with an increasing concentrations. We reject the Null hypothesis in in case.
Increasing dose levels of the two delivery methods show enhanced tooth growth properties. Initially it appeared that the delivery method had no significant impact on tooth length, but when controlling for dose level we discovered that there was a significant difference at 0.5mg and 1.0mg, but not at 2.0mg. Based on this evidence, it appears that OJ is a better delivery method with a larger impact on tooth length for a given dose of VC, but above a maximum dose level there is no further improvement.