Correlation coefficient and simple regression by hand
How to calculate Pearson r from a small dataset, read its sign and size, and fit and interpret a straight-line prediction.
Correlation measures how closely two columns of numbers move together. Simple regression goes one step further and gives a line you can use to predict one from the other. Analyst screenings ask you to compute r from five or six pairs, interpret a slope, or spot the misuse. The arithmetic is short if you set it out in a table.
Calculating Pearson r
For pairs (x, y): find the mean of x and the mean of y, then for each pair compute dx = x − mean(x) and dy = y − mean(y). Then r = sum(dx × dy) divided by the square root of (sum(dx²) × sum(dy²)).
Example 1: hours studied and test score for five people: (1, 50), (2, 55), (3, 65), (4, 70), (5, 85). Mean x = 15/5 = 3. Mean y = 325/5 = 65.
x y dx dy dx*dy dx² dy²
1 50 -2 -15 30 4 225
2 55 -1 -10 10 1 100
3 65 0 0 0 0 0
4 70 1 5 5 1 25
5 85 2 20 40 4 400
sums 85 10 750
r = 85 / sqrt(10 × 750) = 85 / sqrt(7500) = 85 / 86.60 = 0.98. A strong positive correlation.
Reading r
r runs from −1 to +1. The sign gives direction; the size gives strength. r measures straight-line relationships only; a perfect U-shape can give r near 0. r² (here 0.96) is the share of variation in y that the line explains.
Fitting the line
The regression line is y = a + b × x. Slope b = sum(dx × dy) / sum(dx²). Intercept a = mean(y) − b × mean(x).
Using example 1: b = 85/10 = 8.5. a = 65 − 8.5 × 3 = 65 − 25.5 = 39.5. Line: score = 39.5 + 8.5 × hours. Interpretation: each extra hour of study is associated with 8.5 more marks on average. Prediction for 3.5 hours: 39.5 + 29.75 = 69.25.
Example 2: predict for 12 hours: 39.5 + 102 = 141.5, which is above the maximum possible score. The data only covered 1 to 5 hours. Predicting outside that range (extrapolation) is not supported by the line.
Common mistakes and a practice habit
- Forgetting to subtract the means and multiplying raw x and y.
- Taking the square root of each sum separately instead of the square root of the product.
- Reading a strong r as proof of cause. Two things that both rise in summer are correlated without one causing the other.
Pick five pairs from anything you measure, such as steps and hours of sleep. Build the seven-column table, compute r, b and a by hand, then check with a spreadsheet's CORREL and SLOPE functions. When the hand result matches to two decimals, you are test-ready.
More in Data and AI