# Bootstrap example: Estimate correlation between LSAT and GPA
library(bootstrap) #for the law data
print(cor(law$LSAT, law$GPA))
[1] 0.7763745
[1] 0.7599979
# Set up the bootstrap
B <- 200 # number of replicates
n <- nrow(law) # sample size
R <- numeric(B) # storage for replicates
# Bootstrap estimate of correlation
for (i in 1:B) {
idx <- sample(1:n, size=n, replace=TRUE)
law_boot <- law[idx, ]
R[i] <- cor(law_boot$LSAT, law_boot$GPA)
}
mean(R)
[1] 0.7839569
[1] 0.122684