Correlation analysis

Correlation analysis

How Pearson, Spearman and related coefficients measure the strength and direction of association between two variables, and why correlation alone does not show cause.

What it is

Correlation analysis measures how strongly two variables vary together and in which direction. A positive correlation means that when one variable is high the other tends to be high too; a negative correlation means the opposite; zero means no linear (or monotonic) relationship. The strength is summarized by a correlation coefficient between −1 and +1. Correlation is among the most widely used statistical tools, from checking that two instruments agree to screening thousands of variables for relationships, and it is the starting point for regression and multivariate methods.

It answers questions such as: Does catalyst loading go up with conversion? Are two measurements of the same quantity consistent? Which of many variables move together? How strong is the association, and could it be due to chance? It does not answer whether one variable causes the other, a distinction that matters in every field.

Fundamentals

Pearson’s correlation coefficient

For paired observations (xi, yi), Pearson’s r is the covariance divided by the product of the standard deviations:

r = Σ (xi − x̄)(yi − ȳ) / √[Σ (xi − x̄)2 Σ (yi − ȳ)2]

It measures linear association only and is unchanged by linear rescaling or unit changes of either variable. The square r2, the coefficient of determination, is the fraction of variance in y that a straight line on x explains (r = 0.7 gives r2 = 0.49). A common rough guide for the strength is |r| below 0.3 weak, 0.3–0.7 moderate, above 0.7 strong, but meaning depends on the field. The test of H0: ρ = 0 uses t = r√(n − 2)/√(1 − r2) with n − 2 df. Confidence intervals use the Fisher z transformation, z′ = ½ ln[(1 + r)/(1 − r)] = arctanh(r), which has standard error 1/√(n − 3); the interval is back-transformed with tanh. Assumptions for inference are independent pairs, roughly bivariate normal data and no extreme outliers; r is sensitive to outliers, which can create or hide a correlation.

Rank correlations

  • Spearman’s ρ is Pearson’s r applied to the ranks of the data, so it detects any monotonic relationship (always increasing or decreasing, even if curved) and is robust to outliers and ordinal data. With no ties, ρ = 1 − 6 Σ di2 / [n(n2 − 1)], where di is the rank difference.
  • Kendall’s τ compares concordant and discordant pairs, τ = (C − D)/[n(n − 1)/2]; it has a clearer probability interpretation, handles ties better (τ-b) and is more reliable for small samples.
  • Other measures: the point-biserial coefficient (one binary and one continuous variable), the phi coefficient (two binary), polychoric/polyserial correlations (ordinal data assumed to come from underlying continuous variables), the intraclass correlation (ICC) for agreement and reliability, and distance correlation and mutual information, which detect nonlinear and non-monotonic dependence (distance correlation is zero only for independent variables).

Pitfalls and interpretation

Correlation does not imply causation: an observed association can arise because x causes y, y causes x, a third variable (a confounder) causes both, or by chance. Ice cream sales and drowning rise together because of summer heat. Specific traps include:

  • Nonlinearity: a perfect U-shaped relationship can give r ≈ 0. Always draw a scatter plot; Anscombe’s quartet shows four very different datasets with the same r = 0.82.
  • Outliers and leverage points that drive r.
  • Restricted range: sampling only part of the range of x shrinks r; pooling distinct groups can create or reverse a correlation (Simpson’s paradox).
  • Spurious correlation from trending time series, shared denominators (ratios) or compositional data (parts that sum to 100%), where correlation is built in.
  • Ecological fallacy: inferring individual relationships from group averages.
  • Autocorrelation and clustered data violate independence and exaggerate significance.

Partial correlation and many variables

Partial correlation measures the association between x and y after removing the linear effect of one or more control variables z: rxy·z = (rxy − rxz ryz)/√[(1 − rxz2)(1 − ryz2)]. A correlation matrix summarizes all pairs and is displayed as a heatmap or clustered plot; it is the input to principal component and factor analysis. When many correlations are tested (p variables give p(p − 1)/2 pairs), some will be significant by chance, so the false discovery rate (Benjamini–Hochberg) or Bonferroni correction is applied. Large datasets with small effects give very small p-values for trivial correlations, so effect size and confidence intervals matter more than p. The sample size needed to detect r = 0.3 with 80% power at α = 0.05 is about 85. Correlation versus regression: correlation is symmetric and unitless, while regression predicts y from x and gives a slope with units.

Agreement, reliability and software

Correlation is not agreement: two instruments can be perfectly correlated yet differ by a constant offset or scale factor. For method comparison use a Bland–Altman plot (difference versus mean, with limits of agreement at mean difference ± 1.96 s) or the concordance correlation coefficient. Software includes R (cor(), cor.test(), corrplot), Python (scipy.stats.pearsonr, spearmanr, pandas.corr), Excel (CORREL) and SPSS.

Typical applications and limits

Applications include instrument validation, feature screening, exploratory analysis of omics and survey data, and reliability testing. Limits are the focus on pairwise relationships, sensitivity to the points above and the inability to establish cause.

Basic operation

  1. Plot first. Make a scatter plot to check for linearity, outliers and groups.
  2. Choose the coefficient. Use Pearson for linear continuous data, Spearman or Kendall for ranks, skew, outliers or ordinal data.
  3. Compute the coefficient. Calculate r (or ρ, τ) and r2.
  4. Test and give an interval. Obtain a p-value and a confidence interval, using Fisher’s z for Pearson.
  5. Check assumptions and influence. Examine outliers, range restriction and independence of pairs.
  6. Control for confounders. Use partial correlation or regression if other variables matter.
  7. Adjust for multiple tests. Apply false discovery rate correction for many pairs.
  8. Collect the output. You obtain a coefficient with interval and p-value; confounding and nonlinear measures are covered in the video.

Good practice

  • Always look at the scatter plot. The coefficient hides shape.
  • Do not infer causation. Consider confounders and reverse causality.
  • Report intervals and n. A coefficient without uncertainty is hard to judge.
  • Beware of subgroup mixing. Check for Simpson’s paradox.
  • Use agreement methods for method comparison. Do not use r alone.
  • Avoid data dredging. Correct for multiple tests and state in advance which relationships you test.

Key terms

  • Pearson’s r — the coefficient of linear association between two continuous variables.
  • Spearman’s ρ — a rank-based coefficient for monotonic association.
  • Coefficient of determination (r2) — the fraction of variance in one variable explained linearly by the other.
  • Confounder — a third variable that influences both variables studied.
  • Partial correlation — correlation after removing the effect of other variables.
  • Spurious correlation — an association with no real link, arising from chance or structure.
  • Simpson’s paradox — a trend that appears in groups but reverses when they are combined.

Video coming soon

About five minutes on Correlation analysis: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping