Correlation

Pearson's correlation measures the direction and strength of a linear relationship between two numerical variables.

r = R² =

With one (numerical) predictor and an intercept,

where are the standard deviations of .

In general, correlation is not the slope: the slope has units and changes when you change measurement units. Correlation is unitless. Swapping and leaves correlation unchanged, but changes which regression is being fit.

R-squared: R² = r²

The fitted line minimizes the sum of squared vertical residuals. Compare that error with predicting the sample mean for everyone:

only in the case of linear regression with one (numeric) predictor.

Correlation measures linear relations

A correlation near zero can be a poor summary of a striking nonlinear pattern. In both examples below, is determined exactly by , but the upward and downward parts cancel in the linear correlation.

Large positive and negative x both give large y. The horizontal line misses the U-shaped relationship.

The peaks and troughs are perfectly predictable from x, but a straight line captures none of that structure.

The dashed lines are the least-squares straight lines. Their values still equal ; the identity holds even when a line is a bad model. A model using the correct curve would fit these noiseless data perfectly, with .

The numbers are not mathematically meaningless: they correctly report almost no linear association. They become misleading when treated as measures of every kind of relationship. Always inspect the scatter plot. Zero correlation does not imply independence.

For more on fitting regression models, see Linear Models.