How can I calculate a Bootstrap Standard Error in R?

To calculate a Bootstrap Standard Error in R, you would need to use the boot package. This package allows you to resample your data and then calculate the standard error of the bootstrapped sample. You can then use this standard error to get an estimate of the confidence interval of your statistic.


Bootstrapping is a method that can be used to estimate the standard error of a mean.

The basic process for calculating a bootstrapped standard error is as follows:

  • Take k repeated samples from a given dataset.
  • For each sample, calculate the standard error: s/√n
  • This results in k different estimates for the standard error. To find the bootstrapped standard error, take the mean of the k standard errors.

The following examples explain two different methods that can be used to calculate a bootstrapped standard error in R.

Method 1: Use the Boot Package

One way to calculate a bootstrap standard error in R is to use the boot() function from the boot library.

The following code shows how to calculate a bootstrap standard error for a given dataset in R:

#make this example reproducible
set.seed(10)

#load boot library
library(boot)

#define dataset
x <- c(12, 14, 14, 15, 18, 21, 25, 29, 32, 35)

#define function to calculate mean
meanFunc <- function(x,i){mean(x[i])}

#calculate standard error using 100 bootstrapped samples
boot(x, meanFunc, 100)

Bootstrap Statistics :
    original  bias    std. error
t1*     21.5   0.254    2.379263

The “original” value of 21.5 shows the mean of the original dataset. The “std. error” value of 2.379263 shows the bootstrap standard error of the mean.

Note that we used 100 bootstrapped samples to estimate the standard error of the mean in this example, but we could have used 1,000 or 10,000 or any number of bootstrapped samples we’ d like.

Method 2: Write Your Own Formula

Another way to calculate a bootstrapped standard error is to write our own function.

The following code shows how to do so:

#make this example reproducible
set.seed(10)

#load boot library
library(boot)

#define dataset
x <- c(12, 14, 14, 15, 18, 21, 25, 29, 32, 35)

mean(replicate(100, sd(sample(x, replace=T))/sqrt(length(x))))

[1] 2.497414

The bootstrapped standard error turns out to be 2.497414.

Notice that this standard error is quite similar to the one calculated in the previous example.

x