# Bootstrap 95% CI for R-Squared library(boot) # function to obtain R-Squared from the data rsq <- function(formula, data, indices) { d <- data[indices,] # allows boot to select sample fit <- lm(formula, data=d) return(coef(fit)) } # bootstrapping with 1000 replications results <- boot(data=mtcars, statistic=rsq, R=1000, formula=mpg~wt+disp) # get 95% confidence interval boot.ci(results, type="bca") Say you run this bootstrap and get 1000 estimates of the intercept, wt and disp variables and so then you want to put all estimates into the data frame.
dataframe = data.frame(results$t) That will do it but how do you code it to make sure that the column names get the right variable names? I did it that way and it makes column names 'Var1' 'Var2' and 'Var3' but I would wish for them to be 'Intercept' 'wt' and 'weight' and I know I can change them to this; I am wondering how to automate it to make sure the columns get the right names from boot.
names(dataframe) <- names(results$t0)tis a matrix with no names attribute, whilet0i.e. the one returned from 'rsq` have thenamesand you can assign the names based on that