Explore

Correlation tests: Pearson and Spearman

H₀: ρ = 0 · H₁: ρ ≠ 0

Your result lies beyond the edge of the chart; it is marked at the edge.

r = 0.8474 · df = 78 · p = 3.80E-23

p = 3.80E-23 ≤ α = 0.05: reject H₀. The two variables move together more than chance alone would easily produce (r = 0.8474); correlation is not causation.

How to read the picture

  • The curve is the null world of t: how the correlation's t would vary if the true correlation were 0.

  • The vertical line is your t = r √(n − 2) / √(1 − r²).

  • The shaded tail is the p-value; the lighter region is where t must land to reject at α.

  • Below, r with Fisher's interval: an interval that excludes 0 goes with a rejection.

Your data

Test

Data

Download this dataset (CSV)

Alternative hypothesis

Significance level α

When both variables are numbers measured on the same units, the question is whether they move together. Pearson's r measures a straight-line relationship; Spearman's ρ is Pearson's r on the ranks, so it catches any one-directional relationship and shrugs off outliers. Each becomes a t statistic on n − 2 degrees of freedom.

The estimate and what the data show

The estimate with its interval Pearson's r (Fisher's interval): 0.85 [0.77, 0.90]. no correlation. no correlationPearson's r (Fisher's interval) 0.85 [0.77, 0.90] −0.2 −0.0 0.2 0.4 0.6 0.8 1.0correlation

The worked steps

  1. Sums of squares and products

    n = 80 · Sxx = 7058.4839 · Syy = 8322.7769 · Sxy = 6494.9494
  2. The correlation

    r = Sxy / √(Sxx Syy) = 0.8474
  3. The t statistic

    t = r √(n − 2) / √(1 − r²) = 0.8474 × √78 / √(1 − 0.8474²) = 14.0951
  4. Degrees of freedom

    df = n − 2 = 78
  5. The p-value

    p = 2 × P(T ≥ |14.0951|) = 3.80E-23
  6. Critical value at α, as a correlation

    α = 0.05: r* = ±0.2199
  7. Share of variation explained

    r² = 0.7181
  8. Fisher's interval for the correlation

    95 %: [0.7713, 0.8996]

The same in code

scipy
from scipy import stats

result = stats.pearsonr(x, y, alternative='two-sided')
result.statistic, result.pvalue, result.confidence_interval(0.95)
Excel
B1: =CORREL(A2:A81, B2:B81)
B2: =B1*SQRT(78)/SQRT(1-B1^2)
B3: =T.DIST.2T(ABS(B2), 78)
Excel's CORREL gives r; the t test is by formula. Spearman's ρ is CORREL on the RANK.AVG columns (enter it as an array formula in older Excel).

Formulas

S_xy adds the products of each pair's distances from the two means; t turns r into a test on n − 2 degrees of freedom, and Fisher's z gives the interval.

Try this

  1. Outliers and ranks

    Open the ten points with one outlier and switch between Pearson and Spearman.

    Look for: One point far from the rest makes Pearson's r large and significant; on ranks it is only the largest value, and ρ stays modest. Plot the data before trusting r.

  2. Small samples, wide intervals

    Type five pairs that rise together, for example x = 1, 2, 3, 4, 5 and y = 2, 1, 4, 3, 5.

    Look for: r = 0.8 looks strong, but with five pairs Fisher's interval runs from well below 0 to nearly 1 and the test does not reject.

  3. Correlation is not pairing's whole story

    Open Helion's agents with Pearson and read r, then open the two-means explorer's paired preset for the same agents.

    Look for: The strong correlation between before and after is what makes the paired test so much sharper than treating the agents as two groups: the busy stay busy, and pairing takes that out.

An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to Hypothesis Testing Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.