General code for graphs in “Graphical Views of Suppression and Multicollinearity in Multiple Linear Regression.”  (The American Statistician, 59, 127-136.)

 

1)  You will need this function to make the calculations for the b’s, R2, standard errors of

the b’s, etc.  It calculates the limits that r12 can go between, given ry1 and ry2.

 

> F.limcor

function(r1, r2)

{

            ll <- r1 * r2 - sqrt((1 - r1^2) * (1 - r2^2))

            ul <- r1 * r2 + sqrt((1 - r1^2) * (1 - r2^2))

            print(ll, digits = 4)

            print(ul, digits = 4)

            Ll <<- ll

            Ul <<- ul

}

 

2) This is the function that makes all the calculations needed for the graphs of the b’s, R2, and standard errors of the b’s.  It produces a matrix holding

1) values of r12 between the limits given by F.limcor;

2)  values of b1 at the above values of r12;

3)  values of b2 at those same values;

4) values of the derivative of b1 at the above values of r12;

5) values of the derivative of b2 at the above values of r12;

6)  R2 at those values;

7) the standard errors of the b’s at those values;

8) the t-stat of b1 at those values;

9) the t-stat of b2 at those values;

10) a sequence actually just the same as 1) for the purpose of creating the x-axis;

11) a sequence of values between –1 and the maximum value of b1 for the purpose

            of creating the y-axis.

 

> F.betcal

function(v1, v2, lr = 101, mn = 25)

{

            #v1 and v2 are the correlations or vectors of correlations

            #from which we will get the betas and their

            #se's and t's and r sq's

            # lr is the number of points at which we want to calculate

            # mn is the number of subjects that the

            #t-statistic is based on

            F.limcor(v1, v2)

            ll <- round(Ll, digits = 2)

            ul <- round(Ul, digits = 2)

            bnew <- (ul - ll)/(lr - 1)

            rho1 <- seq(ll, ul, by = bnew)

            print(rho1)

            vec1 <- c(rep(v1, length(rho1)))

            vec2 <- c(rep(v2, length(rho1)))

            be1 <- c(rep(0, length(vec1)))

            be2 <- c(rep(0, length(vec1)))

            be1pr <- c(rep(0, length(vec1)))

            be2pr <- c(rep(0, length(vec1)))

            rsq <- c(rep(0, length(vec1)))

            sebe <- c(rep(0, length(vec1)))

            tstat1 <- c(rep(0, length(vec1)))

            tstat2 <- c(rep(0, length(vec1)))

            for(i in 1:length(vec1)) {

                        be1[i] <- (vec1[i] - vec2[i] * rho1[i])/(1 - rho1[

                                    i]^2)

                        be2[i] <- (vec2[i] - vec1[i] * rho1[i])/(1 - rho1[

                                    i]^2)

                        be1pr[i] <- (1/(1 - rho1[i]^2)^2) * (vec1[i] * rho1[

                                    i] * 2 - vec2[i] * (1 + rho1[i]^2))

                        be2pr[i] <- (1/(1 - rho1[i]^2)^2) * (vec2[i] * rho1[

                                    i] * 2 - vec1[i] * (1 + rho1[i]^2))

                        rsq[i] <- vec1[i]^2 + (vec2[i] - vec1[i] * rho1[i])^

                                    2/(1 - rho1[i]^2)

                        sebe[i] <- (sqrt((1 - rsq[i])/(mn - 3)) * sqrt(1/(

                                    1 - rho1[i]^2)))

                        tstat1[i] <- be1[i]/sebe[i]

                        tstat2[i] <- be2[i]/sebe[i]

            }

            lo <- seq(Ll, Ul, length = lr)

            lo1 <- seq(-1, max(be1), length = lr)

            Bp <<- cbind(rho1, be1, be2, be1pr, be2pr, rsq, sebe, tstat1,

                        tstat2, lo, lo1)

            invisible()

}

>

 

3)  The following will produce a graph, based on the two correlations of the independent variables with the dependent variable, with all the annotations that do not involve

subscripts or Greek letters.  (Those can be added by the user, using text boxes.)

 

F.betgraph

function(look = 1, look1 = 1, h1 = 0, v1 = 0, r1 = 1, r2 = 1, x1 = 1,

            y1 = 1, y2 = 1, y3 = 1)

{

            #look and look1 set x and y limits respectively

            #use Bpl[,10],Bpl[,11]

            #h1 and v1 are usually intended for the axes

            #r1 and r2 are for the larger and smaller

            # correlations, resp.

            #x1 and y1,y2,y3 are for the rho,

            #beta1,beta2,rsquared

            plot(look, look1, type = "n", cex = 0.7, xlab = c("     "),

                        ylab = c("            "))

            abline(v = v1)

            abline(h = h1)

            abline(v = (r2/r1), lty = 7)

            abline(v = ((2 * r1 * r2)/(r1^2 + r2^2)), lty = 7)

            text(-0.15, -0.45, c("Region I"), cex = 0.7)

            text(-0.15, -0.55, c("Enhancement"), cex = 0.7)

            text((r2/r1)/2, -0.45, c("Region II"), cex = 0.7)

            text((r2/r1)/2, -0.55, c("Redundancy"), cex = 0.7)

            text(((2 * r1 * r2)/(r1^2 + r2^2) + r2/r1)/2, -0.45, c(

                        "Region III"), cex = 0.7)

            text(((2 * r1 * r2)/(r1^2 + r2^2) + r2/r1)/2, -0.55, c(

                        "Suppression"), cex = 0.7)

            text((2 * r1 * r2)/(r1^2 + r2^2) + 0.1, -0.45, c("Region IV"),

                        cex = 0.7)

            text((2 * r1 * r2)/(r1^2 + r2^2) + 0.1, -0.55, c("Enhancement"),

                        cex = 0.7)

            legend(-0.4, -0.65, legend = c("  ", "   ", "  "), lty = c(

                        1, 6, 3), cex = 0.7)

            lines(x1, y1, lty = 6)

            lines(x1, y2, lty = 3)

            lines(x1, y3, lty = 0)

            points(Bp[1, 10], 0, pch = "[", cex = 1.5)

            points(Bp[100, 10], 0, pch = "]", cex = 1.5)

            points(r2/r1, 0, pch = 15)

            points((2 * r1 * r2)/(r1^2 + r2^2), 0, pch = 15)

            points(0, 0)

}

 

4)  Once one has the function F.betgraph, one can make the graph more quickly using the following function:  (one must, however, have the matrix Bp given by F.betcal for the

given correlations).

 

> F.betshort

function(r1 = 0, r2 = 0)

{

            F.betgraph(Bp[, 10], Bp[, 11], 0, 0, r1, r2, Bp[, 1], Bp[,

                        2], Bp[, 3], Bp[, 6])

}