In an earlier blog post I provided R code for a CI of a difference in R square for dependent and non-dependent correlations. This was based on a paper by Zou (2007). That paper also provides a method for calculating the CI of a difference in independent R square coefficients based on the limits of the CI for a single R square coefficient.

The following function implements this method in R. It requires either MBESS and gsl packages to be installed (for the preferred method based on the Lee (1971) CI) or psychometric for an approximation provided by Olkin and Finn (1995).

I have now verified the code based on the example in Zou (2007). This contains an error in which the R values for the regression are reported as R^2 in the text, but correct in the example.

R2.diff.ind.ci <- function(rsq1, rsq2, n1, n2=n1, k1, k2=k1, conf.level = 0.95, method='LeeZou', Random.Predictors=TRUE) {
# Olkin Finn approximation for comparison only the Lee (1971) approach for input into the Zou (2007) equation is preferred
if (method=='LeeZou') {
require(gsl)
require(MBESS)
L1 <- ci.R2(R2=rsq1, N=n1, K=k1, conf.level=conf.level, Random.Predictors=TRUE)[]
U1 <- ci.R2(R2=rsq1, N=n1, K=k1, conf.level=conf.level, Random.Predictors=TRUE)[]
L2 <- ci.R2(R2=rsq2, N=n2, K=k2, conf.level=conf.level, Random.Predictors=TRUE)[]
U2 <- ci.R2(R2=rsq2, N=n2, K=k2, conf.level=conf.level, Random.Predictors=TRUE)[]
}
if (method=='OlkinFinnZou') {
require(psychometric)
L1 <- CI.Rsq(rsq1, n1, k1, level = 0.95)[]
U1 <- CI.Rsq(rsq1, n1, k1, level = 0.95)[]
L2 <- CI.Rsq(rsq2, n2, k2, level = 0.95)[]
U2 <- CI.Rsq(rsq2, n2, k2, level = 0.95)[]
}

lower <- rsq1 - rsq2 - ((rsq1 - L1)^2 + (U2 - rsq2)^2)^0.5
upper <- rsq1 - rsq2 + ((U1 - rsq1)^2 + (rsq2 - L2)^2)^0.5
output <- list('CI for R square 1' = c(L1, rsq1, U1), 'CI for R square 2' = c(L2, rsq2, U2), 'Confidence level' = conf.level,
'CI for different in R square:' = c(lower, rsq1 - rsq2, upper))
return(output)
} 

To use the function the input required is R square, sample size (n) and parameters (k) for each model being compared. Using the values in Zou (2007)’s example 4:

rsq1 <- .522^2
n1 <-  200
k1 <- 4

rsq2 <- .452^2
n2 <- 300
k2 <- 4

R2.diff.ind.ci(rsq1=rsq1, rsq2=rsq2, n1=n1, n2=n2, k1=k1, k2=k2, conf.level = 0.95, Random.Predictors=TRUE, method='LeeZou')
## Loading required package: gsl
## Loading required package: MBESS
## $CI for R square 1 ##  0.1582343 0.2724840 0.3683474 ## ##$CI for R square 2
##  0.1190193 0.2043040 0.2807469
##
## $Confidence level ##  0.95 ## ##$CI for different in R square:
##  -0.06928456  0.06818000  0.19648929

Or with the default values:

R2.diff.ind.ci(rsq1=rsq1, rsq2=rsq2, n1=n1, n2=n2, k1=k1, k2=k2)
## $CI for R square 1 ##  0.1582343 0.2724840 0.3683474 ## ##$CI for R square 2
##  0.1190193 0.2043040 0.2807469
##
## $Confidence level ##  0.95 ## ##$CI for different in R square:
##  -0.06928456  0.06818000  0.19648929