Sub topic 11
Is the correlation different from zero?
This chapter assumes you can compute a sample correlation, you know the t-test workflow (state hypotheses, compute a statistic, compare with a critical value), and you know what degrees of freedom are. Here you apply that workflow to a sample correlation coefficient.
Why a sample correlation needs a test
A sample correlation, r, is computed from a sample, so it varies from sample to sample. Two series that are truly unrelated in the population will still produce an r that is not exactly zero. The question is whether the r you observed is far enough from zero that sampling noise is an unlikely explanation.
The population correlation is written ρ (rho). The test asks whether ρ = 0.
The hypotheses
- Null hypothesis: H0: ρ = 0 (no linear relationship in the population).
- Alternative, two-tailed: Ha: ρ ≠ 0. This is the usual choice when you have no prior view on direction.
- Alternative, one-tailed: Ha: ρ > 0 or Ha: ρ < 0. Use it only when theory fixes the sign before you see the data.
The test statistic
The test statistic is:
t = r · √(n − 2) / √(1 − r²)
It follows a t-distribution with n − 2 degrees of freedom under H0. Two degrees of freedom are lost because the calculation uses the sample means of both variables.
The statistic grows with |r| and with n. A given r is therefore more convincing in a larger sample, and a given sample size makes a larger |r| more convincing.
The test assumes the two variables are approximately bivariate normal. It also assumes the observations are independent of each other, which is often violated by time series.
Worked example 1: reject
An analyst finds r = 0.45 between a fund's monthly returns and a factor's returns over n = 30 months.
- H0: ρ = 0. Ha: ρ ≠ 0. Significance level 5%, two-tailed.
- Degrees of freedom: 30 − 2 = 28.
- t = 0.45 × √28 / √(1 − 0.2025) = 0.45 × 5.2915 / 0.8930 ≈ 2.67.
- Critical value: ±2.048 for 28 degrees of freedom.
- Since 2.67 > 2.048, reject H0. The correlation is statistically different from zero.
Worked example 2: fail to reject
With r = 0.30 and n = 20, the statistic is t = 0.30 × √18 / √0.91 ≈ 1.33. The critical value for 18 degrees of freedom is ±2.101. Since 1.33 < 2.101, you fail to reject H0.
Failing to reject does not show that ρ = 0. It says only that this sample does not provide enough evidence against it.
Worked example 3: large sample, small correlation
Take r = 0.10 and n = 1,000. Then t = 0.10 × √998 / √0.99 ≈ 3.18. The critical value is about ±1.96, so you reject H0.
A correlation of 0.10 explains only 1% of the variation in one variable (r² = 0.01). The result is statistically significant but of little practical value. Always report the size of r alongside the test result.
The critical correlation
You can solve the test for the smallest |r| that leads to rejection:
rcrit = tcrit / √(t_crit² + n − 2)
For n = 30 at the 5% two-tailed level, tcrit = 2.048, so rcrit = 2.048 / √(4.194 + 28) ≈ 0.361. Any sample correlation with |r| above about 0.36 is significant in that sample size. The table below shows how the threshold falls as n grows (5% level, two-tailed).
| n | Degrees of freedom | Critical t | Approximate critical \ | r\ | Column |
|---|---|---|---|---|---|
| 10 | 8 | 2.306 | 0.632 | ||
| 20 | 18 | 2.101 | 0.444 | ||
| 30 | 28 | 2.048 | 0.361 | ||
| 100 | 98 | 1.984 | 0.197 |
Decision flow
Checking the calculation in Python
The code computes t from r and n by hand, then compares it with scipy.stats.pearsonr. Both use the same t-distribution, so the two p-values agree.
import numpy as np
from scipy import stats
x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])
y = np.array([2.0, 1.5, 3.5, 3.0, 5.5, 4.0, 6.5, 7.0])
n = len(x)
r = np.corrcoef(x, y)[0, 1]
t_manual = r * np.sqrt(n - 2) / np.sqrt(1 - r ** 2)
p_manual = 2 * stats.t.sf(abs(t_manual), df=n - 2)
t_crit = stats.t.ppf(1 - 0.05 / 2, df=n - 2)
r_scipy, p_scipy = stats.pearsonr(x, y)
print(r, r_scipy)
print(t_manual, t_crit)
print(p_manual, p_scipy)
print("Reject H0" if abs(t_manual) > t_crit else "Fail to reject H0")Link to regression
In simple linear regression, the t-test of the slope uses the same statistic and the same n − 2 degrees of freedom. Testing H0: ρ = 0 and testing H0: slope = 0 give identical t-values and p-values. Later chapters on slope inference rely on this equivalence.
Common errors
- Reading correlation as causation. A significant r shows that two variables move together. It does not show that one drives the other.
- Spurious correlation. Two series can correlate because of a shared trend or by chance. Testing many pairs and reporting the significant ones will produce false positives at roughly the significance rate.
- Outliers. One extreme point can create or destroy a correlation. Inspect a scatter plot before trusting r.
- Nonlinear relationships. r measures only linear association. A strong curved relationship can give r near zero.
- Confusing significance with strength. Example 3 shows a tiny r passing the test in a large sample.
- Wrong degrees of freedom. Use n − 2, not n − 1. The n − 1 version belongs to the single-mean t-test.
- Dividing by zero at |r| = 1. The formula breaks down for a perfect correlation. This case does not arise with real noisy data.
Practice
Exercise
A sample of n = 25 observations gives r = −0.52. Test H0: ρ = 0 against Ha: ρ ≠ 0 at the 5% level. The critical t for 23 degrees of freedom is ±2.069.
Show answer
t = −0.52 × √23 / √(1 − 0.2704) = −0.52 × 4.7958 / 0.8542 ≈ −2.92. Since |−2.92| > 2.069, reject H0. The correlation is significantly different from zero.
Exercise
Why can r = 0.10 be significant when n = 1,000 but a correlation of 0.30 fail the test when n = 20? What does this say about interpreting the test?
Show answer
The t-statistic depends on both r and n through √(n − 2). A large sample shrinks the standard error of r, so even a small r gives a large t. A small sample leaves a wide standard error, so even a moderate r can fall short of the critical value. Significance shows only that the sample provides evidence against ρ = 0. It does not show that the relationship is strong or useful, so the size of r (and r²) must be judged separately.