Skip to course content
Free Python statistics course

Statistical Data Analytics with Python

Unit 08.00: A correlation near zero means no straight line

A correlation near zero does not mean no relationship. It means no straight-line relationship.

Plot it, then quote it

Correlation measures the strength of a linear association. A strong curved relationship — a U shape, a threshold, a saturation curve — can produce a correlation of nearly zero while being entirely predictable.

It is also extremely sensitive to individual points. A single observation far from the rest can create a large correlation where none exists among the bulk of the data, or destroy a real one.

Both failures are invisible in the number and obvious in the scatter plot, which is why the plot comes first and the coefficient second — always in that order.

This block correlates a linear relationship, a U-shaped one, and then adds a single distant point to unrelated data.

import numpy as np
from scipy import stats

rng = np.random.default_rng(501)
x = rng.uniform(0, 10, 120)
linear = 2 * x + rng.normal(0, 3, 120)
curved = (x - 5) ** 2 + rng.normal(0, 3, 120)

print(f"Linear relationship,   correlation: {stats.pearsonr(x, linear)[0]:.3f}")
print(f"U-shaped relationship, correlation: {stats.pearsonr(x, curved)[0]:.3f}")
print("\nThe second correlation is near zero and the relationship is strong --")
print("correlation measures STRAIGHT-LINE association only.\n")

x2 = np.append(rng.normal(5, 1, 40), 20.0)
y2 = np.append(rng.normal(5, 1, 40), 20.0)
print(f"40 points with no relationship : {stats.pearsonr(x2[:40], y2[:40])[0]:.3f}")
print(f"The same 40 plus one far point : {stats.pearsonr(x2, y2)[0]:.3f}")
print("\nOne row in 41 manufactured a strong correlation out of nothing.")
print("Always plot before quoting a correlation -- neither failure is visible")
print("in a correlation matrix of numbers.")

The linear relationship gives 0.906. The U-shaped one — strong, obvious in a plot, perfectly predictable — gives −0.002, essentially zero. Then forty points with no relationship correlate at 0.051; adding one distant observation takes that to 0.865. A single row manufactured a strong correlation out of nothing.

The mistake this prevents

The mistake is computing df.corr() over many variables and reading off the large values. Neither curvature nor a single influential point is visible in a matrix of numbers.

Takeaway

Plot every relationship before quoting its correlation. Treat a near-zero coefficient as evidence about linearity only, and check whether any single point is driving a large one.