L06 Backpack Example
L06 Backpack Example
4)
For the backpack example, we are trying to see if the proportion of backpack weight to body weight is less than
10%.
H0 : percent = 10%
Ha : percent ≤ 10%
library(tidyverse)
summary(perc)
set.seed(256)
M <- 1000
RES <- data.frame(res.med = rep(NA, M),
res.mean = rep(NA, M))
n <- 100
for(i in seq(1:M)){
x <- sample(perc, n, replace = TRUE)
RES$res.med[i] <- median(x)
RES$res.mean[i] <- mean(x)}
Here we plot the results of the bootstrap for the mean and the median.
100
75
count
50
25
7 8 9
res.mean
1
RES %>% ggplot(aes(x=res.med)) + geom_histogram()
150
100
count
50
6 7 8 9
res.med
sd(RES$res.mean)
## [1] 0.3662797
sd(RES$res.med)
## [1] 0.5149362
We can see that the standard deviation of the median is larger than it is for the mean.
Since the bootstrap will be centered around the actual data (and not the null hypothesis), we will shift the results
of the bootstrap by the difference in the mean of the data and the null hypothesis.
To estimate the p-value, we will count the number of observations that are below the observed median.
150
100
count
50
7 8 9 10 11
res.med + my.shift
2
# estimated p-value
sum(RES$res.med + my.shift <= my.median) / M
## [1] 0