Tutorials › Exam PA - Predictive Analytics › Scatterplot Matrices for Many Numeric Variables

Exam PA · Visualization and Anomaly Detection · Tutorial 154 of 966

Scatterplot Matrices for Many Numeric Variables

Use scatterplot matrices to survey many numeric-variable relationships efficiently, then identify which panels merit closer inspection.

Beginner 10 min read

What You'll Learn

  • Build a scatterplot matrix in R using selected numeric variables.
  • Distinguish unique variable pairs from their repeated mirror panels.
  • Read off-diagonal panels to screen for curvature, clusters, and unusual observations.
  • Use diagonal panels and variable selection to make a matrix easier to interpret.
  • Recognize when visually similar panels suggest redundant information without treating the plot as proof.

Why Use a Scatterplot Matrix?

A scatterplot is useful for examining the relationship between two numeric variables, but a data set may contain several candidate predictors. Inspecting every pair one at a time can make it easy to overlook a pattern or spend time on redundant plots. A scatterplot matrix arranges the pairwise scatterplots in a grid, giving a compact visual screen of the relationships among a selected set of numeric variables.

Each off-diagonal panel displays one variable on the horizontal axis and another on the vertical axis. The diagonal panels are typically used for each variable’s own distribution, often with a histogram. The matrix is a screening tool: it helps identify relationships that deserve closer examination, but it does not establish causation or replace checks of data quality and model assumptions. This use of visualization is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Definition: For \(p\) selected numeric variables, a scatterplot matrix is a \(p \times p\) grid. Each off-diagonal cell shows a scatterplot for a pair of different variables; diagonal cells show the individual variables’ distributions or are left blank. Because the same pair appears in two mirrored cells, the matrix contains \(p(p-1)/2\) unique variable pairs and \(p(p-1)\) off-diagonal cells.

Building and Reading the Matrix in R

In base R, the function pairs() creates a scatterplot matrix. Select the numeric columns that address the question at hand rather than passing every column in a data frame without inspection. Identifiers, dates stored as numbers, and numeric codes for categories usually do not belong in the matrix: their numerical appearance does not make the spacing between values meaningful.

For example, if a data frame named portfolio has numeric columns exposure, claim_cost, claim_count, and risk_score, a basic matrix can be created with: pairs(portfolio[, c("exposure", "claim_cost", "claim_count", "risk_score")]). The selected column order determines the panel order. The diagonal contains each variable paired with itself, so it is not another relationship between distinct variables.

To read a panel, first check its axis labels. In row \(j\), column \(k\), the horizontal axis corresponds to the variable in column \(k\), and the vertical axis to the variable in row \(j\). The mirrored panel reverses those axes. Then look for broad features: a curved rather than straight pattern, separate clumps of points, a point isolated from the rest, or a similar pattern repeated across several panels. A matrix is often crowded, so an initial screen should lead to a smaller number of focused plots where the axes and observations can be examined carefully.

Worked Example: Screening Four Hypothetical Portfolio Variables

A hypothetical analyst has six complete records and wants to screen four numeric variables: exposure units, annual claim cost in thousands of dollars, annual claim count, and a numeric risk score. The records are:

RecordExposureClaim cost ($000)Claim countRisk score
11206
22415
33604
44823
551012
661231

Step 1: Count the distinct comparisons. There are \(p=4\) variables, so the matrix has \(4 \times 4=16\) cells. Four are diagonal cells. The remaining \(4(4-1)=12\) cells are scatterplots, representing \(4(4-1)/2=6\) unique pairs.

Step 2: Create the plot. If the table is stored as portfolio, the R command is pairs(portfolio[, c("Exposure", "Claim cost", "Claim count", "Risk score")]). The data are complete, so all six records can appear in every pairwise panel.

Step 3: Describe the patterns without overclaiming. Claim cost increases by 2 thousand dollars whenever exposure increases by 1 unit. Thus those points lie exactly on an increasing straight line in the exposure-versus-cost panel. Risk score decreases by 1 whenever exposure increases by 1, so exposure and risk score also form a straight-line pattern, but in the decreasing direction. Claim cost and risk score have the same decreasing straight-line pattern because claim cost is exactly twice exposure in these records.

Claim count does not follow an exact straight-line pattern with exposure: as exposure rises from 1 to 6, counts are 0, 1, 0, 2, 1, and 3. The matrix therefore flags a visibly different relationship for further inspection. The six-record data set is intentionally small; these patterns describe only the listed records and are not evidence that the same relationships hold in a broader population.

Check. The count of six unique pairs agrees with the six possible comparisons: exposure with each of the other three variables, then claim cost with each remaining variable, then claim count with risk score. The common mistake of counting all 12 off-diagonal panels as distinct comparisons would count every pair twice.

Why the Pair Count Has a Factor of Two

The number of unique pairs follows by choosing two different variables from \(p\) candidates. There are \(p\) choices for the first variable and \(p-1\) for the second, giving \(p(p-1)\) ordered choices. Each unordered pair, such as exposure and cost, is counted twice in that total: once with exposure first and once with cost first. Dividing by two gives the number of unique pairs.

$$ \text{Unique pairs}=\frac{p(p-1)}{2}, \qquad \text{off-diagonal cells}=p(p-1) $$

This count is useful before plotting: it indicates how much visual material the matrix will contain. For example, a matrix with eight numeric variables has \(8 \times 7 / 2=28\) unique pairs, displayed across 56 off-diagonal cells. The duplication is not a mistake; it makes each variable appear once as a horizontal axis and once as a vertical axis.

What to Screen For

A scatterplot matrix can help flag several kinds of structure at once. A curved band suggests that a straight-line summary may not capture the visible relationship. Distinct clumps may indicate subgroups worth identifying and investigating. A point far from the rest in one panel may be unusual for that particular pair of variables; it may not be unusual in every other panel. Similar-looking patterns across multiple panels can suggest that some variables convey overlapping information, but visual resemblance alone does not prove that two variables are interchangeable.

These observations are leads, not final diagnoses. Return to the relevant pair in a larger scatterplot to check axis scales, point overlap, and whether the apparent feature is supported by more than one observation. Use the labels and context to determine what an unusual point represents before deciding whether it is an error or a plausible record.

The diagonal panels have a different role. A histogram on the diagonal shows each variable’s marginal distribution, not its relationship with another variable. It can help explain why a pairwise panel has a dense mass of points or a few values spread far from the rest, but it cannot show which observations occur together across two variables.

Worked Example: Following Up a Possible Cluster and an Unusual Pair

Suppose an analyst screens four numeric measurements from a hypothetical fleet: vehicle age, monthly distance, repair cost, and sensor alerts. The matrix shows two clumps in the age-versus-distance panel. It also shows one observation separated from the main cloud in the repair-cost-versus-sensor-alerts panel. The analyst must decide what to inspect next, without assuming either feature is an error.

Step 1: Locate each feature by its variables. The two-clump feature concerns vehicle age and monthly distance. The isolated point concerns repair cost and sensor alerts. Because the mirrored cells display the same observations with axes swapped, these are two unique pairwise findings, not four separate findings.

Step 2: Identify the rows involved. The analyst returns to the data and determines which records lie in each clump and which record produced the separated point. The matrix itself does not reveal whether the two clumps correspond to a meaningful fleet subgroup or to a data-processing issue.

Step 3: Check the relevant context and plot at larger scale. The analyst examines vehicle age and distance for the clump records, then repair cost and sensor alerts for the isolated record. If the isolated point is a valid high-cost repair, deleting it merely because it is visually unusual would discard potentially important information. If a recorded value is demonstrably incorrect, any correction or exclusion requires a documented reason.

Conclusion and check. The matrix has served as a screen by directing attention to two specific pairs. It has not established why the points group or why one record is isolated. The common mistake this method avoids is declaring an observation an error solely because it looks unusual in one panel.

Making the Matrix More Useful

Clarity depends on choosing variables and plotting settings that match the question. Base R allows points to be colored by a known group, which can help check whether a visual cluster aligns with that group. For example, if portfolio also contains a categorical segment column, a color vector can be made with ifelse(portfolio$segment == "A", "steelblue", "darkorange"), then supplied as col in pairs(). The grouping variable should be used to distinguish points, not treated as a numeric axis merely because it has been coded with numbers.

When adding color, keep the mapping consistent across all panels and explain what each color represents. If many records overlap, transparency can reduce the visual dominance of dense areas; using pch = 19 with a transparent color is one option in base R. These choices do not add information to the underlying records, but can make patterns easier to see. For a large number of variables, select a focused subset before plotting rather than trying to interpret an unreadable grid.

Be explicit about which records are included. If the analysis uses only rows complete on the selected variables, state that choice and the resulting record count. A matrix based on a reduced set of rows may tell a different visual story from one based on all records; the plotted population should therefore be clear. Do not treat the diagonal histograms or a visual pattern as a substitute for checking how the data were collected and prepared.

Worked Example: Planning a Matrix for Five Candidate Measurements

A hypothetical analyst has five numeric measurements available for screening: account tenure, annual premium, annual claim count, average repair severity, and a numeric risk index. The analyst also has a categorical region label and a unique account number. The goal is to survey numeric pairwise patterns and see whether any visible structure aligns with region.

Step 1: Choose the variables. Use the five measurements as axes. Exclude the account number because it identifies records rather than measuring a meaningful quantity. Keep region as a grouping label, not as a numeric axis.

Step 2: Work out the size of the display. Here \(p=5\), so there are \(5 \times 5=25\) cells, five diagonal distributions, and \(5(5-1)=20\) off-diagonal cells. These 20 cells represent \(5(5-1)/2=10\) distinct pairs. This count helps set expectations: the plot will repeat every distinct pair in a mirrored panel.

Step 3: Construct and annotate the plot. With a data frame named accounts, the selected matrix can be created with pairs(accounts[, c("tenure", "premium", "claim_count", "repair_severity", "risk_index")], col = ifelse(accounts$region == "North", "steelblue", "darkorange"), pch = 19). A legend should identify the regions represented by the colors; if more than two regions are present, assign a distinct, consistent color to each.

Step 4: Screen and prioritize. Scan the diagonal to understand each measurement’s marginal spread, then inspect the ten unique pairings for curvature, clumps, or isolated points. If a clump appears in premium versus repair severity and its colors are mostly one region, record that as a possible region-related pattern and inspect that pair more closely. Do not conclude from color alone that region caused the pattern.

Check. Ten distinct pairs produce twenty off-diagonal panels, not ten. The matrix is correct only if each of the five chosen variables is represented on both axes and the categorical label remains a visual grouping variable.

Common Mistakes and a Practical Routine

The most frequent reading error is to count mirrored panels as separate relationships. Another is to infer a relationship from a diagonal histogram, which displays just one variable. A third is to include numeric identifiers or arbitrary codes and then interpret their spacing as meaningful. Finally, a visually isolated point should be described in relation to the pair of axes where it appears; it is not automatically a data error or a multivariable outlier.

A disciplined screen can be organized as follows:

1
Select meaningful numeric variables.
Exclude identifiers and numeric category codes; use a manageable set tied to the question.
2
Know what is plotted.
Count the unique pairs and confirm the selected records and axis labels.
3
Screen consistently.
Look across unique panels for curvature, clumps, isolated observations, and repeated patterns.
4
Follow up, do not overstate.
Return to the records and inspect promising pairs at larger scale before drawing a conclusion.

The main value of a scatterplot matrix is efficient comparison: it places many pairwise views in one organized display. Its main limitation is that a compact grid can hide detail. Use it to decide where to look next, and report what the panels show in specific, appropriately cautious language.

Check Your Understanding

For each problem, count unique pairs separately from displayed off-diagonal cells where relevant.

  1. A matrix contains six selected numeric variables. How many unique pairs and how many off-diagonal cells does it display? (Answer: 15 unique pairs and 30 off-diagonal cells.)
  2. A data frame includes numeric annual premium, claim count, and account ID. Which variables belong as axes in a relationship-screening matrix, and why? (Answer: Annual premium and claim count; account ID is an identifier, not a meaningful numeric measurement.)
  3. A four-variable matrix has a curved pattern in one panel and its mirrored panel. How many distinct curved pairwise relationships have been flagged? (Answer: One distinct pairwise relationship.)
  4. In a five-variable matrix, two clumps appear in the panel for account tenure versus repair severity, and most points in one clump share a color for region. What is a sound next step? (Answer: Identify the records and inspect the tenure-versus-severity pair more closely; treat region alignment as a possible pattern, not proof of causation.)
  5. An analyst says an observation is erroneous because it is isolated in the claim-count versus premium panel. What is the correction? (Answer: Treat it as a potentially unusual observation for that pair, then check the record and context; isolation alone does not establish an error.)
Clinical Biostats