Tutorials › Exam PA - Predictive Analytics › Reading a Predictor Correlation Matrix

Exam PA · Screening and Dimension Reduction · Tutorial 265 of 966

Reading a Predictor Correlation Matrix

Learn to construct and read a numeric-predictor correlation matrix in R without treating a large correlation as an automatic reason to remove a predictor.

Intermediate 11 min read

What You'll Learn

  • Select numeric predictors appropriately before constructing a correlation matrix in R.
  • Read matrix symmetry, diagonal values, signs, and magnitudes.
  • Identify highly correlated pairs as candidates for further review, not automatic removal.
  • Recognize how nonlinear patterns can be missed by a correlation matrix.
  • Check how missing-data handling changes the observations behind each pairwise value.

Why Read a Predictor Correlation Matrix?

A data set may contain several numeric predictors that record overlapping information. A matrix of pairwise correlations provides a compact way to spot relationships worth investigating: a strong positive association, for example, or a strong negative one. It is a screening summary, not a decision rule. A large correlation does not establish that either predictor is unnecessary, and a small one does not establish that the predictors are unrelated in every useful sense.

The matrix is most useful when its entries are interpreted alongside the variables’ definitions, units, data quality, and intended model. This tutorial focuses on constructing and inspecting the matrix in R, including what its signs and magnitudes can and cannot tell you.

Definition: A predictor correlation matrix is a square table whose entry in row \(j\) and column \(k\) is the correlation between numeric predictors \(X_j\) and \(X_k\), calculated on the observations specified by the missing-data rule. For a standard Pearson correlation matrix, the diagonal entries are 1 when the corresponding predictor has nonzero variation, the matrix is symmetric, and each defined off-diagonal entry lies between -1 and 1.

Choose the Columns Before You Calculate

In R, first identify which columns are appropriate numeric predictors. Do not include a response variable if the goal is to inspect redundancy among predictors. Also exclude identifiers such as policy numbers or customer IDs: they may be stored as numbers, but the numerical differences between ID values usually have no substantive meaning. A categorical variable represented by integer codes is not automatically a numeric predictor either; its codes may simply label categories.

After deliberately selecting the predictor columns, a typical calculation is cor(numeric_predictors, use = "complete.obs"). The cor function returns a matrix, with variable names on its rows and columns. The use = "complete.obs" option uses only rows that have observed values for every selected predictor. Another option, use = "pairwise.complete.obs", uses the rows observed for each pair separately. These choices can produce different results and should be reported or checked rather than left implicit.

A constant predictor has no variation, so its correlation with another variable is undefined: its standard deviation is zero, making the usual correlation denominator zero. In R this commonly appears as NA. Investigate such columns rather than interpreting the missing entry as a weak relationship. They may reflect a data problem, an unexpected subset, or a predictor that provides no variation in the current data.

1
Select deliberately.
Choose numeric predictors with meaningful numerical scales. Exclude identifiers, the response when screening predictor redundancy, and categorical codes that are labels rather than measurements.
2
Check data coverage.
Look for missing values, constant columns, and small effective sample sizes. Decide whether rows must be complete across all selected predictors or may be used pair by pair.
3
Read the matrix as a screen.
Check the sign and magnitude of off-diagonal entries, then investigate plausible redundant pairs in context. Do not remove a variable solely because an entry is large.

What the Entries Summarize

For two observed numeric variables \(X\) and \(Y\), the sample Pearson correlation is the covariance divided by the product of the sample standard deviations. Equivalently, it is the sum of products of the centered observations divided by the square root of the two centered sums of squares:

$$ r_{XY}= \frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\left[\sum_{i=1}^{n}(x_i-\bar{x})^2\right] \left[\sum_{i=1}^{n}(y_i-\bar{y})^2\right]}} $$

Here \(n\) is the number of paired observations used, and \(\bar{x}\) and \(\bar{y}\) are their sample means. This expression applies when both variables have nonzero sample variation and the pairs are valid observations. It describes linear association in the paired data; it does not by itself describe causation or every possible form of dependence.

The reason for the formula is that centering removes each variable’s location, while dividing by its standard deviation puts the variables on a common scale. The correlation is the average covariance of these standardized values (with the usual sample covariance and standard deviation conventions). Thus a change of measurement units, such as dollars to thousands of dollars, does not change the correlation. Reversing the direction of one variable changes the sign.

An entry near 1 indicates a strong positive linear association in the observations used; an entry near -1 indicates a strong negative linear association. An entry near 0 indicates little linear association in those observations, but does not rule out a curved or otherwise nonlinear relationship. The sign is about direction, not strength: compare absolute magnitudes when screening for strong linear association.

Worked Example: Reading Positive and Negative Entries

A hypothetical analyst compares three numeric measurements for four records. Let \(X_1=(1,2,3,4)\), \(X_2=(10,20,30,40)\), and \(X_3=(4,3,2,1)\). Construct the correlation matrix and interpret the two off-diagonal relationships. Use the standard Pearson sample correlation and no rounding until the final result.

Method. Calculate each pairwise correlation from the centered values, then arrange the results symmetrically. For \(X_1\), the mean is \((1+2+3+4)/4=2.5\), and the centered values are \((-1.5,-0.5,0.5,1.5)\). Their squared values sum to \(2.25+0.25+0.25+2.25=5\).

For \(X_2\), the mean is 25, its centered values are \((-15,-5,5,15)\), and its centered sum of squares is \(225+25+25+225=500\). The cross-product sum with \(X_1\) is \(22.5+2.5+2.5+22.5=50\). Therefore \(r_{12}=50/\sqrt{5(500)}=50/50=1\).

For \(X_3\), the mean is 2.5 and its centered values are \((1.5,0.5,-0.5,-1.5)\); its centered sum of squares is 5. The cross-product sum with \(X_1\) is \(-2.25-0.25-0.25-2.25=-5\). Thus \(r_{13}=-5/\sqrt{5(5)}=-5/5=-1\). Since \(X_2=10X_1\) and \(X_3=5-X_1\), \(X_2\) and \(X_3\) also have correlation \(-1\).

R code for the calculation is cor(data.frame(X1 = c(1,2,3,4), X2 = c(10,20,30,40), X3 = c(4,3,2,1))). The resulting matrix has 1 on the diagonal, 1 for the \(X_1,X_2\) pair, and -1 for the \(X_1,X_3\) and \(X_2,X_3\) pairs. Its symmetry follows because swapping the two variables does not change the correlation.

Check and interpretation. The entries agree with the exact linear relationships in the data. The positive sign for \(X_1,X_2\) means they increase together; the negative sign for \(X_1,X_3\) means one decreases as the other increases. The common mistake this avoids is reading a negative correlation as weak: its strength is represented by its absolute magnitude, which here is 1.

A Small Correlation Can Miss a Pattern

A correlation matrix compresses each pair of variables to a measure of linear association. As a result, a value near zero is not evidence that no relationship exists. A curved pattern can be systematic even when positive and negative centered products cancel in the correlation calculation. Conversely, a strong pairwise correlation is not proof that one variable should be discarded. A variable can carry distinct information for the model or have a different interpretation, measurement quality, or operational role.

Worked Example: Zero Correlation Despite a Deterministic Pattern

A hypothetical data set has \(X=(-2,-1,0,1,2)\), \(Z=3-2X\), and \(Q=X^2\). Use the correlation matrix to identify the linear relationship and explain the result for \(X\) and \(Q\).

Method. The values are \(Z=(7,5,3,1,-1)\) and \(Q=(4,1,0,1,4)\). The means are \(\bar{X}=0\), \(\bar{Z}=3\), and \(\bar{Q}=2\). The centered values are \(X=(-2,-1,0,1,2)\), \(Z-\bar{Z}=(4,2,0,-2,-4)\), and \(Q-\bar{Q}=(2,-1,-2,-1,2)\).

The cross-product sum for \(X,Z\) is \(-8-2+0-2-8=-20\). The centered sums of squares are 10 for \(X\) and 40 for \(Z\), so \(r_{XZ}=-20/\sqrt{10(40)}=-20/20=-1\). For \(X,Q\), the cross-products are \(-4,1,0,-1,4\), which sum to 0; hence \(r_{XQ}=0\). For \(Z,Q\), the cross-products are \(8,-2,0,2,-8\), which also sum to 0; hence \(r_{ZQ}=0\).

In R, these results can be checked with cor(data.frame(X = c(-2,-1,0,1,2), Z = c(7,5,3,1,-1), Q = c(4,1,0,1,4))). The matrix has \(r_{XZ}=-1\) and both correlations involving \(Q\) equal to 0.

Check and interpretation. \(Z\) is an exact decreasing linear transformation of \(X\), while \(Q\) is exactly determined by \(X\) through a curve. The zero entries do not mean that \(Q\) and \(X\) have no relationship; they mean the centered products cancel in this data set. This example avoids the mistake of treating a small correlation as proof of independence or lack of useful structure.

Missing Values Can Change the Matrix

With complete observations, every pairwise entry is calculated from the same rows. With pairwise-complete observations, each entry can use a different subset. The latter may preserve more data for individual entries, but the collection of correlations may not describe one common set of jointly observed records. Pairwise calculations can therefore be difficult to compare and can even produce a matrix that is not a valid positive-semidefinite correlation matrix.

Worked Example: Pairwise Correlations From Different Records

Consider six hypothetical records with three numeric predictors. Some measurements are missing:

RecordABC
111NA
222NA
31NA1
42NA2
5NA12
6NA21

Use pairwise-complete observations. For \(A,B\), the two available pairs are \((1,1)\) and \((2,2)\). Both variables have mean 1.5, their centered values are \((-0.5,0.5)\), the cross-product sum is \(0.5\), and each centered sum of squares is \(0.5\). Thus \(r_{AB}=0.5/\sqrt{0.5(0.5)}=1\). The \(A,C\) pairs are also \((1,1)\) and \((2,2)\), so \(r_{AC}=1\) by the same calculation.

For \(B,C\), the available pairs are \((1,2)\) and \((2,1)\). Their means are both 1.5. The centered values are \((-0.5,0.5)\) for \(B\) and \((0.5,-0.5)\) for \(C\). Their cross-product sum is \(-0.5\), and each centered sum of squares is \(0.5\), giving \(r_{BC}=-0.5/\sqrt{0.5(0.5)}=-1\). Each off-diagonal entry is based on only two records.

In R, enter the data as a data frame and use cor(data, use = "pairwise.complete.obs"). The off-diagonal results are \(r_{AB}=1\), \(r_{AC}=1\), and \(r_{BC}=-1\). The resulting matrix, in the order \(A,B,C\), is \(\begin{pmatrix}1&1&1\\1&1&-1\\1&-1&1\end{pmatrix}\). Its determinant is \(-4\), so it is not positive semidefinite. The conflicting pairwise relationships arise because no pair uses the same two records as another pair.

Check and interpretation. Pairwise deletion gives a value for every pair, but there are no records with all three predictors observed. A complete-observation calculation therefore has no jointly complete records from which to form this three-variable matrix. This example avoids the mistake of assuming that every pairwise-complete matrix represents correlations calculated on one common sample. Inspect the pair counts and missingness pattern before using such a matrix to support conclusions.

Common Interpretation Traps

  • Reading sign as strength. A correlation of -0.9 is a strong negative linear association, not a weak one. Compare absolute magnitudes to discuss strength.
  • Treating numeric codes as measurements. Suppose three categories are assigned codes 1, 2, and 3, and their recorded costs are 100, 200, and 300. The calculation cor(c(1,2,3), c(100,200,300)) gives 1. Reversing the arbitrary category codes to 3, 2, and 1 gives -1 for the same category-cost pattern. Neither result describes a meaningful numerical relationship among the category labels.
  • Reading a low value as no relationship. The worked quadratic example has zero linear correlations involving \(Q\), even though \(Q=X^2\) exactly. Inspect plots or use methods suitable for the relationship being investigated.
  • Removing a variable automatically. A high-magnitude pair is a reason to examine definitions, data quality, and model purpose. It is not, by itself, a sufficient reason to remove either predictor.
  • Ignoring sample size and missingness. The same-looking entry can have very different evidential value when one is based on many observations and another on only a few. Record how each value was calculated.
Key takeaway: A predictor correlation matrix is a useful first screen for pairwise linear association among numeric predictors. Interpret its signs and magnitudes in context, verify the variables and observations behind each entry, and treat possible redundancy as a question for further investigation—not as a verdict to remove a predictor. This treatment is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each question, focus on what the matrix supports and what it does not establish.

  1. A matrix entry for two numeric predictors is -0.84. What does the sign indicate, and what does the magnitude suggest about their linear association? (Answer: They have a negative linear association, and its magnitude suggests a strong association; the value alone does not establish that either predictor should be removed.)
  2. A data frame contains a numeric customer ID, a numeric claim frequency, and a factor for distribution channel. Which columns should ordinarily be excluded when constructing a matrix to screen numeric-predictor redundancy, and why? (Answer: Exclude the ID because it is an identifier, and do not treat the factor as a numeric measurement; include claim frequency only if it is a predictor rather than the response.)
  3. For \(X=(-1,0,1)\) and \(Y=(1,0,1)\), the correlation is zero. Does that show the variables are unrelated? (Answer: No. \(Y=X^2\) for these observations, so a deterministic curved relationship exists despite zero linear correlation.)
  4. Three pairwise-complete correlations are based on 12, 8, and 5 observations respectively. What should be checked before comparing or interpreting them? (Answer: Check which records contribute to each pair and report the pair-specific counts; the entries may describe different subsets.)
  5. A selected numeric predictor is constant in the modeling data. What should you expect from its correlation with another predictor, and what should you do? (Answer: Its correlation is undefined because its standard deviation is zero and may appear as NA; investigate the constant column and the data subset rather than interpreting NA as no association.)
Clinical Biostats