Correlation matrix with heatmap
Compute a Pearson, Spearman or Kendall correlation matrix from CSV columns, with p-values and a colour heatmap.
A clear answer. Here’s how.
Finds the numeric columns (or uses the ones listed) and correlates every pair. Pearson’s r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² Σ(y − ȳ)²) measures straight-line association. Spearman’s rho is Pearson’s r of the average ranks, so ties share a rank, and it measures any monotonic association. Kendall’s tau-b = (concordant − discordant pairs) ÷ √((n₀ − n₁)(n₀ − n₂)), with n₁ and n₂ the pairs tied in each column, counted with Knight’s O(n log n) algorithm. Two-sided p-values use t = r√((n − 2) ÷ (1 − r²)) on n − 2 df for Pearson and, as an approximation, Spearman, and the normal approximation with the tie-corrected variance of S for Kendall (as R’s cor.test with exact = FALSE). Pairwise deletion uses every row where both values are present, so each cell may rest on a different n; listwise uses only rows complete in every chosen column. The heatmap runs from blue (−1) through white to red (+1), with each value printed. P-values are not corrected for the number of pairs; use the multiple testing correction tool for that. Correlation is not causation, and r can hide curves, clusters and outliers, so plot the data. It is a calculator, not a substitute for a statistician when decisions depend on the answer.
How this is checked
5 reference checks passed These 5 cases were run when this page was built, on 20 October 2026, and all reproduce within the stated tolerance. The same cases are part of the automated tests that run on every change to Toolmoz. Engine version 1.
See the checks and where each expected answer comes from
Case 1
- Inputs
- The tool’s default inputs
- Expected, and what Toolmoz gave
- Pearson r (mpg, wt) expected -0.8676593765172278, Toolmoz -0.8676593765172277Pearson r (mpg, hp) expected -0.7761683718265864, Toolmoz -0.7761683718265863Pearson r (hp, wt) expected 0.6587478873447592, Toolmoz 0.6587478873447592Pearson r (mpg, cyl) expected -0.8521619594266131, Toolmoz -0.8521619594266129P-value (mpg, wt) expected 1.293958701350505e-10, Toolmoz 1.2939587013505346e-10
- Where the expected answer comes from
- R’s cor(mtcars) gives −0.868 for mpg and wt, −0.776 for mpg and hp, 0.659 for wt and hp and −0.852 for mpg and cyl, and cor.test(mtcars$mpg, mtcars$wt) p = 1.294e-10; full precision from exact fractions and an incomplete-beta integral in an independent Python script
- Allowed difference
- ±1e-7 relative
Case 2
- Inputs
- Coefficient spearman
- Expected, and what Toolmoz gave
- Spearman rho (mpg, wt) expected -0.8864220332702978, Toolmoz -0.8864220332702978Spearman rho (mpg, hp) expected -0.8946646457499625, Toolmoz -0.8946646457499625Spearman rho (hp, wt) expected 0.7746767333913839, Toolmoz 0.7746767333913839
- Where the expected answer comes from
- Pearson r of average ranks computed in an independent Python fractions script; R’s cor.test(method = “spearman”) gives rho −0.886 for mpg and wt
- Allowed difference
- ±1e-12
Case 3
- Inputs
- Coefficient kendall
- Expected, and what Toolmoz gave
- Kendall tau-b (mpg, wt) expected -0.727832149528431, Toolmoz -0.727832149528431P-value (mpg, wt) expected 6.705770383419463e-9, Toolmoz 6.705770405595859e-9Kendall tau-b (hp, wt) expected 0.6113080957320589, Toolmoz 0.6113080957320589
- Where the expected answer comes from
- Counting all 496 pairs of cars in an independent Python script (O(n²)), with the tie-corrected variance of S; R’s cor.test(method = “kendall”) gives tau = −0.728, z = −5.798, p = 6.706e-09 for mpg and wt
- Allowed difference
- ±1e-8 relative
Case 4
- Inputs
- Data table, column names in the first line x1,y1,x2,y2,x3,y3,x4,y4 10,8.04,10,9.14,10,7.46,8,6.58 8,6.95,8,8.14,8,6.77,8,5.76 13,7.58,13,8.74,13,12.74,8,7.71 9,8.81,9,8.77,9,7.11,8,8.84 11,8.33,11,9.26,11,7.81,8,8.47 14,9.96,14,8.10,14,8.84,8,7.04 6,7.24,6,6.13,6,6.08,8,5.25 4,4.26,4,3.10,4,5.39,19,12.50 12,10.84,12,9.13,12,8.15,8,5.56 7,4.82,7,7.26,7,6.42,8,7.91 5,5.68,5,4.74,5,5.73,8,6.89
- Expected, and what Toolmoz gave
- Pearson r (x1, y1) expected 0.8164205163448399, Toolmoz 0.81642051634484Pearson r (x2, y2) expected 0.8162365060002428, Toolmoz 0.8162365060002428Pearson r (x3, y3) expected 0.8162867394895983, Toolmoz 0.8162867394895981Pearson r (x4, y4) expected 0.8165214368885029, Toolmoz 0.8165214368885028
- Where the expected answer comes from
- Anscombe (1973): all four data sets have r = 0.816; exact fractions in an independent Python script
- Allowed difference
- ±1e-12
Case 5
- Inputs
- Data table, column names in the first line a,b,c 1,2,1 2,1,3 3,4,2 4,3,5 5,NA,4 NA,6,6
- Expected, and what Toolmoz gave
- Pearson r (a, b) expected 0.6, Toolmoz 0.6Pairs (a, b) expected 4, Toolmoz 4Pearson r (a, c) expected 0.8, Toolmoz 0.8Pearson r (b, c) expected 0.6016946526766802, Toolmoz 0.6016946526766802
- Where the expected answer comes from
- Pairwise deletion by hand: a and b share rows 1–4, where Σdxdy = 3 and Σdx² = Σdy² = 5, so r = 0.6; a and c share rows 1–5 with r = 8/10; b and c from an independent Python script
- Allowed difference
- ±1e-12
What this shows: the engine reproduces independently worked values for these cases. It does not prove every possible input is right. To test an answer you were given, see how to check a number; to see what is and is not checked across Toolmoz, see the accuracy ledger.
See a worked example
Worked example
A fixed demonstration, separate from the values you enter above.
- Data table, column names in the first line
model,mpg,cyl,disp,hp,drat,wt,qsec Mazda RX4,21.0,6,160.0,110,3.90,2.620,16.46 Mazda RX4 Wag,21.0,6,160.0,110,3.90,2.875,17.02 Datsun 710,22.8,4,108.0,93,3.85,2.320,18.61 Hornet 4 Drive,21.4,6,258.0,110,3.08,3.215,19.44 Hornet Sportabout,18.7,8,360.0,175,3.15,3.440,17.02 Valiant,18.1,6,225.0,105,2.76,3.460,20.22 Duster 360,14.3,8,360.0,245,3.21,3.570,15.84 Merc 240D,24.4,4,146.7,62,3.69,3.190,20.00 Merc 230,22.8,4,140.8,95,3.92,3.150,22.90 Merc 280,19.2,6,167.6,123,3.92,3.440,18.30 Merc 280C,17.8,6,167.6,123,3.92,3.440,18.90 Merc 450SE,16.4,8,275.8,180,3.07,4.070,17.40 Merc 450SL,17.3,8,275.8,180,3.07,3.730,17.60 Merc 450SLC,15.2,8,275.8,180,3.07,3.780,18.00 Cadillac Fleetwood,10.4,8,472.0,205,2.93,5.250,17.98 Lincoln Continental,10.4,8,460.0,215,3.00,5.424,17.82 Chrysler Imperial,14.7,8,440.0,230,3.23,5.345,17.42 Fiat 128,32.4,4,78.7,66,4.08,2.200,19.47 Honda Civic,30.4,4,75.7,52,4.93,1.615,18.52 Toyota Corolla,33.9,4,71.1,65,4.22,1.835,19.90 Toyota Corona,21.5,4,120.1,97,3.70,2.465,20.01 Dodge Challenger,15.5,8,318.0,150,2.76,3.520,16.87 AMC Javelin,15.2,8,304.0,150,3.15,3.435,17.30 Camaro Z28,13.3,8,350.0,245,3.73,3.840,15.41 Pontiac Firebird,19.2,8,400.0,175,3.08,3.845,17.05 Fiat X1-9,27.3,4,79.0,66,4.08,1.935,18.90 Porsche 914-2,26.0,4,120.3,91,4.43,2.140,16.70 Lotus Europa,30.4,4,95.1,113,3.77,1.513,16.90 Ford Pantera L,15.8,8,351.0,264,4.22,3.170,14.50 Ferrari Dino,19.7,6,145.0,175,3.62,2.770,15.50 Maserati Bora,15.0,8,301.0,335,3.54,3.570,14.60 Volvo 142E,21.4,4,121.0,109,4.11,2.780,18.60
- Column separator
- Detect automatically
- Coefficient
- Pearson r (linear)
- Missing values
- Pairwise: each pair uses its complete rows
- Columns to correlate
- Table shows
- Correlation coefficients
Example result
| Pearson r | mpg | cyl | disp | hp | drat | wt | qsec |
|---|---|---|---|---|---|---|---|
| mpg | 1 | -0.8522 | -0.8476 | -0.7762 | 0.6812 | -0.8677 | 0.4187 |
| cyl | -0.8522 | 1 | 0.902 | 0.8324 | -0.6999 | 0.7825 | -0.5912 |
| disp | -0.8476 | 0.902 | 1 | 0.7909 | -0.7102 | 0.888 | -0.4337 |
| hp | -0.7762 | 0.8324 | 0.7909 | 1 | -0.4488 | 0.6587 | -0.7082 |
| drat | 0.6812 | -0.6999 | -0.7102 | -0.4488 | 1 | -0.7124 | 0.0912 |
Pearson’s r measures straight-line association; its p-value uses t = r√((n − 2) ÷ (1 − r²)) with n − 2 df. Pairwise deletion: each pair uses every row where both values are present, so n can differ between cells. P-values are not adjusted for the 21 tests; correlation does not show cause.