Correlation & Regression Lab
Drag points. Every (x − x̄)(y − ȳ) rectangle is one term of the covariance; blue rectangles push r up, red ones pull it down. The line minimises the sum of the orange squares.
Points (x, y, residual)
1e = -8.2
2e = 1.6
3e = -4.5
4e = -13.1
5e = 7.9
6e = 10.5
7e = 7.2
8e = 6.6
9e = -5.8
10e = -1.4
11e = -3.9
12e = 12.2
13e = -0.5
14e = -1.1
15e = 10.6
16e = 7.1
17e = -17.7
18e = -0.3
19e = -9.2
20e = 1.8
Pearson r and its t-test, Spearman ρ on average ranks, OLS by normal equations with classical SEs (statsmodels-equivalent), logistic by IRLS. Synthetic data, seeded; the 'outlier' preset plants one high-leverage point by hand.
r = 0.910, b = 5.10, R² = 0.828
Formula
r = Σ(xᵢ−x̄)(yᵢ−ȳ) / √(Σ(xᵢ−x̄)² Σ(yᵢ−ȳ)²)b = r · s_y/s_xa = ȳ − b x̄t = r√(n−2)/√(1−r²)
One far point in the corner can dominate both r and b: leverage grows with (x − x̄)². Spearman only sees ranks, so it barely moves.