Business Analytics & Data Science

B05 · Intermediate

Correlation Analysis

10 lessons

B05 · Module 4, lesson 1 · Lesson 8 of 10

Correlation matrices

Put every pair of measures in one table, read it as a map of what goes with what, spot measures that say the same thing, and test 28 correlations at once without being fooled by the false alarms that many tests produce: Bonferroni, Holm and the Benjamini–Hochberg false discovery rate.

About 80 minutes

Before you start

You will be able to

  • Construct a correlation matrix and its heatmap in Excel, with CORREL or the Analysis ToolPak’s Correlation tool, and read its structure: blocks, redundant measures and near-zero pairs.
  • Calculate the number of distinct pairs among m variables and explain why testing them all at α = 0.05 produces false alarms.
  • Apply the Bonferroni, Holm and Benjamini–Hochberg procedures to a set of p-values and explain what each controls: the family-wise error rate or the false discovery rate.
  • Recognise the limits of a matrix: pooled groups, nonlinear links, pairwise deletion and the impossibility of some combinations of correlations.
  • Use a matrix to choose follow-up questions rather than to report conclusions.

Review first

Fictional case A fictional coffee business founded by Ana Lim. It starts as a catering and barista-training service, opens its own cafés and an online shop for beans, and plans a canned cold brew.

The idea

Fictional case

By the end of December 2027 Ana has ten months of her cafés’ daily log: 306 days at Harbourside and 306 at Millbrook. She has looked at a few scatterplots one at a time, but she has eight daily measures that matter to her (the high temperature, rain, footfall, transactions, sales, the share of iced drinks, the barista hours rostered for the 7–11 a.m. peak and the average wait at the peak), and she wants to see everything that goes with everything before she decides what to investigate.

From pairs to a matrix

Eight measures make 8×7÷2=288 \times 7 \div 2 = 28 distinct pairs. A scatterplot matrix of all 28 is possible but cramped, and the pattern across 28 small plots is hard to hold in your head. A correlation matrix puts all the pairs in one square table: one row and one column for each variable, and in each cell the correlation of the row’s variable with the column’s. The table below is the Pearson matrix for the year, both cafés together.

Pearson correlations between the cafés’ daily measures, 1 March – 31 December 2027 (both cafés, 612 days; lower triangle)
1234567
2 Rain (in)0.05
3 Footfall0.25−0.14
4 Transactions0.21−0.120.98
5 Sales0.29−0.150.890.83
6 Iced share0.940.060.260.220.30
7 Peak barista hours0.230.030.920.930.750.24
8 Peak wait0.08−0.150.730.770.680.100.53

Columns are numbered as the rows: 1 High (°F), 2 Rain (in), 3 Footfall, 4 Transactions, 5 Sales, 6 Iced share, 7 Peak barista hours, 8 Peak wait. Every cell uses all 612 days.

Three features make a correlation matrix quick to read. The diagonal is all 1s, because every variable correlates perfectly with itself, so tables often leave it out. The matrix is symmetric, because the correlation of footfall with sales is the correlation of sales with footfall, so half of it is enough: here the lower triangle. And every cell is on the same scale, −1 to +1, whatever the variables’ units, so cells can be compared directly in a way that covariances can’t.

Reading the matrix

Read a matrix by looking for its structure before its single numbers. This one has three groups. The first is how busy the day was: footfall, transactions, sales, peak barista hours and peak wait correlate with each other at 0.53 to 0.98. The second is the weather’s effect on the menu: the high temperature and the iced share correlate at 0.94, the S-shaped curve of the nonlinear-and-restricted lesson. The third is rain, which correlates weakly and negatively with footfall, transactions, sales and peak wait (−0.12 to −0.15), and hardly at all with peak barista hours (0.03) or the high temperature (0.05).

Between the groups, the high temperature goes with the busy measures only modestly, at 0.21 to 0.29, and with the peak wait at only 0.08. A matrix like this is a summary of linear association; it says nothing about why. Some of the links the case was built with (footfall, transactions and sales form a chain; warm days bring more iced drinks), and some are side effects of how the cafés are run, as the next sections show.

Redundant measures

Footfall and transactions correlate at 0.98: on the year’s data, knowing one tells you almost everything about the other (r² = 0.96). Two such measures are redundant measures for most questions. Their correlations with everything else are nearly identical, so they are not two independent pieces of evidence that busy days have longer waits; they are one piece counted twice. When you choose which measures to carry into later analysis, keep the one closer to the question (transactions, if the question is about the till) and say why.

Peak barista hours correlate with footfall at 0.92 and with transactions at 0.93. That is not because baristas bring customers in: the case’s managers roster more baristas for the peak on days they expect to be busy, so the roster follows the expected crowd. In regression (B06) measures this closely related cause a problem called multicollinearity: their separate effects can’t be estimated well. Here it is enough to notice that the matrix’s strongest cells often reflect how a business is run rather than how one measure affects another.

A heatmap

A heatmap colours each cell by its value, usually with one colour for positive correlations, another for negative ones, and pale cells near 0. It makes blocks visible at a glance, but only if related variables sit next to each other: the Explore widget puts the iced share beside the high temperature, so the busy block shows as a dark square in the lower right of its map, where the table above, in the log’s column order, splits it. Good heatmaps make the numbers available too, because colour alone is hard to read precisely and impossible for some readers; the widget gives them in a data table beneath the map.

One table, many tests

Each cell can carry the testing-correlation lesson’s test of H₀: ρ = 0. Twenty-eight cells mean 28 tests. B04’s ANOVA lesson showed the problem: if every null hypothesis were true and the tests were independent, the chance of at least one false alarm among 28 tests at α = 0.05 would be 1−0.9528≈0.761 - 0.95^{28} \approx 0.76, and on average 1.4 cells would be “significant” by chance alone. Tests in a matrix share variables, so they are not independent and the exact figure differs, but the warning stands: a matrix scanned for stars will find some.

With the whole year, the many-tests problem is not the main danger. With 612 days, any correlation larger than 0.08 in size is significant at 5%, so 24 of the 28 cells pass, and 22 to 24 still pass after the adjustments in the In depth section. Here the question is not whether a correlation is zero but whether it is large enough to matter, the practical significance of the testing-correlation lesson. The adjustments matter when samples are small: in Harbourside’s 30 June days, 18 cells are significant at 5% unadjusted, but only 10 survive the Bonferroni correction, 13 Holm’s method and 16 the Benjamini–Hochberg procedure. The challenging example works through them.

In depth

What a correlation matrix is

For m variables, the correlation matrix is the m × m table whose cell in row i and column j is rijr_{ij}, the correlation of variable i with variable j. It has 1s on the diagonal, rij=rjir_{ij} = r_{ji}, and m(m−1)/2m(m-1)/2 distinct off-diagonal cells. A Spearman matrix holds Spearman’s ρ in each cell instead; the rank-correlation lesson explains when to prefer it. For the log the two tell the same story: high temperature and iced share are 0.94 by Pearson and 0.96 by Spearman, because the S-shaped curve is monotonic but not straight.

Not every symmetric table of numbers between −1 and 1 can be a correlation matrix. If x and y correlate at 0.9 and y and z at 0.9, then x and z must correlate at least 0.9×0.9−(1−0.92)(1−0.92)=0.620.9 \times 0.9 - \sqrt{(1 - 0.9^2)(1 - 0.9^2)} = 0.62: variables that both follow y closely must follow each other. The general bound for any three variables is in the Formulas section. A valid matrix is what mathematicians call positive semidefinite; you rarely need the term, but you will meet its failure when a matrix is assembled from different sources or different rows.

Pairwise deletion and the n behind each cell

When some values are missing, the engine used in this course works out each cell from the rows where both of its variables are present, which is pairwise deletion. Each cell can then rest on a different set of rows and a different n, so cells are less comparable, and in bad cases the table as a whole can break the bound above. Report the n of each cell (the Explore widget shows it when you choose one), or use only rows complete on every variable, listwise deletion, if few are lost. Ana’s log has no missing values, so every cell of her matrix uses all 612 days.

Pooled groups and curves

A matrix pools whatever rows you give it, and a matrix of pooled data can mislead. Footfall and sales correlate at 0.89 over both cafés but at 0.98 inside Harbourside and 0.97 inside Millbrook: Millbrook has more customers with smaller tickets, so pooling the cafés blurs a nearly straight line into two. Peak barista hours and peak wait correlate at 0.53 pooled and 0.42 inside each café. The groups-and-simpsons-paradox lesson shows a pair whose sign flips. Before trusting a pooled matrix, compute it within each group too.

A matrix also holds only linear association (or monotonic association, for Spearman). Peak waits rise steeply once the load passes about seven transactions per barista hour, and rain is zero on 209 of the 306 days; a single number in a cell can’t show either shape. A near-zero cell means “no straight-line link”, not “no link”.

Building one in Excel

The Analysis ToolPak’s Correlation tool (Data > Data Analysis > Correlation) takes a block of columns with labels and returns a correlation matrix; Microsoft’s page describes each entry as CORREL’s value for that pair, and the Covariance tool beside it as doing the same with COVARIANCE.P. In use, the tool fills the lower triangle with 1s on the diagonal, writes values rather than formulas (so rerun it when the data change) and gives no p-values.

With formulas, each cell is a CORREL. With the data in B2:E31 and the variable names along the top of a grid, the cell for row variable B and column variable C is =CORREL($B$2:$B$31,C$2:C$31): the dollar signs fix the row variable’s range while the column variable’s range moves as you fill right. One more column of tests is =T.DIST.2T(ABS(r)*SQRT(n-2)/SQRT(1-r^2),n-2) with r and n replaced by their cells, the p-value of the testing-correlation lesson’s t test. Excel has no function for the adjustments below, but each is one or two columns of formulas.

Controlling the family-wise error rate: Bonferroni and Holm

The family-wise error rate is the chance of at least one false alarm among the m tests. The Bonferroni correction keeps it at or below α by testing each hypothesis at α/m\alpha / m: for 28 pairs, 0.05÷28=0.001790.05 \div 28 = 0.00179. Equivalently, multiply each p-value by m (capped at 1) and compare the adjusted p-value with α. It needs no assumption about how the tests depend on each other, which suits a matrix, whose tests share variables. Its cost is power: with many tests, real but moderate correlations fail the strict threshold.

Holm’s method (Holm, 1979) keeps the same guarantee and never rejects fewer hypotheses. Sort the p-values from smallest to largest, p(1)≤p(2)≤⋯≤p(m)p_{(1)} \le p_{(2)} \le \dots \le p_{(m)}. Compare the smallest with α/m\alpha/m, the next with α/(m−1)\alpha/(m-1), and so on, the k-th with α/(m−k+1)\alpha/(m-k+1). Reject while each p-value is below its threshold and stop at the first that isn’t: it and every larger p-value stand. The first comparison is Bonferroni’s; after that each threshold is a little less strict, because once a hypothesis is rejected there is one fewer that could be a false alarm. Holm proved that the guarantee holds whatever the dependence between the tests.

Controlling the false discovery rate: Benjamini–Hochberg

When a matrix is used to screen for leads rather than to confirm findings, guarding against even one false alarm is often too strict. Benjamini and Hochberg (1995) proposed controlling a different quantity, the false discovery rate: the expected proportion of false alarms among the hypotheses rejected (0 if none is rejected). At q = 0.05, about one in twenty of the pairs you report as discoveries may be false, on average.

The Benjamini–Hochberg procedure sorts the p-values in the same way and compares the k-th smallest with k q/mk\,q/m, a threshold that rises in a straight line. Find the largest k whose p-value is at or below its threshold, and reject that hypothesis and every one with a smaller p-value, even if some of those were above their own thresholds. It works from the largest p-value down, so it is called a step-up procedure; Holm’s works from the smallest up and is a step-down. Benjamini and Hochberg proved the control for independent tests. The statsmodels documentation, whose procedures this course’s engine follows, notes that most of these procedures are also robust when the tests are positively correlated. Tests in a matrix need not all be, since they share variables in both directions, so when a guarantee matters Holm’s method (or the more conservative Benjamini–Yekutieli variant, which statsmodels also offers) is the safe choice.

Harbourside, June 2027: the 20 smallest of the 28 p-values in rank order, against each procedure’s threshold. Bonferroni’s threshold is flat at 0.05 ÷ 28; Holm’s rises slowly from it; Benjamini–Hochberg’s rises in a straight line to 0.05 at rank 28. Points above 0.06 are drawn at the top edge.

Which to use

  • Confirming a few planned relationships. When a report will act on each finding, control the family-wise error rate with Holm’s method; it is never worse than Bonferroni.
  • Screening many pairs for leads. When a matrix is a first look and every lead will be checked again, control the false discovery rate with Benjamini–Hochberg, and say that a share of the leads may be false.
  • Defining the family. The adjustment depends on m, so decide before looking which tests form the family: the 28 cells of one matrix, not only the cells that looked interesting. Running a Pearson matrix, then a Spearman matrix, then one for each café and each month multiplies the tests again; an adjustment within each matrix doesn’t correct for that p-hacking.
  • Large samples. With hundreds of rows almost every cell is significant with or without adjustment, so judge the size of each correlation and its interval instead.

Formulas

Number of distinct pairs in a matrix

pairs=m(m−1)2\text{pairs} = \dfrac{m(m-1)}{2}
mm
Number of variables in the matrix
pairs\text{pairs}
Distinct off-diagonal cells, one test each

Eight variables give 28 pairs; ten give 45.

The range a third correlation must lie in

rxy ryz−(1−rxy2)(1−ryz2)  ≤  rxz  ≤  rxy ryz+(1−rxy2)(1−ryz2)r_{xy}\,r_{yz} - \sqrt{(1 - r_{xy}^2)(1 - r_{yz}^2)} \;\le\; r_{xz} \;\le\; r_{xy}\,r_{yz} + \sqrt{(1 - r_{xy}^2)(1 - r_{yz}^2)}
rxy,ryzr_{xy}, r_{yz}
The correlations of x with y and of y with z
rxzr_{xz}
The correlation of x with z

Assumes. All three correlations are worked out from the same rows.

A matrix that breaks it was assembled from different rows (pairwise deletion) or different sources.

Bonferroni-adjusted p-value

p~i=min⁡(1,  m pi)\tilde{p}_i = \min(1,\; m\,p_i)
pip_i
The unadjusted p-value of test i
mm
Number of tests in the family
p~i\tilde{p}_i
Adjusted p-value, compared with α

Assumes. None about dependence between the tests.

The same as testing each p-value against α ÷ m. Controls the family-wise error rate at α.

Holm’s step-down thresholds

reject H(1),…,H(k) while p(k)<αm−k+1\text{reject } H_{(1)}, \dots, H_{(k)} \text{ while } p_{(k)} < \dfrac{\alpha}{m - k + 1}
p(k)p_{(k)}
The k-th smallest p-value
H(k)H_{(k)}
Its null hypothesis
kk
Rank, 1 for the smallest p-value
mm
Number of tests
α\alpha
Family-wise error rate to control

Assumes. None about dependence between the tests.

Stop at the first p-value that is not below its threshold. Adjusted p-values: (m − k + 1) p₍ₖ₎, made non-decreasing in rank and capped at 1.

Benjamini–Hochberg step-up rule

k∗=max⁡{k:p(k)≤km q};reject H(1),…,H(k∗)k^{*} = \max\left\{k : p_{(k)} \le \dfrac{k}{m}\,q\right\}; \quad \text{reject } H_{(1)}, \dots, H_{(k^{*})}
p(k)p_{(k)}
The k-th smallest p-value
H(k)H_{(k)}
Its null hypothesis
k∗k^{*}
The largest rank meeting the rule
kk
Rank, 1 for the smallest p-value
mm
Number of tests
qq
False discovery rate to control

Assumes. Proved for independent tests; robust to the positive dependence usual in a matrix.

Adjusted p-values: p₍ₖ₎ × m ÷ k, made non-increasing from the largest rank down and capped at 1.

Worked examples

A first example: Three adjustments for ten p-values

Fictional figures

Pinecrest Hotel (fictional) correlated five weekly measures (occupancy, average room rate, review score, spa bookings and staff on shift) over a year and tested all 10 pairs. Sorted from smallest to largest, the p-values are 0.0004, 0.0021, 0.0049, 0.0068, 0.012, 0.028, 0.041, 0.13, 0.36 and 0.72. How many pairs are significant at 0.05 with no adjustment, with Bonferroni, with Holm’s method and with Benjamini–Hochberg at q = 0.05?

Pinecrest Hotel’s p-values and the thresholds they are compared with
Rank kp-valueBonferroni α/mHolm α/(m − k + 1)BH kq/m
10.00040.00500.00500.0050
20.00210.00500.00560.0100
30.00490.00500.00630.0150
40.00680.00500.00710.0200
50.0120.00500.00830.0250
60.0280.00500.01000.0300
70.0410.00500.01250.0350
80.130.00500.01670.0400
90.360.00500.02500.0450
100.720.00500.05000.0500
  1. No adjustment: seven p-values are below 0.05 (all up to 0.041).
  2. Bonferroni: with m=10m = 10 each test uses 0.05÷10=0.0050.05 \div 10 = 0.005. Three p-values (0.0004, 0.0021 and 0.0049) are below it.
  3. Holm: the thresholds are 0.05 ÷ 10, then 0.05 ÷ 9, then 0.05 ÷ 8, and so on. 0.0004 < 0.0050, 0.0021 < 0.0056, 0.0049 < 0.0063 and 0.0068 < 0.0071 are rejected; 0.012 is not below 0.0083, so the procedure stops there and the six largest stand.
  4. Benjamini–Hochberg: the thresholds are k×0.005k \times 0.005. Working down from the largest rank, the first p-value at or below its threshold is rank 6, 0.028 against 0.030 (rank 7’s 0.041 is above 0.035). Reject ranks 1 to 6.

Answer. Seven pairs with no adjustment, three with Bonferroni, four with Holm and six with Benjamini–Hochberg.

What it means. The four counts answer different questions. If the hotel will act on each pair as a finding, it should use Holm’s four, with at most a 5% chance that any of them is a false alarm. If the matrix is a screen for leads to check next season, Benjamini–Hochberg’s six are reasonable, expecting that, on average, at most about one in twenty such leads will turn out false.

A harder example: Twenty-eight tests on thirty days

Fictional figures

Ana computes the eight-measure matrix for Harbourside in June 2027 alone: 30 days, 28 pairs. Which correlations survive each adjustment at 0.05, and what explains the differences? The table shows ranks 9 to 19 of the 28 p-values, where the decisions change.

Harbourside, June 2027: ranks 9–19 of the 28 p-values, with each procedure’s threshold
RankPairrp-valueHolm α/(m − k + 1)BH kq/m
9Sales – Peak wait0.720.00000.00250.0161
10Footfall – Peak wait0.700.00000.00260.0179
11Rain (in) – Transactions−0.550.00180.00280.0196
12Rain (in) – Sales−0.530.00240.00290.0214
13High (°F) – Peak barista hours0.520.00300.00310.0232
14Rain (in) – Footfall−0.510.00380.00330.0250
15Iced share – Peak barista hours0.450.01190.00360.0268
16High (°F) – Footfall0.420.02240.00380.0286
17High (°F) – Transactions0.390.03320.00420.0304
18Footfall – Iced share0.370.04390.00450.0321
19High (°F) – Sales0.360.05080.00500.0339
  1. With n = 30 a correlation needs a size of at least 0.36 to be significant at 5% (the testing-correlation lesson’s critical r, t∗/n−2+t∗2t^{*}/\sqrt{n - 2 + t^{*2}} with 28 df). Eighteen of the 28 cells reach it, from transactions–sales (0.99) down to footfall–iced share (0.37, p = 0.044).
  2. Bonferroni tests each at 0.05÷28=0.001790.05 \div 28 = 0.00179. Ten pairs pass. Rank 11, rain–transactions, has p = 0.0018 (r = −0.55) and misses by a hair: at n = 30 Bonferroni needs a correlation of about 0.55 in size.
  3. Holm compares rank 11 with 0.05 ÷ 18 = 0.0028 and rejects it; rank 12 (0.0024 against 0.0029) and rank 13 (0.0030 against 0.0031) are rejected too; rank 14, rain–footfall, has 0.0038 against 0.0033 and stops the procedure. Thirteen pairs survive.
  4. Benjamini–Hochberg looks for the largest rank whose p-value is at or below k × 0.05 ÷ 28. Rank 16, high–footfall, has 0.022 against 0.029; ranks 17 and above are all above their thresholds (0.033 against 0.030 at rank 17). Sixteen pairs are discoveries.
  5. What changes between the procedures is the band of moderate correlations, 0.42 to 0.55 in size: rain with transactions, sales and footfall, and peak barista hours with the high temperature and the iced share, and the high temperature with footfall. The ten strong ones survive everything; the last two of the 18 (high–transactions at 0.39 and footfall–iced share at 0.37) survive nothing but the unadjusted test.

Answer. Eighteen pairs are significant unadjusted, ten after Bonferroni, thirteen after Holm and sixteen after Benjamini–Hochberg (all at 0.05).

What it means. On 30 days, how Ana handles the 28 tests changes what she can claim about rain. With Holm’s method, rain–transactions and rain–sales survive but rain–footfall doesn’t, which is odd if rain keeps people away; with Benjamini–Hochberg all three survive as leads. The sensible reading is that June gives moderate evidence that rainy days were quieter at Harbourside, consistent with the whole year’s weaker but clearer −0.23, and that a month is too short to separate the rain pairs from one another. The example is fictional, like all of Lantern’s log.

Applied: a business decision: From a matrix to a list of questions

Fictional figures

Ana’s year matrix (the table in The idea) has 24 significant cells. She doesn’t want 24 findings; she wants the few questions worth her time in January. Turn the matrix into a short list.

  1. Remove duplicates first. Footfall and transactions correlate at 0.98, so their rows say the same thing; she keeps transactions, the measure her till records, and treats footfall as a check on it.
  2. Look for links that would change a decision. Peak barista hours and peak wait correlate at +0.53: taken at face value, more baristas go with longer waits, which would be a reason to roster fewer. Both also rise with how busy the day is (transactions correlate with barista hours at 0.93 and with waits at 0.77), so the pair needs a comparison at a given number of transactions: the partial-correlation lesson.
  3. Check pooled cells by café. High temperature and sales correlate at 0.29 pooled, 0.40 at Harbourside and 0.15 at Millbrook: the waterfront café’s trade follows the weather far more than the office café’s.
  4. Note what the matrix can’t show. Rain correlates with sales at only −0.15, but rain falls on 97 of the 306 days and is zero on the rest, so a straight-line summary undersells a link that appears only on wet days (the nonlinear-and-restricted lesson).

Answer. Three questions for January: do more baristas shorten waits at a given level of trade; does Harbourside’s stock and staffing need to follow the forecast more closely than Millbrook’s; and how much does a wet day cost each café?

What it means. The matrix did its job: it pointed at three questions and away from 21 cells that are significant but either duplicated, expected or too weak to change anything. None of the three is answered by the matrix itself; each needs a closer look, and the first needs the next lesson.

Explore

The year’s matrix for both cafés. Choose a cell to see its scatterplot: compare footfall–transactions (one tight line) with peak barista hours–peak wait (a cloud). Switch to Spearman and watch high–iced share rise to 0.96. Then turn on an adjustment: with 612 days, Bonferroni removes only two of the 24 significant pairs.

Loading the interactive…

Harbourside in June: 30 days. Start with no adjustment (18 significant pairs), then try Bonferroni, Holm and Benjamini–Hochberg and find the cells that change. Choose rain–transactions to see the correlation that misses Bonferroni’s threshold by a hair.

Loading the interactive…

Set the correlations of x with y and of y with z and see the range in which the third correlation must lie. Two correlations of 0.9 force the third to be at least 0.62; two of 0.5 allow anything from −0.5 to 1.

Loading the interactive…

Common mistakes

  • “Twenty-four cells are significant, so I have 24 findings.”

    With 612 days, any correlation larger than 0.08 in size is significant. Significance only says the correlation is unlikely to be exactly zero; whether 0.08 matters to anyone is a separate question. Report the size of each correlation and its interval, and pick out the few that would change a decision.

  • “I’ll choose the adjustment after I see which one keeps my favourite pair.”

    Choosing Bonferroni, Holm or Benjamini–Hochberg after seeing the results is another way of trying analyses until one works. Decide before looking: Holm when every rejection will be acted on as a finding, Benjamini–Hochberg when the matrix is a screen for leads. Define the family (which tests) in advance too.

  • “Footfall and transactions both correlate with waiting, so that’s two pieces of evidence.”

    Two measures that correlate at 0.98 carry nearly the same information. Their correlations with a third variable will be nearly identical, so counting both double-counts one piece of evidence. Choose one, or combine them, before you count links.

  • “The cell is near zero, so the two are unrelated.”

    A cell holds linear (or, for Spearman, monotonic) association over the rows you gave it. A curve, a U-shape, a variable that is zero on most days, or two groups pulling in opposite directions can all give a cell near zero. Look at the scatterplot and compute the matrix within each group.

  • “A matrix of pairwise correlations is always valid.”

    With pairwise deletion each cell may use different rows, and the table as a whole can then be impossible: for instance, 0.9 and 0.9 with a third cell of 0.2, below the 0.62 that the bound requires. Check the n behind each cell and, if many values are missing, consider listwise deletion or report the missing data.

Guided practice

Work through these with hints when you need them. Every hint and every worked solution is there to be used.

Loading four questions…

On your own

No hints this time. Answer, check, and read the feedback; the solution appears once you have answered or if you ask for it. Your first answers count toward mastery.

Loading six questions…

In practice

A correlation matrix is one of the first things an analyst builds when a dataset arrives with many measures: a retailer’s weekly store KPIs, a hotel’s nightly operating figures, a fund’s daily returns on many assets, or the dozen questions of a customer survey. It answers three practical questions quickly. Which measures are near-duplicates, so that a dashboard or model needs only one of them? Which pairs are strong enough to deserve a closer look? And which expected links are missing, which may point to a data problem (a broken feed, a column in the wrong units) rather than a business insight?

Fictional case

Ana’s January note reads: “The daily log’s correlation matrix (eight measures, both cafés, 612 days) has three blocks: how busy the day was (footfall, transactions, sales, peak barista hours and peak wait), the weather and the iced share, and rain. Footfall and transactions are near-duplicates (r = 0.98), so I will use transactions. With this many days almost every pair is statistically significant, so I have ranked pairs by size instead. Three questions follow: whether baristas shorten waits at a given level of trade, why Harbourside’s sales follow the weather (r = 0.40) more than Millbrook’s (0.15), and what a wet day costs each café. None of these correlations shows what causes what.”

Her note follows the habits that make a matrix useful rather than misleading. It states the rows used (both cafés, all days) and the n. It treats the matrix as a map that suggests questions, not as a list of results. It removes duplicates before counting links. It checks pooled results within each café. And it avoids causal words: the cells say what goes with what, and the last lesson of this module is about what more it would take to say what causes what.

When a matrix is used to confirm findings, the adjustment for many tests belongs in the report: say how many pairs were tested, which procedure was used and why, and give both the adjusted and unadjusted p-values for the pairs you discuss. When it is used for screening, say so, and treat every lead as a hypothesis to test again on new data, such as the next quarter’s log. A lead that holds up on data it wasn’t found in is worth far more than one that survives an adjustment on the data that suggested it.

Knowledge check

Six questions, one attempt each, no hints. Score 80% or more to complete the lesson; you can take it again at any time.

Loading six questions…

Summary

  • A correlation matrix shows every pair of m variables in one symmetric table with 1s on the diagonal; it has m(m − 1)/2 distinct pairs (28 for 8 variables). A heatmap colours the cells, and should print the numbers too.
  • Read the structure first: blocks of related measures, redundant measures (footfall and transactions, r = 0.98, carry one piece of evidence, not two) and near-zero pairs. Then look at the scatterplot behind any cell you report.
  • A matrix pools the rows you give it and holds only linear (or monotonic) association: compute it within groups, and remember that a near-zero cell can hide a curve.
  • Some combinations of correlations are impossible: if r_xy = r_yz = 0.9, r_xz must be at least 0.62. Pairwise deletion can produce such impossible matrices.
  • Testing every cell makes false alarms likely. Bonferroni (α ÷ m) and Holm’s step-down method control the family-wise error rate whatever the dependence; Holm is never less powerful. Benjamini–Hochberg controls the false discovery rate and finds more leads.
  • With hundreds of rows almost every cell is significant, so judge practical size; with a few dozen rows the adjustment decides what you can claim (June at Harbourside: 18 unadjusted, 10 Bonferroni, 13 Holm, 16 Benjamini–Hochberg).
  • Use a matrix as a map for questions, decide the family and the adjustment before looking, and check leads on new data. A matrix says what goes with what, not why.

Key formulas

Terms introduced

Correlation matrix
A square, symmetric table of the correlations between every pair of a set of variables, with 1s on the diagonal; m variables give m(m − 1)/2 distinct pairs.
Heatmap
A table or matrix drawn as a grid of coloured cells, the colour showing each cell’s value; for a correlation matrix, one colour for positive and another for negative correlations, paler near zero.
Redundant measures
Two or more variables so closely correlated that they carry nearly the same information, so that using both adds little and can double-count evidence.
Holm’s method
A step-down procedure that controls the family-wise error rate: sort the m p-values, compare the k-th smallest with α ÷ (m − k + 1), and reject until the first that is not below its threshold. Never less powerful than Bonferroni.
False discovery rate
The expected proportion of false alarms among the hypotheses rejected (taken as 0 when none is rejected).
Benjamini–Hochberg procedure
A step-up procedure that controls the false discovery rate at q: sort the m p-values and reject every hypothesis up to the largest rank k whose p-value is at or below k × q ÷ m.

Sources

  1. Holmes, A., Illowsky, B. & Dean, S. (2023). Introductory Business Statistics 2e, section 13.1, “The Correlation Coefficient r”. OpenStax. openstax.org/books/introductory-business-statistics-2e/pages…
  2. Microsoft Support. “Use the Analysis ToolPak to perform complex data analysis” (the Correlation and Covariance tools). support.microsoft.com/en-us/topic/6c67ccf0-f4a9-487c-8dec-bd…
  3. Holm, S. (1979). “A simple sequentially rejective multiple test procedure”. Scandinavian Journal of Statistics, 6(2), 65–70. ime.usp.br/~abe/lista/pdf4R8xPVzCnX.pdf
  4. Benjamini, Y. & Hochberg, Y. (1995). “Controlling the false discovery rate: a practical and powerful approach to multiple testing”. Journal of the Royal Statistical Society, Series B, 57(1), 289–300. dcscience.net/Benjamini-Hochberg-1995-FDR.pdf
  5. statsmodels. “statsmodels.stats.multitest.multipletests” (documentation). statsmodels.org/stable/generated/statsmodels.stats.multitest…
  6. NIST/SEMATECH. e-Handbook of Statistical Methods, section 7.4.7.3, “Bonferroni’s method”. itl.nist.gov/div898/handbook/prc/section4/prc473.htm