corvisualize {correlatio}R Documentation

Visualize the correlation coefficient geometrically.

Description

Visualize the correlation coefficient geometrically, i.e., use the angle between the linear vector that represents the predictor and the linear vector that represents the outcome, show where the dropping of the perpendicular lands on the linear vector that represents the predictor in the two-dimensional linear space, finally read b regression weight from the simple linear regression between predictor and outcome; or read the beta regression weight, in case the predictor and outcome have been scaled (mean = zero, standard deviation = one).

Usage

corvisualize(data = NULL, x = "x1", y = "x2", visualize = TRUE)

Arguments

data

A data.frame with two columns, which shall be correlated by Pearson's product-moment method.

x

A single character, i.e., the column name of the data.frame which shall be the predictor (independent variable) in the simple linear regression.

y

A single character, i.e., the column name of the data.frame which shall be the outcome (dependent variable) in the simple linear regression.

visualize

A single boolean value (default: TRUE), which determines whether the data shall be visualized.

Details

Any textbook on linear algebra and/or analytic geometry usually contains at least one numeric example and a geometric visualization of a correlation between two continuous variables. I want to express my gratitude to Dr. Johannes Andres (who taught statistics as well as multivariate statistics to psychology students, of which I was one).

Value

a list with results (name: res), and one graph as elements (name: anglePlot). res is a list with 13 objects:

  1. covMat Covariance matrix of predictor and outcome.

  2. covPredMat Covariance matrix of predictor and the predicted outcome, based on the simple linear regression estimates.

  3. corMat Correlation matrix of predictor and outcome.

  4. spreadMat Square root of the variance of the predictor and the variance of the outcome. If the angle is greater than 90 degrees, the spread of the predictor is multiplied by minus one.

  5. angle The angle between predictor and outcome: In R, compute: acos(cor(predictor,outcome))*180/pi.

  6. rsquared Explained variance of the outcome variable.

  7. errorVariance Difference between the variance of the outcome and the explained variance of the (predicted) outcome variable.

  8. errorSpread Square root of the error variance.

  9. observedSpread Square root of the variance of the outcome variable.

  10. yhatSpread Square root of the difference between outcome variance and variance of the predicted outcome. If the angle is greater than 90 degrees, yhatSpread is multiplied by minus one.

  11. bWeight The regression weight (slope) of the simple linear regression of the predictor and the outcome variable.

  12. betaWeight Same as bWeight, if the predictor and the outcome have both been scaled (mean = 0, standard deviation = 1).

  13. anglePlot Visualization of the regression weight, unless the function argument visualize has been set to FALSE.

Author(s)

Marcel Miché

References

Boyer CB (1949). “The invention of analytic geometry.” Scientific American, 180(1), 40–45.

Gniazdowski Z (2013). “Geometric interpretation of a correlation.” Zeszyty Naukowe Warszawskiej Wyższej Szkoły Informatyki.

Graffelman J (2013). “Linear-angle correlation plots: new graphs for revealing correlation structure.” Journal of Computational and Graphical Statistics, 22(1), 92–106.

Graffelman J, De Leeuw J (2023). “Improved approximation and visualization of the correlation matrix.” The American Statistician, 77(4), 432–442.

Examples

positiveCorDat <- data.frame(x1=c(5,9,3,6,2,9,3,7,2,8),
                      x2=c(2,6,7,8,3,5,5,8,3,9))
negativeCorDat <- data.frame(x1=c(5,9,3,6,2,9,3,7,2,8),
                      x2=c(5,7,9,2,5,5,8,1,9,8))
# Run corvisualize with positiveCorDat.
corvisualize(data=positiveCorDat, x="x1", y="x2", visualize=TRUE)
# Run corvisualize with negativeCorDat.
corvisualize(data=negativeCorDat, x="x1", y="x2", visualize=TRUE)

[Package correlatio version 0.2.1 Index]