Pearson correlation coefficient
The Pearson correlation coefficient (Pearson’s r, or the product-moment correlation) is the standard measure of how closely two continuous variables follow a straight line. It’s the most common form of correlation, used for questions such as “Is study time related to exam score?” or “Does blood pressure rise with age?”.
What r measures
r runs from −1 (a perfect negative line) through 0 (no linear relationship) to +1 (a perfect positive line). It’s calculated as the covariance of the two variables divided by the product of their standard deviations:
r = Σ(x − x̄)(y − ȳ) / √[Σ(x − x̄)² × Σ(y − ȳ)²]
Each case contributes positively when it’s above average on both variables or below average on both, and negatively when it’s above on one and below on the other. Dividing by the SDs removes the units, so r is the same whether you measure in kilograms or pounds.
Hypotheses
- H₀: there is no linear relationship in the population (ρ = 0).
- H₁: there is a linear relationship (ρ ≠ 0).
The test converts r into a t statistic with n − 2 degrees of freedom: t = r√(n − 2) / √(1 − r²).
Assumptions
- Both variables are continuous, measured on the same cases.
- Independent cases: no repeated measurements of the same person.
- Linearity: the relationship follows a straight line, not a curve. Check with a scatterplot.
- Approximate normality of each variable. This matters mostly for the p-value and confidence interval, especially in small samples.
- No dominating outliers: a single extreme point can create or hide a correlation.
If the relationship is curved but consistently rising or falling, or the data are ordinal or skewed, use Spearman’s rank correlation instead.
Worked example: car weight and fuel economy
The mtcars dataset (built into R) has data on 32 cars from a 1974 issue of Motor Trend. Are heavier cars less fuel-efficient?
Step 1: check the assumptions
- Normality: D’Agostino-Pearson p = .257 for mpg and .391 for weight, so no evidence of non-normality.
- Linearity: a Ramsey RESET test, which checks whether adding curved terms improves a straight-line fit, gives p = .056, so no strong evidence of curvature. (Analytika reroutes to Spearman when this test gives p < .01.)
Step 2: run the test
Pearson r: -0.8677 P-value: 1.294e-10 N: 32 df: 30 95% CI: [-0.9338, -0.7441] Influential points (Cook's D > 4/n): 5 Pearson r (excl. influential): -0.8826 P-value (excl. influential): 1.136e-09 Rows excluded for missing values: 0 of 32
> cor.test(mtcars$mpg, mtcars$wt)
Pearson's product-moment correlation
data: mtcars$mpg and mtcars$wt
t = -9.559, df = 30, p-value = 1.294e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.9338264 -0.7440872
sample estimates:
cor
-0.8676594Same r, p and confidence interval. (R reports the t statistic, and Analytika reports r directly.) Analytika’s test suite checks this case against R on every change.
Step 3: interpret
- r = −.87: a very strong negative relationship. Heavier cars get fewer miles per gallon.
- r² = .75: weight and fuel economy share about 75% of their variance.
- p < .001, 95% CI [−.93, −.74]: even the weakest plausible value is a strong correlation.
- Influential points: five cars have a large influence on the fit (Cook’s distance above 4/n). Without them, r = −.88. The result doesn’t depend on them.
Step 4: report it (APA 7)
Car weight and fuel economy were strongly negatively correlated, r(30) = −.87, p < .001, 95% CI [−.93, −.74].
The number in brackets is the degrees of freedom (n − 2). Correlations can’t exceed 1, so APA style drops the leading zero. Say “associated” or “correlated”, not “caused”. This is observational data, and engine size, for example, affects both weight and fuel use.
Correlation matrices and multiple tests
With many variables, researchers often report a correlation matrix. Testing 10 variables means 45 correlations, and at α = .05 you’d expect two or three to be significant by chance alone. Use a correction such as Holm or Bonferroni, or be clear that the analysis is exploratory.
Common mistakes
- Not plotting the data. A curve, two separate clusters or one outlier can all produce a misleading r.
- Reading r as a slope. r = .8 doesn’t mean y rises 0.8 units per unit of x. For that, use regression.
- Restricting the range. Correlating SAT scores with grades among admitted students only (all of whom scored highly) understates the correlation in the full population.
- Causal language for observational data.
How to run it
- SPSS: Analyze → Correlate → Bivariate, then tick Pearson.
- R:
cor.test(df$x, df$y) - Python:
scipy.stats.pearsonr(x, y) - Analytika: ask whether the two variables are related. It checks normality and linearity, chooses Pearson or Spearman, and flags influential points.
More in Correlation
Try it with the free tools
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.