Statisticsdrill

Regression and correlation Updated November 2026

Correlation coefficient (Pearson r)

The Pearson correlation coefficient r measures the strength and direction of a straight-line relationship between two variables, from -1 to 1: r = sum((x - x-bar)(y - y-bar)) / sqrt(sum((x - x-bar)^2) * sum((y - y-bar)^2)). Values near 0 mean no linear relationship.

Syntax

r = Sxy / sqrt(Sxx * Syy)
PartWhat it is
Sxysum of (x - x-bar)(y - y-bar)
Sxxsum of (x - x-bar)^2
Syysum of (y - y-bar)^2

Examples

x: 1, 2, 3, 4, 5  (x-bar = 3)
y: 2, 4, 5, 4, 5  (y-bar = 4)
Sxy = (-2)(-2) + (-1)(0) + 0 + (1)(0) + (2)(1) = 6
Sxx = 10, Syy = 6
r = 6 / sqrt(60)

Result: r = 0.775

Excel: =CORREL(A1:A5, B1:B5) or =PEARSON(A1:A5, B1:B5)

x: 1, 2, 3, 4, 5; y: 2, 4, 6, 8, 10 (exact line, slope 2)

Result: r = 1

x: 1, 2, 3; y: 3, 2, 1

Result: r = -1

Test whether r = 0.775 from n = 5 is significant
t = r * sqrt(n - 2) / sqrt(1 - r^2) = 0.775 * 1.732 / 0.632

Result: t = 2.12, df = 3, two-sided p = 0.12

Common mistakes

  • Reading r = 0.8 as 80% of the variation explained; that is r^2 = 0.64.
  • Reporting a strong r as proof of cause; correlation can come from a third variable or coincidence.
  • Using Pearson r for a curved relationship; it only measures straight-line association, so plot the data first.

Practice Correlation coefficient (Pearson r)

These drills check your answer on live data, free, no account needed.

  • Correlation coefficientData on monthly ad spend and sales at regional stores (x = Ad spend ($k), y = Sales ($k)): (9, 87.8), (10, 98.7), (6, 81.3), (12, 99.1), (15, 111.9), (6, 78.6). What is the correlation coefficient r? Round to 3 decimal places.
  • Testing a correlationIn a sample of 10 stores, the correlation between staff hours and customer satisfaction scores is r = 0.24. Find the t statistic for H0: ρ = 0, then decide (two-sided) at α = 0.1. Round to 2 decimal places.

Questions

What is a strong correlation?

Rules of thumb: |r| below 0.3 weak, 0.3 to 0.7 moderate, above 0.7 strong. The right threshold depends on the field; in physics 0.7 is weak, in social science it is strong.

What is the difference between correlation and covariance?

Covariance is in the units of x times y and can be any size. Correlation is covariance divided by both standard deviations, which makes it unitless and bounded between -1 and 1.

When should I use Spearman instead of Pearson?

When the relationship is monotonic but not linear, when the data is ranked, or when outliers distort Pearson r. Spearman is Pearson r computed on the ranks.

Related

  • CovarianceHow to calculate sample and population covariance, a worked example with exact numbers, how covariance becomes correlation, and Excel COVARIANCE.S and .P.
  • Linear regressionHow to fit a regression line y = a + bx: slope b = Sxy / Sxx, intercept a = y-bar - b x-bar, a worked example, prediction and Excel SLOPE and INTERCEPT.
  • R-squaredR-squared is the share of variation in y explained by the regression, 1 - SSE / SST. Worked example with exact numbers, link to r, Excel RSQ and its limits.
  • OutliersHow to detect outliers with the 1.5 IQR fence rule and the z-score rule, worked examples with exact fences, and what to do with outliers once found.

Previous: Statistical powerNext: Linear regression