# standard error of sample mean

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?

• I don't see a problem here: what is the issue you are trying to ask about?
– whuber
Sep 13, 2022 at 22:34
• @whuber The first answer and the second give two different results - which one is the standard error of the sample mean? Sep 13, 2022 at 22:56
• 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).
– whuber
Sep 14, 2022 at 15:31

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)