Worked correlation example

Pearson vs Spearman is not just normal vs non-normal.

Pearson's r summarizes linear association in the raw paired values. Spearman's ρ summarizes monotonic association after replacing both variables with ranks. The scientific question and the scatterplot come before a normality-test P value.

9 paired observations2 correlation estimandsOfficial R example8-minute read

The short answer

Choose the relationship you mean to quantify.

Use Pearson correlation when a linear association is the target and the scatterplot supports that model. Use Spearman correlation when the target is monotonic ordering, when values are meaningfully ordinal, or when ranks better express the question. Neither coefficient detects every kind of relationship.

Decision rule: inspect the raw paired data, state whether “linear” or “monotonic” is the estimand, check independence and influential observations, then choose the coefficient. Do not run both and report whichever P value is smaller.

R's canonical tuna-quality example

The official R cor.test documentation reproduces Hollander and Wolfe's comparison of Hunter L lightness with averaged consumer-panel scores for nine lots of canned tuna. Each row is one lot measured in both ways.

Lot Hunter L Panel score L rank Score rank
1 44.4 2.6 3 2
2 45.9 3.1 6 4
3 41.9 2.5 1 1
4 53.3 5.0 8 8
5 44.7 3.6 4 5
6 44.1 4.0 2 7
7 50.7 5.2 7 9
8 45.2 2.8 5 3
9 60.1 3.8 9 6
Hunter L lightness versus consumer panel score Nine paired points show an overall positive association with visible scatter. The lot with the highest Hunter L value does not have the highest panel score. Lot 1: 44.4, 2.6 Lot 2: 45.9, 3.1 Lot 3: 41.9, 2.5 Lot 4: 53.3, 5.0 Lot 5: 44.7, 3.6 Lot 6: 44.1, 4.0 Lot 7: 50.7, 5.2 Lot 8: 45.2, 2.8 Lot 9: 60.1, 3.8 2.5 3.4 4.3 5.2 42 50 60 Hunter L lightness Consumer panel score
All nine lots. The positive tendency is neither a perfectly straight line nor a perfectly preserved ordering; the scatterplot makes that visible before either coefficient is calculated.

Pearson asks how closely the points follow a line

Pearson correlation standardizes the covariance of the two measured variables. For these values, r = 0.5712, with R² = 0.326, an approximate 95% confidence interval from −0.1497 to 0.8956, and a two-sided P = 0.1082.

Here R² describes squared linear association in this sample. It does not show that lightness causes panel preference, establish agreement between two measurement methods, or mean that 32.6% of a biological mechanism has been explained.

Spearman asks how closely the ordering is preserved

With no tied values, replace each column by ranks and compute ρ = 1 − 6Σd²/[n(n²−1)]. The nine rank differences have Σd² = 48, so ρ = 0.6000. Plotwright reports its t-approximation two-sided P = 0.08762 and approximate Fisher-z 95% interval −0.1066 to 0.9039.

Small-sample convention matters: R's source example pre-specifies a positive, one-sided alternative and uses its AS 89 small-sample procedure. The linked Plotwright project deliberately opens with a two-sided Spearman analysis; this guide labels Plotwright's t approximation explicitly. Do not compare P values without matching method, tails, tie handling and approximation.

A better Pearson-versus-Spearman checklist

  • Scientific target: Pearson quantifies linear covariation; Spearman quantifies monotonic rank association.
  • Measurement scale: meaningful ranks can support Spearman; interpretable numeric spacing can support Pearson.
  • Scatterplot: look for curvature, clusters, changing spread, restricted range and influential observations before summarizing.
  • Independence: repeated observations from the same subject or batch are not made independent by ranking them.
  • Inference: state tails, confidence level, exact or approximate method, and how ties or missing pairs were handled.

A normality test can inform diagnostics, but its P value does not define the research question. Spearman is also not an automatic outlier repair: ranking reduces the impact of marginal magnitude, yet influential bivariate observations can still matter.

Neither is a universal relationship detector: a strong U-shaped relationship can have Pearson and Spearman coefficients near zero. Plot the paired values; a non-significant coefficient is not evidence that every form of association is absent.

A compact reporting template

“Association between Hunter L lightness and mean panel score across nine tuna lots was summarized with a two-sided Spearman rank correlation because monotonic ordering was the stated estimand. The association was positive but imprecise (ρ = 0.600, approximate 95% CI −0.107 to 0.904; t-approximation P = 0.0876). All paired observations were shown in the scatterplot.”

If linear association was the pre-specified target instead, report Pearson's r and its interval, explain why the linear model was plausible, and retain the scatterplot.

What Plotwright checks

Plotwright submits all nine pairs to the production correlation engine. The published-example gate independently reconstructs Pearson's r from centered cross-products and Spearman's ρ from the rank identity with Σd² = 48, then checks the displayed coefficients and P-value convention.

Those checks establish the defined calculations. They cannot establish independent sampling, select a scientific estimand, diagnose every influential observation or turn association into causation.

Historical-data caveat: this nine-lot example is a calculation and interpretation benchmark. Its excerpt does not provide enough sampling or sensory- study context for a modern food-science conclusion.

Sources and reproducibility

  1. R stats documentation: cor.test—the complete tuna values, directional example, supported coefficients and small-sample inference conventions.
  2. NIST/SEMATECH: scatter plots—checking linearity, nonlinearity, changing variation, outliers and the limits of causal interpretation.
  3. Statistical notes for clinical researchers: correlation—the linear-versus-monotonic distinction and rank formulation.
  4. Plotwright statistical validation—published expected values, tolerances and evidence limits.

Keep the raw pairs, scatterplot and coefficient together.

Plotwright opens the complete nine-lot dataset, a two-sided Spearman analysis and an editable scatterplot in one local project.