# How to Calculate a Bootstrap Standard Error in R

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 with replacement 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)

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)