Mathematics · Simulator 051
Tap to add data points, drag them around, and watch the best-fit line respond. See the residuals (the vertical misses), the squared errors the line minimises, and how a single outlier can swing the whole fit.
Class 11–12CollegeClass 11 Economics: Statistics for Economics (correlation); regression is college level
Ordinary least squares chooses the line ŷ = a + bx that minimises the sum of squared residuals Σ(yᵢ − ŷᵢ)²:
b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)², a = ȳ − b x̄
R² is the fraction of the variation in y explained by the line (1 = perfect, 0 = none); it equals the squared correlation r². Squaring the residuals means points far from the line pull very hard. An outlier with an extreme x value (high leverage) can drag the slope a long way.
The optional squares view draws each squared residual as an actual square, so you can see what “least squares” minimises. The robust option fits with least absolute deviations instead (iteratively reweighted), which is much less sensitive to outliers.
Correlation is not causation, and a straight line can fit curved data badly. Always look at the residuals.
Four points: (0, 1), (1, 3), (2, 5), (3, 7). What are the slope, intercept and R²? Now drag (3, 7) up to (3, 11). How does the slope change?
The points lie exactly on y = 1 + 2x, so b = 2, a = 1 and R² = 1. Moving the last point to y = 11 adds 4 to one y value: the slope rises by 4 × (3 − 1.5)/Σ(x − x̄)² = 6/5 = 1.2, to 3.2, and R² drops below 1. Enter the points with “Clear” and tap to check.
Data: (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). Means: x̄ = 3, ȳ = 4.
Slope: Σ(x − x̄)(y − ȳ) = 4 + 0 + 0 + 0 + 2 = 6 and Σ(x − x̄)² = 10, so b = 0.6. Intercept: a = 4 − 0.6 × 3 = 2.2. The line is ŷ = 2.2 + 0.6x.
Residuals: −0.8, 0.6, 1.0, −0.6, −0.2. They sum to zero, as least-squares residuals always do.
R²: squared residuals add to 2.4, total variation Σ(y − ȳ)² = 6, so R² = 1 − 2.4 / 6 = 0.6. The line explains 60% of the variation in y.
In the lab, turn on the squares view: each residual is drawn as a square, and the fitted line is the one that makes their total area smallest (2.4 for the five points above).
The sum of the squared vertical distances from the points to the line. Squaring stops positive and negative errors cancelling and punishes large errors most.
The share of the variation in y that the line explains, from 0 to 1. R² = 0.6 means 60% is explained and 40% is scatter around the line.
Because errors are squared, one far-away point, especially at an extreme x value, can pull the whole line towards it. Robust methods such as least absolute deviations resist this.