Quant Memo

Visualizers

Regression Playground

Click to drop data points and watch the best-fit line, R² and residuals update instantly. Linear regression you can feel.

Regression Playground

y = 0.78·x + 1.26R² = 0.965n = 9
02468100246810(1, 2.1), shift-click to remove(2, 2.6), shift-click to remove(3, 4.1), shift-click to remove(4, 3.9), shift-click to remove(5, 5.4), shift-click to remove(6, 5.5), shift-click to remove(7, 7.2), shift-click to remove(8, 7), shift-click to remove(9, 8.5), shift-click to remove

Click anywhere to add a point · Shift-click a point to remove it · The red segments are the residuals least squares minimizes.

Linear regression draws the single straight line that makes the total squared vertical distance to your points as small as possible, those red residuals are exactly what it is shrinking. The slope tells you how much y moves for every one-unit step in x, and the intercept is where the line crosses x = 0. R² runs from 0 to 1 and says how much of the wiggle in y the line actually explains, 1 is a perfect fit, near 0 is basically noise. Drop in a stray point far from the crowd and watch how a single outlier can swing the whole line.

Learn how it works

Five worked examples. Read a couple before you dive in, try to answer first, then reveal the solution.

A clear trend, high R²

Click to drop points that roughly follow a rising diagonal line. Watch the best-fit line and the value.

Show solution

The line tilts up steeply, threading right through your points, and R² climbs toward 1 (say 0.9+).

  • The slope captures the trend: as x goes up, y goes up.
  • A high R² means the line explains almost all of the up-and-down movement in your points, they hug it closely.

When the data tells a clean story, the line finds it and R² rewards the tight fit.

A shapeless cloud, low R²

Now scatter points in a random blob with no direction. Look at the line and R².

Show solution

The best-fit line goes nearly flat, and R² drops toward 0.

  • With no trend to find, the line's best guess for y is basically just the average, ignoring x.
  • A near-zero R² means the line explains almost none of the variation, knowing x barely helps you predict y.

Low R² isn't a broken tool; it's the honest verdict that there's no relationship here.

One outlier yanks the line

Build a tidy rising trend with a good R². Then drop one point far away from the rest and watch what happens.

Show solution

The line swings toward the outlier, tilting away from the crowd, and R² drops.

Least-squares fitting minimizes squared gaps, so a single far-off point contributes a huge penalty and drags the line hard to reduce it.

  • One bad data point can distort the whole fit.
  • This is why least squares is called sensitive to outliers, always eyeball your data for stragglers before trusting the line.

What the red lines mean

With any set of points on screen, look at the red vertical lines connecting each point to the fitted line.

Show solution

Each red line is a residual, the vertical gap between an actual point and what the line predicted for that x. It's the line's error on that point.

  • Points above the line have positive residuals; points below, negative.
  • The best-fit line is the one chosen to make the sum of the squared residuals as small as possible, that's what 'least squares' means.

The red lines make the fitting rule visible: shorten these gaps overall, and you've found the best line.

Reading R² plainly

Watch the number as you rearrange points from a tight line to a loose scatter and back.

Show solution

R² is the share of the up-and-down variation in y that the line explains, a score from 0 to 1.

  • R² = 0.8 means the line accounts for 80% of the wiggle in y; the leftover 20% is scatter the line can't explain.
  • R² near 1: points hug the line, the trend explains almost everything.
  • R² near 0: the line is no better than guessing the average.

It's the single-number report card for how well the line fits, but remember, even a high R² doesn't prove x causes y.

What you'll learn

What ordinary least squares actually does, how outliers move the line, and what R-squared and residuals are telling you.