Chapter 14 Sources
14.1 t-test
The data set shows energy expend in two groups of women: stature
library(ISwR)
data(energy)
attach(energy)
## The following objects are masked from energy (pos = 22):
##
## expend, stature
head(energy)
## expend stature
## 1 9.21 obese
## 2 7.53 lean
## 3 7.48 lean
## 4 8.08 lean
## 5 8.09 lean
## 6 10.15 lean
tapply(expend, stature, mean)
## lean obese
## 8.066154 10.297778
H0: there is no difference in averages between lean and obese.
t.test(expend ~ stature)
##
## Welch Two Sample t-test
##
## data: expend by stature
## t = -3.8555, df = 15.919, p-value = 0.001411
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -3.459167 -1.004081
## sample estimates:
## mean in group lean mean in group obese
## 8.066154 10.297778
Alternative hypothesis is true - means are different.
Mean difference is in between -3.5 and 1.0 with a probability 95%.
The risk of error is 0.15%
14.1.1 Two-tailed test
Compair two sets of variables.
data(intake) # from package ISwR
attach(intake)
## The following objects are masked from intake (pos = 22):
##
## post, pre
head(intake)
## pre post
## 1 5260 3910
## 2 5470 4220
## 3 5640 3885
## 4 6180 5160
## 5 6390 5645
## 6 6515 4680
mean(post - pre)
## [1] -1320.455
Is difference of means significant?
t.test(pre, post, paired=TRUE)
##
## Paired t-test
##
## data: pre and post
## t = 11.941, df = 10, p-value = 3.059e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 1074.072 1566.838
## sample estimates:
## mean of the differences
## 1320.455
The difference is significant with a probability 95%.
The difference is in between 1074.1 and 1566.8 kJ/day