3.3 Describing Covariances

In the previous section we looked at the means and variances. Because these are repeated measures, we can also look at covariances and correlations over time. A simple covariance and correlation matrix of the verbal scores across grades can be produced using the cov() and cor() function.

cov(wiscwide[,c("verb1","verb2","verb4","verb6")], use="complete.obs")
##          verb1    verb2    verb4     verb6
## verb1 33.72932 25.46388 30.88886  40.51478
## verb2 25.46388 37.28784 33.81957  47.40488
## verb4 30.88886 33.81957 53.58070  62.25489
## verb6 40.51478 47.40488 62.25489 113.74332
cor(wiscwide[,c("verb1","verb2","verb4","verb6")], use="complete.obs")
##           verb1     verb2     verb4     verb6
## verb1 1.0000000 0.7180209 0.7265974 0.6541040
## verb2 0.7180209 1.0000000 0.7566242 0.7279080
## verb4 0.7265974 0.7566242 1.0000000 0.7974552
## verb6 0.6541040 0.7279080 0.7974552 1.0000000

A plot corresponding to the correlation matrix can be obtained in a number of different ways. First, using the pairs() function from base R.

pairs(wiscwide[,c("verb1","verb2","verb4","verb6")])

There is also a pairs.panel() function in the psych package. Here we see a LOESS smoothed fit line in red.

psych::pairs.panels(wiscwide[,c("verb1","verb2","verb4","verb6")])

Finally, thescatterplotMatrix() from the car (Fox and Weisberg 2019) package can be used to create scatterplot matrices with confidence bands around the line of best fit.

car::scatterplotMatrix(~ verb1 + verb2 + verb4 + verb6, data=wiscwide)

Each of these functions can be customized with additional features. Those interested in specifics should consult the help documentation for each function (e.g. ?car::scatterplotMatrix). It is also worth noting the default behavior of these functions is to provide automatic, data-based ranges for each pair of variables separately.

References

Fox, John, and Sanford Weisberg. 2019. An R Companion to Applied Regression. Third. Thousand Oaks CA: Sage. https://socialsciences.mcmaster.ca/jfox/Books/Companion/.