Bootstrapping is sampling with replacement. Here's a simple recipe for calculating the median value from a dataset with bootstrap. ```R B <- 10000 bootMedian <- vector() for(i in 1:B){ bootSample <- sample(data$value, size=nrow(data), replace=TRUE) bootMedian[i] <- median(bootSample) cat("Bootstrap sample:", i, "\n") } # Calculate bootstrap mean, standard error, confidence interval mean(bootMedian) sd(bootMedian) # standard error quantile(bootMedian, probs = c(0.025, 0.975)) # approximate 95% CI # Plot histogram of results ggplot(data= data.frame(bootMedian) , aes(x = bootMedian)) + geom_histogram(col = "black", binwidth = 0.01, closed = "left", boundary = 0) + labs(x = "Bootstrap replicate esimates of the median asymmetry", y = "Frequency") ``` In [[R]], the `boot` package simplifies bootstrap sampling. ```R library(boot) boot.median <- function(x, i){ median(x[i])} bootData <- boot(data$value, boot.median, R = 10000) # Show bootData object bootData # Get confidence intervals boot.ci(bootData, type = "perc") ```