Edd's Knowledge Base

A correlation coefficient summarizes how strongly two variables move together on a scale from -1 (perfectly opposite) to +1 (perfectly together). Pearson, Spearman, and Kendall differ in the kind of togetherness they detect, and point-biserial and phi cover binary variables. For how to test and put intervals on them, see Statistical Inference Basics.

Zero correlation is not independence

A coefficient of 0 only means there is no linear relationship (Pearson) or no monotonic one (Spearman, Kendall). Independent variables always have correlation 0, but the reverse fails: on a symmetric range has despite perfect dependence. The exception is a jointly bivariate normal pair, where uncorrelated does imply independent. Variables that are each normal but not jointly normal can be uncorrelated yet dependent.

Pearson (linear)

  • Measures how well a straight line fits; is the share of variance explained by the linear fit.
  • Uses raw values, so a single outlier can move it a lot. Anscombe’s quartet shows four very different datasets sharing the same .

Spearman rank (monotonic)

  • Pearson applied to ranks, so any monotonic curve (such as ) scores 1.
  • Robust to outliers; suitable for ordinal data. Ties get the average rank, and with many ties use the Pearson-on-ranks form, not the shortcut.

Kendall’s tau (concordance)

A pair of observations is concordant if both variables order it the same way, otherwise discordant.

; count pairs tied in and in . Use with ties (SciPy’s default).

  • Meaning: for a random pair.
  • Robust, best for small samples and many ties; usually smaller in magnitude than Spearman.
  • Naive cost ; Knight’s algorithm gives .
  • Under a bivariate normal only: and .

Comparison

PearsonSpearmanKendall
DetectsLinearMonotonicMonotonic
UsesRaw valuesRanksPair orderings
Outlier robustNoYesYes
Ordinal dataNoYesYes
Small n / many tiesFineOKBest
Interpretation = variance explainedPearson on ranksConcordant minus discordant probability

Example

x = [1,2,3,4,5], y = [1,2,3,4,100] is perfectly monotonic with one extreme point. Pearson (the outlier distorts the fit); Spearman and Kendall .

from scipy.stats import pearsonr, spearmanr, kendalltau
pearsonr(x, y), spearmanr(x, y), kendalltau(x, y)

Source: SciPy statistics reference.

Which to Use

  1. Plot the scatter first.
  2. Clean, continuous, roughly linear data: Pearson.
  3. Curved but monotonic, outliers, or ordinal ratings: Spearman.
  4. Small sample, many ties, or a probabilistic reading wanted: Kendall.
  5. Non-monotonic patterns (U-shapes, cycles): none of these work. Use distance correlation (zero only under independence), mutual information, or a plot.

Correlation never implies causation. In practice, correlation matrices and heatmaps are a standard step in Exploratory Data Analysis.

Monotonic Functions

A function is monotonic if it never changes direction: non-decreasing () or non-increasing. Every line with nonzero slope is monotonic, but so are , , and . over all reals and are not. This is the gap Spearman and Kendall exploit: they score 1 whenever the ranking is perfectly preserved, whatever the curve.

Ranking Is Not Binning

Spearman ranks each variable separately, so it works when one variable is continuous and the other ordinal (or both are either). Each distinct value gets its own rank and ties share the average rank, e.g. ages [23, 31, 45, 31, 60] get ranks [1, 2.5, 4, 2.5, 5]. Order is preserved; only the spacing is discarded, which is why outliers cannot dominate. With heavy ties from a short ordinal scale, Kendall’s is often preferable.

Ordinal Association and Other Variable Types

Ordinal variables have an order but no meaningful distances (star ratings, education level). An ordinal association is the tendency for higher ranks of one variable to go with higher (or lower) ranks of another, using only order. Kendall’s tau captures this directly through concordant and discordant pairs.

CoefficientVariablesExampleResult
PearsonTwo continuous, linearHours studied vs. exam score
SpearmanContinuous or ordinal, monotonicSaturating dose-response (1 to 32 mg), Pearson only
KendallOrdinal, small n, many tiesSatisfaction (1 to 5) vs. loyalty tier (1 to 3)
Point-biserialContinuous and binaryPassed (0/1) vs. hours studied
PhiTwo binarySmoker vs. disease in a 2x2 table

Point-biserial is Pearson with the binary variable coded 0/1:

Testing is equivalent to a pooled two-sample t-test of the group means. Use it for a true dichotomy; an artificially split continuous variable calls for the biserial coefficient.

Phi is Pearson on two 0/1 variables. From a 2x2 table with counts :

Smokers with disease , without , non-smokers with disease , without give . Its maximum falls below 1 when the margins are unequal, so compare it across tables with care.

Variable typesUse
Continuous, continuous, linearPearson
Continuous or ordinal, monotonicSpearman
Ordinal, small n, many tiesKendall
Continuous, binaryPoint-biserial
Binary, binaryPhi

Normality

Normality only matters for inference (p-values, intervals), never for computing a coefficient, and it is a reason to choose a test, not a different coefficient.

CoefficientInference assumesIf violated
PearsonApproximately bivariate normal (the joint distribution, not each variable alone). The CLT helps at moderate n; outliers and heavy tails hurt most.Bootstrap CI or permutation test
SpearmanDistribution-free under independence (exact or permutation tables)Usually none needed
KendallDistribution-free under independence; exact test is reliable at small nUsually none needed
Point-biserialEquals the pooled t-test: continuous variable roughly normal within each group, equal variancesWelch, Mann-Whitney U, permutation test
PhiNo normality; chi-square needs expected counts of about 5 or more per cellFisher’s exact test

Independence of observations is the assumption that matters most across all five and fails most often (repeated measures, time series, clustered data). For paired binary data use McNemar’s test. Ties need the corrections noted above (average ranks, ); SciPy applies them.

Application: Early Warning in Industrial Systems

Sensors that normally move together form a stable correlation pattern during healthy operation. A change in that pattern can be the warning, often before any single sensor crosses an alarm threshold, supporting predictive maintenance and less unplanned downtime.

SettingSignalsEarly warning
Pumps, motors, fansVibration vs. current vs. bearing temperatureVibration rises at constant load, suggesting bearing wear
Cooling systemsCoolant flow vs. outlet temperatureNormally strongly negative; weakening suggests fouling or pump failure
Process plantsFeed rate vs. reactor temperature vs. qualityA tight relationship loosens: catalyst aging or sensor drift
ManufacturingCutting force vs. surface roughnessTool wear before parts fail inspection
Power utilitiesTransformer load vs. oil temperatureTemperature rises faster than load explains
Redundant sensorsTwo sensors measuring the same quantityCorrelation near 1 degrades, flagging sensor drift

See Correlation Drift Monitoring with Spark for a runnable batch and streaming example.

Method: learn a baseline correlation matrix on healthy data, recompute over a rolling window, alert when correlations leave their normal band, and use lagged cross-correlation for lead time. Caveats: a change is a symptom, not a diagnosis; start-up and load regimes legitimately alter correlations; Pearson misses nonlinear patterns (use Spearman or mutual information); trending variables correlate spuriously unless detrended; short windows are fast but noisy, long ones stable but slow.