You may have noticed that although we have created confidence intervals for a mean, we have not done hypothesis tests for a mean – until now.
Remember that a randomization distribution should simulate a situation that
The randomization distributions we have seen so far have either used
rflip()
to simulate categorical data with a specified proportion, orshuffle()
to ensure that there is no association between two variables.Neither of these will work for a hypothesis about a mean. We need a new idea. Here it is:
We can create a randomization distribution for a test about a single mean by shifting the bootstrap distribution to make it centered in the right location.
This will give us a distribution that is centered at the value specified by the null hypothesis and the appropriate amount of variability.
Here’s how.
mean(~BodyTemp, data = BodyTemp50)
## [1] 98.26
# Create the Bootstrap distribution
Temp_boot <-
do(2000) * df_stats( ~ BodyTemp, data = resample(BodyTemp50), mean_BodyTemp = mean)
# Shift it so that it is centered in the correct place for our hypothesis
Temp_null <-
Temp_boot %>% mutate(mean_BodyTemp = mean_BodyTemp + (98.6 - 98.26))
Notice that 98.6 lies a bit out side the 95% confidence interval and the p-value is a bit less than 0.05.
# 95% confidence interval
cdata(~ mean_BodyTemp, data = Temp_boot)
## lower upper central.p
## 2.5% 98.05 98.47 0.95
# p-value for test of H0: mu = 98.6
2 * prop(~ (mean_BodyTemp <= 98.26), data = Temp_null)
## prop_TRUE
## 0