OLS & Multiple Regression

Dr. R. Düsing · University of Osnabrück
N = 30 students X₁ = study time (h/week) X₂ = sleep hours (h/night) Y = exam grade (0–100 pts.)
Seed: —
The Least-Squares Principle
Why does OLS minimize the squared deviations — and what does that mean?
Study time (h/week) → Exam grade
b₀
b₁
RSS
RSS comparison (smaller = better)
Your line
OLS (min)
Model:
Y = + · X₁
Tutorial — The Least-Squares Principle

What you're seeing
30 simulated students: study time X₁ (h/week) → exam grade Y (points). The orange line is your estimated line — draggable via two round anchors at the left and right edge. Turn on ● Residuals: green marks = positive residuals (point above the line), red marks = negative residuals (point below it). A residual eᵢ = yᵢ − ŷᵢ is the deviation of the observed value from the predicted value.

What to do
Drag the anchors until your RSS (orange bar, absolute value) is as small as possible. Then click ◎ Show OLS — the blue OLS line appears. The second bar shows its RSS. Compare: how close did you get to the minimum?

What is RSS? (Residual Sum of Squares)
RSS = Σeᵢ² = Σ(yᵢ − ŷᵢ)². OLS finds analytically the exact b₀ and b₁ for which RSS is globally minimal — unique and provable. No trial and error: b₁ = Cov(X,Y)/Var(X), b₀ = ȳ − b₁·x̄.

Why squares, not absolute values?
(1) For every OLS line, Σeᵢ = 0 holds — positive and negative residuals trivially cancel out. (2) Squaring penalizes large residuals disproportionately: a residual of 10 costs 100, not 10. (3) The square yields a differentiable function → a closed-form, unique solution.

What to observe
· Wrong slope → RSS rises faster than a wrong intercept.
· Points at the edge of X (high leverage) swing b₁ strongly if they deviate far from the line.
· Deliberately try bad lines (steep, flat, negative) — the RSS value explodes.
· Gauss-Markov: under the 5 OLS assumptions (→ Module ) OLS is BLUE — Best Linear Unbiased Estimator. No other linear unbiased estimator has smaller variance.

What is a residual? eᵢ = yᵢ − yᵢ is the deviation of the observed value from the predicted one. Why square it? First, positive and negative residuals are treated equally (|+3| = |−3|). Second, large residuals are penalized disproportionately: a residual of 10 counts as 100, not 10. OLS finds the one b₀, b₁ for which: Σeᵢ = 0 and Σeᵢ² is minimal — this solution is unique.
I — linear
II — quadratic
III — outlier
IV — leverage point
All four datasets have (nearly) identical statistics: b₁ ≈ 0.50, b₀ ≈ 3.0, r ≈ .816, R² ≈ .667. Yet the scatterplot and residual plot show fundamentally different patterns. Bottom line: coefficients and R² alone are not enough — residual diagnostics are mandatory.
Understanding b₀, b₁ and β
Slope, intercept and standardized coefficient — visually and formally
Regression line with coefficient visualization
b₀
b₁
β
b₁: Per +1 h of study time, the expected grade rises by points.
β = r = — bivariately, β = r always holds.
b₀: Expected grade at 0 h of study time (extrapolated, often not meaningful substantively).
Tutorial — Understanding b₀, b₁ and β

What you're seeing
The OLS line through all 30 data points. Enable △ Slope for the slope triangle and ✛ Mean for the centroid (x̄, ȳ) on the canvas.

b₁ = — slope (unstandardized)
Per +1 h of study time, the expected grade rises by points. Unit: points/hour. Interpretation: descriptive, not a causal effect. b₁ is scale-dependent — a b₁ from another study with different scales isn't directly comparable.
The slope triangle on the canvas shows this concretely: +3 h of study time → + points (= 3 · b₁).

β = standardized coefficient
Per +1 SD in X₁, Y rises by β SD. Bivariately, β = r (Pearson correlation) always holds — check this in the coefficient cell! β allows comparing predictors on different scales within a study, but not across studies (it depends on SD(X) and SD(Y)).
Important: β does not directly indicate the importance or causal influence of a predictor — with correlated predictors, β can deviate strongly from the partial effect (→ Module ).

b₀ = — intercept
Expected grade at X₁ = 0 h of study time. Since 0 h lies outside the observed range, this is an extrapolation — usually not meaningfully interpretable in substantive terms. b₀ is mathematically necessary but rarely has stand-alone meaning.

Centroid (x̄ = h | ȳ = pts)
The OLS line always passes through (x̄, ȳ) — mathematically necessary, since b₀ = ȳ − b₁·x̄. Enable ✛ Mean and check this visually. OLS estimates E[Y|X] — the conditional expectation, not an individual prediction.

Calculation formulas:
b₁ = Σ(xᵢ − x)(yᵢ − y) / Σ(xᵢ − x)² = Cov(X,Y) / Var(X)
b₀ = y − b₁ · x  ·  β = b₁ · (SDX / SDY) = r  (bivariate)
b₁ (unstandardized) is reported when the unit is substantively meaningful: "+1 h of study time → + points". Requirement: readers know the scale.

β (standardized) allows comparing predictors on different scales within a study. Caution: β varies with SD(X) and SD(Y) — comparisons across studies are not valid.

In bivariate OLS, β = r = always holds. In the multiple model (Module ), β ≠ r, because of partialling out the other predictors.
Model Fit & Variance Decomposition
TSS = SSM + RSS, R², adjusted R² and the assumptions of the OLS model
Total (TSS) — distances of the points from the mean ȳ
TSS = SSM + RSS
SSM
RSS
SSM = — RSS = —
adj. R²
r (Pearson)
= SSM/TSS = % of the total variance in Y is explained by X₁.
= R²/(1−R²) = SSM/RSS:  small ≥ .02 · medium ≥ .15 · large ≥ .35
Tutorial — Variance Decomposition & Model Fit

What you're seeing — three modes (TSS = SSM + RSS)
TSS (gray marks): distances of all points from the mean ȳ — the total spread in Y, independent of the model. SSM (green marks): distances of the model (regression line) from the mean ȳ — the share the model explains over "just ȳ as the prediction". RSS (red marks): distances of the points from the model — the residuals, i.e. what remains unexplained. The bar on the left shows the SSM : RSS ratio. Switch modes using the buttons.

TSS = — Total Sum of Squares
TSS = Σ(yᵢ − ȳ)². Total variance in Y — how much do grades vary in general? TSS does not depend on the model. It's the starting point that is to be explained.

SSM = (% of TSS) — Sum of Squares Model
SSM = Σ(ŷᵢ − ȳ)². The share explained by the model — the distance of the regression line from the mean ȳ at each data point (one contribution per observation), i.e. the improvement over "just ȳ". The larger SSM is relative to TSS, the better the fit. OLS maximizes SSM (equivalent to minimizing RSS).

RSS = (% of TSS) — Residual Sum of Squares
RSS = Σeᵢ² = Σ(yᵢ − ŷᵢ)² — the squared sum of all residuals, what the model doesn't explain. TSS = SSM + RSS holds exactly. RSS = 0 would be a perfect fit — impossible in practice and not desirable (overfitting).

and (Cohen's effect size)
R² = SSM/TSS (→ stats on the left): proportion of explained variance. Caution: R² always increases with every additional predictor — even useless ones! Adjusted R² corrects this with a penalty term per predictor.
f² = R²/(1−R²) = SSM/RSS = → a effect. f² is the ratio of explained to unexplained variance. Cohen (1988): .02 small · .15 medium · .35 large.
Model comparisons: AIC and BIC penalize complexity more strongly than adj. R² — recommended when comparing several competing models.

What's good / problematic
· Good: large green bar (SSM ≫ RSS), R² close to 1, f² ≥ .15.
· R² = 0: the model explains nothing — no better than ȳ as a forecast.
· R² alone is not sufficient — a good R² despite violated assumptions is misleading. Residual diagnostics are mandatory (→ OLS assumptions accordion below).

Linearity: The relationship between X and Y is linear. Violation: the residual-vs-fitted plot shows a systematic pattern (curve, fan shape). Remedy: transformation or polynomial terms.
Independence: Observations are independent (no autocorrelation, no clustering). Violated with longitudinal or nested data → mixed models become necessary. Students in the same school class are not independent.
Homoscedasticity: The variance of the residuals is constant across all X values — no fan shape. Violation: heteroscedasticity-robust standard errors (HC3 — sandwich-based, leverage-corrected covariance estimation, robust even in small samples) or WLS (Weighted Least Squares — weights each observation inversely to its estimated variance, instead of just correcting the standard errors after the fact). Anscombe dataset III shows a classic violation.
Normal distribution of residuals: Only needed for inferential statistics (t-tests, CIs) — not for the OLS estimation itself (Gauss-Markov theorem!). With n ≥ 30 the central limit theorem kicks in: minor violations are uncritical.
No perfect multicollinearity (multiple regression): if two predictors are perfectly correlated, (XX) is not invertible. High (non-perfect) collinearity inflates standard errors → VIF > 10 is critical. See Module .
Multiple Regression & Added Variable Plot
What does "controlling for X₂" mean? Understanding partial slopes visually.
Step — bivariate model: Y ~ X₁
Step
Correlation X₁↔X₂
Coefficient comparison
Model b₁ β₁
Bivariate
Partial
AVP slope
Δb₁
Step ① shows the bivariate regression of Y on X₁ — as in Module ①. The bivariate b₁ still contains the influence of X₂ if X₁ and X₂ are correlated.
Tutorial — Multiple Regression & AVP

From the line to the plane
Bivariately (Y ~ X₁), the solution is a line in 2D space. With two predictors (Y ~ X₁ + X₂), it becomes a regression surface (plane) in 3D space. Picture it: X₁ on the x-axis, X₂ on the z-axis, Y on the y-axis — the OLS minimum is the plane that minimizes RSS across all points. b₁ is the slope in the X₁ direction, b₂ in the X₂ direction — each holding the other predictor constant.

Why multiple regression?
X₁ (study time) and X₂ (sleep) correlate with r₁₂ = . The bivariate model Y ~ X₁ does not measure the pure X₁ effect — b₁ also contains the influence of X₂, since X₂ is intertwined with X₁. The multiple model solves this: it holds X₂ statistically constant.

Reading the coefficients (table on the left)
Bivariate b₁: slope from Y ~ X₁ alone — contains confounding by X₂.
Partial b₁: slope from Y ~ X₁ + X₂ — adjusted for X₂. This is the value the regression surface has in the X₁ direction.
Δb₁: the difference quantifies the confounding. At r₁₂ = 0, Δb₁ = 0.

Step ① — bivariate starting point
What you're seeing: the bivariate OLS line Y ~ X₁ (study time → grade) — identical to Module ①.
Problem: when r₁₂ ≠ 0, b₁ contains the influence of X₂ as a confound. The bivariate estimator is biased as long as X₂ correlates with X₁ and also affects Y.
Tip: note the bivariate b₁ (table on the left), then change r₁₂ and compare.

Confounding compared
bivariate b₁ = · partial b₁ = · Δb₁ =
The larger r₁₂, the more the bivariate deviates from the partial b₁. At r₁₂ = 0 both are identical — X₂ confounds nothing. Try the four r₁₂ scenarios on the left.

AVP principle: an Added Variable Plot (partial regression plot) makes the partial effect of X₁ on Y visible — adjusted for X₂. To do this, X₂ is removed from both Y (e(Y|X₂)) and X₁ (e(X₁|X₂)). The slope of the regression line through the residual vectors corresponds exactly to the partial coefficient b₁ from the multiple model. Change the correlation X₁↔X₂ to see when and why bivariate b₁ ≠ partial b₁.
Flashcards — OLS & Multiple Regression
OLS criterion
OLS minimizes the sum of squared residuals: min Σ(yᵢ − ŷᵢ)². Squaring has two reasons: signs are neutralized, and large residuals are penalized disproportionately more than small ones. The solution is unique and always yields Σeᵢ = 0.
Coefficient b₁
Interpretation: "Per +1 unit of X, the expected value of Y rises by b₁ units — all other predictors held constant (ceteris paribus)." In the bivariate case: b₁ = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)². The numerator is the covariance, the denominator the variance of X.
Intercept b₀
b₀ is the expected Y value when all predictors equal 0. This is often not meaningful substantively (e.g. 0 hours of study, 0 sleep). b₀ is needed for prediction, but should usually not be interpreted substantively. It always holds that ȳ = b₀ + b₁·x̄.
R² = SSM/SST ∈ [0, 1] — proportion of explained variance. R² increases with every added predictor, even useless ones. Adjusted R² corrects for this: adj.R² = 1 − (1−R²)·(n−1)/(n−k−1). adj.R² decreases when a new predictor explains less than expected by chance.
Partial slope
b₁ in the multiple model is not the same as in the bivariate model — it is the slope in the Added Variable Plot (AVP): the regression of e(Y|X₂) on e(X₁|X₂). This value corresponds to the partial slope: the effect of X₁ on Y, after the shared portion of X₂ has been removed from both.
Standardization β
β = b · (SD_X / SD_Y) — the standardized regression coefficient. β indicates how many standard deviations Y rises when X rises by one SD. Allows comparison of predictors on different scales, but only within a sample. Across studies, β values are not directly comparable because of differing SDs.
? Help — OLS & Multiple Regression

What is OLS?

Ordinary Least Squares (OLS) is the standard method for estimating linear regression models. It finds the coefficients b₀ and b₁ that minimize the sum of squared residuals: min Σ(yᵢ − ŷᵢ)² = min Σ(yᵢ − b₀ − b₁·xᵢ)². The solution follows from the normal equations:

  • b₁ = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)²
  • b₀ = ȳ − b₁·x̄
▸ Matrix notation (for the curious)
In the multiple case with design matrix X (n×(k+1), first column ones) and vector y:
b = (XX)⁻¹ Xy
Requirement: (XX) is invertible → no perfect multicollinearity.

Coefficient interpretation

b₁ (unstandardized): "Per +1 unit of X, Ŷ rises by b₁ units, holding all other predictors constant." The "ceteris paribus" is crucial — in the multiple model, b₁ is a partial effect, not a marginal raw effect.

β (standardized): comparison of predictors on different scales. Caution: β is sample-specific and must not be compared across studies.

R² and model fit

= SSM/TSS = 1 − RSS/TSS. In the bivariate case, R² = r². R² increases with every predictor, even random ones (Freedman's paradox). Adjusted R² corrects for the number of predictors k:

adj.R² = 1 − (1−R²)·(n−1)/(n−k−1)

Effect size f² and SESOI

f² = R²/(1−R²) — effect size for multiple regression. Conventions (Cohen 1988): small ≥ .02, medium ≥ .15, large ≥ .35. Better than conventions: SESOI — define the smallest substantively meaningful effect before the study. → See Power & Sample Size.

When does OLS fail?

  • Nonlinearity — residual-vs-fitted plot shows a pattern
  • Heteroscedasticity — fan shape in the residual plot
  • Outliers/leverage — individual points determine the line (→ Anscombe)
  • Multicollinearity — high r(X₁,X₂) inflates standard errors; VIF > 10 is critical
  • Measurement error — attenuation of b₁ → Measurement error tool

Related tools