Skip to content

CAssociation · Guide test 077

Pearson correlation test

Tests a specified linear correlation, commonly zero, with calibration depending on distributional assumptions.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

In Correlation test (Pearson / Spearman / Kendall), choose Coefficient = Pearson r (linear).

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Pearson correlation test

30
0.40
0.050

Alternative

The statistic's distribution if the design's true effect is real.

Your data

Simulated with a known ρ

If H₀ were true

t = 2.11
  1. The reference: how t varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .044).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

t=rn−21−r2,ν=n−2t = r\sqrt{\dfrac{n-2}{1-r^2}},\qquad \nu = n-2

With your numbers

t=0.3730−21−0.372=2.11,ν=28t = 0.37\sqrt{\dfrac{30-2}{1-0.37^2}} = 2.11,\qquad \nu = 28
rr
the sample correlation
nn
the number of pairs

The verdict

t(28) = 2.11, p = .044, r = 0.37

p ≤ α = .050: reject H₀

Effect size: Pearson correlation r = 0.370

Tests ρ = 0 for a straight-line association; a curved or outlier-driven pattern can hide behind any r. Always look at the scatter.

Statistic
2.106
p-value
0.0443
Pearson correlation test on 30 (x, y) pairs: t(28) = 2.11, p = .044, r = 0.37. The p-value is below α = .050, so the data are hard to reconcile with H0.

Pearson correlation test on 30 (x, y) pairs: t(28) = 2.11, p = .044, r = 0.37. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: population Pearson correlation ρ=0.

Assumptions

Independent paired quantitative observations; bivariate normality gives the exact t reference. Linear association and finite variances are required for its interpretation.

Formula

r=∑i(xi−xˉ)(yi−yˉ)∑i(xi−xˉ)2∑i(yi−yˉ)2t=rn−21−r2\begin{gathered}r=\frac{\sum_i(x_i-\bar x)(y_i-\bar y)}{\sqrt{\sum_i(x_i-\bar x)^2\sum_i(y_i-\bar y)^2}}\\[5pt] t=r\sqrt{\frac{n-2}{1-r^2}}\end{gathered}

Parameters and notation

n is the paired sample size; reference df=n−2.

Structure of the method

Center both variables, normalize their cross-product by their sample sums of squares, and transform the resulting correlation into a t statistic for the zero-correlation null. Under independent bivariate-normal observations, this reference is equivalent to the usual beta distribution of sample correlation.

Estimated and nuisance parameters

Estimate two means, two marginal scales, and the sample covariance or correlation. Sample size counts complete matched observations, not the combined lengths of the two vectors. A zero-variance variable makes the correlation undefined; its numerical value should not be patched to zero.

Settings and design choices

Prespecify directional versus two-sided inference, missing-pair handling, transformations, and any multiplicity across a correlation matrix. A nonzero population-correlation null requires a different calibration. Distinguish testing correlation from fitting a predictive regression or assessing absolute agreement.

Fitting and adaptation

Recompute centering and correlation for each new independent sample. Permuting one variable can test independence under exchangeability, a stronger null than zero correlation outside the Gaussian setting. Bootstrap whole pairs for a suitable interval; never resample each variable independently when estimating sampling uncertainty.

Sensitivity and robustness

Outliers, range restriction, nonlinear patterns, and near-constant variables can dominate or obscure correlation. Repeated or serial pairs violate the independent-observation reference. Inspect the scatterplot and report an interval; a small p-value can accompany weak predictive utility.

How to use and calibrate

Use a t tail for zero correlation. A Fisher transformation or other appropriate procedure tests a nonzero ρ0.

Example application

Test whether two continuous measurements have a linear association.

Interpretation and pitfalls

Watch out

Zero correlation is not general independence. Outliers, nonlinear dependence and repeated observations can mislead.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Paired observations, two-sided association test. Ties and exact-versus-asymptotic settings can cause small cross-language differences.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
print(stats.pearsonr(x,y))
Output
PearsonRResult(statistic=np.float64(0.5374861883945781), pvalue=np.float64(0.10908734453243193))
R

Validated — Executed successfully in the validation environment · needs Base/standard library

x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(cor.test(x,y,method="pearson"))
Output
	Pearson's product-moment correlation

data:  x and y
t = 1.8028, df = 8, p-value = 0.1091
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.1392719  0.8720106
sample estimates:
      cor 
0.5374862

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 077, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT077.