# Multiple R-squared from bootstrap in R

I am fairly new to R and am having issues with my bootstrapped linear model. I'm using non-parametric case re-sampling to account for some skewed variables. Here is what I have done so far:

library(car)
library(carData)
set.seef(214)
mod1 <- lm(a~b+c+d+e)
mod1_boot <- Boot(mod1, R=1000, f=coef, method="case")
Confint (mod1_boot)


Then I use the average of individual predictors 95CIs to get a coefficient estimate. My question is how to find the CIs for the multiple R-squared, so I can assess the fit of the model. I suspect it is by re-writing the "f" (function) in the Boot model? apologies if this is a super elementary question, any input would be much appreciated. Thanks!

Not so easy with Boot which is a wrapper around the functions in library boot

We first create a function to extract coefficients and rsq:

fit_func = function(data,ind){
model = lm(mpg~cyl+disp+hp,data=data[ind,])
c(coef(model),rsq = summary(model)$r.squared) }  Then we call boot on mtcars: library(boot) B = boot(mtcars,R=999,statistic=fit_func)  The bootstrap results are under: head(B$t)
[,1]      [,2]         [,3]         [,4]      [,5]
[1,] 30.54030 -0.190894 -0.013044469 -0.049631250 0.7544081
[2,] 38.70884 -2.466009 -0.002938124 -0.012823860 0.8235995
[3,] 38.09804 -1.808732 -0.021593248 -0.006439406 0.8368061
[4,] 32.64324 -1.031982 -0.015882272 -0.016905832 0.7531038
[5,] 37.48415 -1.868353 -0.025565559  0.003352453 0.8451436
[6,] 33.91880 -1.110828 -0.021153522 -0.015057623 0.7465940


The colnames are gone, but they correspond to your coefficients and the last column is r-squared. To get a confidence interval for example on the 2nd column, cyl, do

boot.ci(B,index=2,type="perc")
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL :
boot.ci(boot.out = B, type = "perc", index = 2)

Intervals :
Level     Percentile
95%   (-2.457, -0.021 )
Calculations and Intervals on Original Scale


You can do this for rsq:

boot.ci(B,index=5,type="perc")
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL :
boot.ci(boot.out = B, type = "perc", index = 5)

Intervals :
Level     Percentile
95%   ( 0.6851,  0.8735 )
Calculations and Intervals on Original Scale


Perhaps like this using a function for rsquared from the MuMin package. There is likely a better way to do this but this works for me!

library(MuMin)
mod1_boot <- Boot(mod1, R=1000, f=MuMIn::r.squaredGLMM, method="case")
Confint (mod1_boot)