I am asked to calculate the standard error of the sample mean using bootstrapping for this data set
y = c(4.9, 3.3, 2.2, 2.3, 1.6, 2.4, 4.7, 1.4, 1.7, 5.1)
The solutions are as follows:
set.seed(12345)
nsim = 10^6
ybar.sim = numeric(nsim)
for (i in 1:nsim){
y.sim = sample(y, replace=TRUE)
ybar.sim[i] = mean(y.sim)
}
se.boot = sd(ybar.sim); se.boot
[1] 0.4322378
whereas I thought it would be this way:
mean(replicate(1000000, sd(sample(
y, replace=TRUE))/sqrt(length(y))))
which gives [1] 0.4264217
and using the boot
library gives:
bootmean <- function(d, i) mean(d[i])
bs <- boot(y, bootmean, R=1000000, stype="i")
print(bs)
Bootstrap Statistics :
original bias std. error
t1* 2.96 0.00021043 0.4318501
which is similar to the first answer.
I do not understand why the first answer is correct given the formula for standard error is the standard deviation divided by the length of the vector. Why is the second answer wrong?