we will examine ToothGrowth data set in R.
dose variable positively effect len at p-value
< 0.001. supp variable have some effect on
len at p-value = 0.06. Choice of \(\alpha\) is not explicitly stated, and is
left for reader judgement.
data("ToothGrowth")
#?ToothGrowth
typing in ?ToothGrowth command show some info about the
dataset. Response, or the output of interest, is the length
len of some cell related to tooth growth from 60 guinea
pigs. The 2 inputs are:
dose level of vitamin C, either 0.5, 1 or 2
mg/day
supp delivery method, Orange Juice as
OJ or ascorbic acid VC
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 ...
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
60 rows, 3 col
first column is len
second column is factor OJ or VC
third column is dose
there are no NAs in this data set, neat!
pairs(ToothGrowth)
# level of doses
unique(ToothGrowth$dose)
## [1] 0.5 1.0 2.0
# 3 levels are 0.5, 1, 2
#hist(ToothGrowth$len)
since our response len is continuous, we will use
t.test to compare mean len from
OJ vs VC Assumptions: 1. homogeneity of
variance 2. Independent , randomly sample 3. len is normally
distributed
#plot(len~supp,data = ToothGrowth)
tTest<-with(ToothGrowth,
t.test(
subset(len, supp == "OJ"),
subset(len, supp == "VC")
)
)
tTest
##
## Welch Two Sample t-test
##
## data: subset(len, supp == "OJ") and subset(len, supp == "VC")
## 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 of x mean of y
## 20.66333 16.96333
mean of len from OJ is 20.66 while mean
len from VC is 16.96 (p-value = 0.0606345)
with effect size of -3.7
if we set \(\alpha\) at 5%, we would
accept null hypothesis that supp is not related to
len.
first dose = 0.5 and 2
tTest<-with(ToothGrowth,
t.test(
subset(len, dose == 0.5),
subset(len, dose == 2)
)
)
tTest
##
## Welch Two Sample t-test
##
## data: subset(len, dose == 0.5) and subset(len, dose == 2)
## 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 of x mean of y
## 10.605 26.100
(p-value = 4.397525^{-14}) with effect size of 15.495 at dose = 0.5 vs 2. This is statistical significant if \(\alpha=0.05\)
Next dose = 1 and 2
tTest<-with(ToothGrowth,
t.test(
subset(len, dose == 1),
subset(len, dose == 2)
)
)
tTest
##
## Welch Two Sample t-test
##
## data: subset(len, dose == 1) and subset(len, dose == 2)
## 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 of x mean of y
## 19.735 26.100
(p-value = 1.9064295^{-5}) with effect size of 6.365 at dose = 1 vs 2. This is statistical significant if \(\alpha=0.05\)
Lastly, dose = 0.5 and 1
tTest<-with(ToothGrowth,
t.test(
subset(len, dose == 0.5),
subset(len, dose == 1)
)
)
tTest
##
## Welch Two Sample t-test
##
## data: subset(len, dose == 0.5) and subset(len, dose == 1)
## 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 of x mean of y
## 10.605 19.735
(p-value = 1.2683007^{-7}) with effect size of 9.13 at dose = 1 vs 2 this is statistical significant if \(\alpha=0.05\)
summary(glm(len~dose, data = ToothGrowth))
##
## Call:
## glm(formula = len ~ dose, data = ToothGrowth)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -8.4496 -2.7406 -0.7452 2.8344 10.1139
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.4225 1.2601 5.89 2.06e-07 ***
## dose 9.7636 0.9525 10.25 1.23e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 21.17078)
##
## Null deviance: 3452.2 on 59 degrees of freedom
## Residual deviance: 1227.9 on 58 degrees of freedom
## AIC: 357.4
##
## Number of Fisher Scoring iterations: 2
## dose effect size = 9.76, p-val < 0.001
summary(glm(len~dose+supp, data = ToothGrowth))
##
## Call:
## glm(formula = len ~ dose + supp, data = ToothGrowth)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -6.600 -3.700 0.373 2.116 8.800
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.2725 1.2824 7.231 1.31e-09 ***
## dose 9.7636 0.8768 11.135 6.31e-16 ***
## suppVC -3.7000 1.0936 -3.383 0.0013 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 17.93956)
##
## Null deviance: 3452.2 on 59 degrees of freedom
## Residual deviance: 1022.6 on 57 degrees of freedom
## AIC: 348.42
##
## Number of Fisher Scoring iterations: 2
## if we incldue dose and supp in the linear model at the same time, supp (that was statisticall insignificant alone) now become sig at p-val = 0.0013
## plot with line from group mean
plot(len~dose,data = ToothGrowth)
xs <- c(0.5,1,2)
ys <- aggregate(ToothGrowth$len,list(ToothGrowth$dose), mean)[,2]
lines(xs,ys)