I googled and searched on stats.stackexchange but I cannot find the formula to calculate a 95% confidence interval for an $R^2$ value for a linear regression. Can anyone provide it?
Even better, let’s say I had ran the linear regression below in R. How would I calculate a 95% confidence interval for the $R^2$ value using R code.
lm_mtcars <- lm(mpg ~ wt, mtcars)
Answer
You can always bootstrap it:
> library(boot)
> foo <- boot(mtcars,function(data,indices)
summary(lm(mpg~wt,data[indices,]))$r.squared,R=10000)
> foo$t0
[1] 0.7528328
> quantile(foo$t,c(0.025,0.975))
2.5% 97.5%
0.6303133 0.8584067
Carpenter & Bithell (2000, Statistics in Medicine) provide a readable introduction to bootstrapping confidence intervals, though not specifically focused on $R^2$.
Attribution
Source : Link , Question Author : luciano , Answer Author : Stephan Kolassa