2
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ I don't see a problem here: what is the issue you are trying to ask about? $\endgroup$
    – whuber
    Sep 13, 2022 at 22:34
  • $\begingroup$ @whuber The first answer and the second give two different results - which one is the standard error of the sample mean? $\endgroup$
    – FACEIT
    Sep 13, 2022 at 22:56
  • $\begingroup$ Of course they give different results, because they are based on random simulations! The differences are so small that they can be attributed to the random variation. To check whether that's right, run your simulations several times (starting from different seeds, of course). $\endgroup$
    – whuber
    Sep 14, 2022 at 15:31

1 Answer 1

0
$\begingroup$

The problem is that your second approach is not estimating the thing you want to be estimating, i.e. $\mathrm{SD}(\bar y)$. You should instead use

> set.seed(1)
> sd(replicate(1000000, mean(sample(y, replace=TRUE))))
[1] 0.4323913

which gives an answer that is within the simulation variability of your other approaches.

To use the bootstrap here, you need to (i) create the bootstrap sample, (ii) calculate the statistic whose distribution you are trying to learn about (the mean in this case), (iii) calculate the empiric standard deviation of that statistic.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.