Chapter 1 · Simple Linear Regression

Worked Example — MLB Home Runs

Predicting runs scored from home runs hit across six teams — every number computed by hand. Use the steps below to move through it. Calculations retain full precision; displayed values are rounded.

Step 1 of 8

The raw data

Do teams that hit more home runs score more runs? x = home runs, y = runs scored — both per season, six teams.

Scatterplot of home runs and runs scored for the six teams
Six teams plotted from the table

6 MLB teams — one season

TeamHome runs (x)Runs scored (y)
Yankees245807
Dodgers221758
Red Sox198726
Astros214749
Cubs177691
Padres162668
Moneyball connection Billy Beane's A's found that some cheap counting stats had a big effect on winning. Spotting which x-variables move y the most is exactly what regression does.
Step 2 of 8

Find the means x̄ and ȳ

The means are the data's centre of gravity. A key OLS fact: the fitted line always passes through the point (x̄, ȳ).

Fitted line passing through the mean home runs and mean runs scored
The line must pass through (x̄, ȳ)

x̄ — mean home runs

x̄ = (245 + 221 + 198 + 214 + 177 + 162) / 6 = 1217 / 6 = 202.83

ȳ — mean runs scored

ȳ = (807 + 758 + 726 + 749 + 691 + 668) / 6 = 4399 / 6 = 733.17
(x̄, ȳ) = (202.83, 733.17) is the "average team" in this sample. No matter what the slope and intercept turn out to be, the regression line is guaranteed to run through this point.
Step 3 of 8

Compute Sxx and Sxy

Sxx measures how spread out the home-run counts are. Sxy measures how x and y move together. Both feed straight into the slope.

Horizontal and vertical deviations from the mean point
Deviations from the mean

Deviation table

Teamxᵢ−x̄yᵢ−ȳ(xᵢ−x̄)²(xᵢ−x̄)(yᵢ−ȳ)
Yankees42.1773.831778.033113.31
Dodgers18.1724.83330.03451.14
Red Sox-4.83-7.1723.3634.64
Astros11.1715.83124.69176.81
Cubs-25.83-42.17667.361089.31
Padres-40.83-65.171667.362660.97
Σ≈ 0≈ 04590.837526.17
Sxx = Σ(xᵢ−x̄)²4590.83
Sxy = Σ(xᵢ−x̄)(yᵢ−ȳ)7526.17
The deviation columns sum to ≈ 0 — always true, and a handy arithmetic check. Sxy is large and positive: more home runs clearly travels with more runs.
Step 4 of 8

The slope β̂₁ and intercept β̂₀

With Sxx and Sxy in hand, the line is one division and one subtraction away.

Slope triangle: 40 additional home runs correspond to about 65.6 runs
Slope = rise ÷ run

Slope

β̂₁ = Sxy / Sxx = 7526.17 / 4590.83 = 1.639

Each extra home run is worth about 1.639 more runs.

Intercept

β̂₀ = ȳ − β̂₁ × x̄ = 733.1667 − 1.63939009 × 202.8333 = 400.64
ŷ = 400.64 + 1.6394 × x
Matrix connection β̂₁ = Sxy / Sxx is exactly what β̂ = (XᵀX)⁻¹XᵀY gives for one predictor. Add more predictors and you need the full matrix; with a single x it collapses to this ratio.
Step 5 of 8

Fitted values ŷᵢ and residuals eᵢ

Plug each xᵢ into the line to get ŷᵢ. The residual eᵢ = yᵢ − ŷᵢ is how far off the model is for that team. Keep full precision in the model, then round the displayed values.

Residual plot showing each team’s observed minus predicted runs
Each dashed gap is a residual

ŷᵢ = 400.64371029 + 1.63939009 × xᵢ

Teamyᵢŷᵢeᵢeᵢ²
Yankees807802.29+4.7122.14
Dodgers758762.95-4.9524.49
Red Sox726725.24+0.760.57
Astros749751.47-2.476.12
Cubs691690.82+0.180.03
Padres668666.22+1.783.15
Σ≈ 056.51
Residuals always sum to zero in OLS. The Astros' −2.47 means they scored about 2.47 fewer runs than predicted — home runs alone can't capture everything (a few stranded runners, say).
Step 6 of 8

SSE and the variance estimate s²

SSE is the total squared error after fitting. s² estimates σ² — the natural scatter around the true line.

Squares with areas proportional to the first three squared residuals
Square each residual, then add

Sum of squared errors

SSE = Σ eᵢ² = 22.14 + 24.49 + 0.57 + 6.12 + 0.03 + 3.15 = 56.51

Variance estimate

s² = SSE / (n − 2) = 56.51 / 4 = 14.13 s = √14.13 = 3.76 runs
Why n − 2? We used up 2 degrees of freedom estimating β̂₀ and β̂₁, so we divide by n − 2, not n. Writing n here is the most common slip on this topic.
Step 7 of 8

R² — how much we explained

R² answers: what proportion of the total variation in runs does the model account for?

99.5 percent explained variation and 0.5 percent residual variation
Explained vs unexplained

Total sum of squares

TSS = Σ(yᵢ − ȳ)² = 5451.36 + 616.69 + 51.36 + 250.69 + 1778.03 + 4246.69 = 12394.83

R²

R² = 1 − SSE / TSS = 1 − 56.51 / 12394.83 = 0.9954
TSS (total)12394.83
SSE (unexplained)56.51
R²0.995
Home runs explain 99.5% of the variation in runs scored across these six teams. The other 0.5% is everything else — walks, singles, stolen bases. This is a strong association in this small teaching dataset, not evidence of causation.
Step 8 of 8

Putting it into words

Every quantity, its value, and what it actually means — plus how to phrase it in an exam.

Prediction at 200 home runs: about 729 runs scored
From numbers to meaning

Summary

QuantityValueMeaning
β̂₁1.639+1 HR → +1.639 runs
β̂₀400.64Baseline runs at x = 0
SSE56.51Unexplained squared error
s3.76Typical miss (± runs)
R²0.995499.5% of variation explained

How to write it in an exam

Slope: For each additional home run in a season, a team is estimated to score 1.639 more runs on average.

Intercept: A team hitting zero home runs is predicted to score 400.64 runs (non-HR scoring) — but x = 0 is outside the data, so it isn't practically meaningful.

R²: Home runs explain 99.5% of the variation in runs scored — an excellent fit.