Quick bootstrapping of confidence intervals for linear models in R
In graduate school, I had to code up my bootstrapping methods for linear models myself. But, I recently discovered the “boot” library in R that certainly makes getting bootstrapped confidence intervals quick and easy in R. Here’s a simple, generic example with 10,000 replicates.
library(boot) func = function(data,idx){ coef(lm(y ~ X1 + X2 + X2, data[idx])) } B = boot(data_joined,func,R=10000) boot.ci(B,index=1,type="perc") # intercept ci boot.ci(B,index=2,type="perc") # X1 ci boot.ci(B,index=3,type="perc") # X2 ci boot.ci(B,index=4,type="perc") # X2 ci