Correlation Analysis
Understand correlation coefficients, their interpretation, and limitations. Learn Pearson, Spearman, and point-biserial correlations.
On This Page
Pearson’s r measures linear association
Pearson’s sample correlation r measures the direction and strength of a linear relationship between two numerical variables observed in pairs. It ranges from −1 to 1 when both variables have nonzero variation.
A positive r means larger X values tend to accompany larger Y values; a negative r means larger X values tend to accompany smaller Y values. An r near zero indicates little linear association, not necessarily no relationship.
Before calculating, plot the pairs. A curved relationship, one influential point, or a mixture of groups can make one coefficient misleading. Start with reading scatter plots if the graphical interpretation is unfamiliar.
Calculate r from raw data
For paired values (xᵢ, yᵢ):
Use the same five illustrative pairs as the linear regression lesson:
| x | y | x − x̄ | y − ȳ | Product |
|---|---|---|---|---|
| 2 | 65 | −4 | −15 | 60 |
| 4 | 75 | −2 | −5 | 10 |
| 6 | 80 | 0 | 0 | 0 |
| 8 | 88 | 2 | 8 | 16 |
| 10 | 92 | 4 | 12 | 48 |
Here x̄ = 6, ȳ = 80, Σ(x − x̄)² = 40, Σ(y − ȳ)² = 458, and the cross-product sum is 134.
Paste X = 2,4,6,8,10 and Y = 65,75,80,88,92 into the correlation calculator. Keep each row’s X and Y together. Independently sorting the columns creates different pairs and changes the analysis.
What is invariant, and what is not?
Changing units by a positive scale factor, such as meters to centimeters, does not change r. Adding a constant does not change it either. Multiplying one variable by a negative constant reverses the sign.
The regression slope is different: its units matter. In these data, the slope is 3.35 score points per X unit, while r is dimensionless. Swapping X and Y leaves r unchanged but changes the regression equation.
If either variable is constant, the denominator is zero and Pearson’s r is undefined. Reporting r = 0 would incorrectly suggest observed variation with no linear association.
r² and regression
With simple least-squares regression including an intercept, R² = r². In the example, r² ≈ 0.9801: the fitted line accounts for about 98.01% of the sample’s variation in Y around its mean.
“Accounts for” describes a model fit. It does not mean X causally generates that percentage of Y’s variation, and the remaining variation is not automatically attributable to particular other variables. A high in-sample R² is not proof of good prediction on new data.
Test a population correlation under a model
For independent pairs from a bivariate normal population, testing H₀: ρ = 0 uses:
Using the unrounded r in the example gives t ≈ 12.1651, df = 3, and two-sided p ≈ 0.0012. Avoid rounding r to 0.99 before calculating; the denominator can be sensitive when |r| is close to 1.
The p-value concerns compatibility with the zero-correlation model. It does not measure the size of an effect or make five teaching observations representative of a larger population. The calculation and the inferential assumptions are separate.
For time series, repeated observations of the same person, or clustered pairs, the simple independent-pair test can be misleading. Bivariate normality is a model for this classical exact test, not a requirement merely to compute the sample coefficient.
Causation, confounding, and selection
Ice cream sales and swimming incidents can both increase in hot weather. A positive association does not establish that sales cause incidents. A third variable can affect both, causation can run in the opposite direction, and selective sampling can produce misleading associations.
Pooling different groups can also reverse or distort a within-group pattern. Inspect relevant group labels and ask why observations appear in your sample before drawing conclusions.
Choose an appropriate alternative
Spearman correlation measures association between ranks and is useful for a monotonic relationship. It does not capture every nonlinear relationship and does not establish causality. Strongly curved, U-shaped data may have both Pearson and Spearman coefficients near zero despite clear structure.
There is no universal r threshold that makes an association “useful.” A small association may matter in one setting and a large one may be uninformative in another. Consider units, uncertainty, prediction error, and the scientific question.
Practice
1. If r = −0.8, what is r²? Does the sign tell you the regression direction?
Show the explanation
r² = 0.64. For a simple least-squares line with nonconstant variables, the slope has the same negative sign as r. R² loses that sign and describes fit, not causation.
2. X values are −2, −1, 0, 1, 2 and Y = X². Is r = 0 evidence of no relationship?
Show the explanation
No. The centered cross-products cancel, so r is 0, but Y is completely determined by a curved function of X. A scatter plot makes the relationship visible immediately.
Reference and next steps
The official SciPy Pearson correlation documentation describes the coefficient and the classical null distribution. Continue with linear regression to fit and interpret a predictive line.
Check your understanding
Choose an answer, then check the explanation. These are practice questions, not a certification or graded assessment.
0 of 2 answered
Did this explanation help?
Your response helps us identify lessons that need more work.