Contents/ Part XV · Regression Analysis/ Chapter 97

Multiple Linear Regression

Real outcomes have many drivers. Multiple regression fits them together and lets you read the effect of each one "holding the others constant." That power comes with a new hazard, multicollinearity, and the same five-step discipline keeps you honest.

⏱️ ~19 min read
🐍 Notebook included
📊 Chapter 97

A car's fuel economy depends on its weight, its power, and where it was built, all at once. Fit them one at a time and each steals credit from the others. Fit them together and multiple regression separates the signal: how much does weight matter once power and origin are already accounted for?

βₖ
Multiple linear regression models one response from several predictors, ŷ = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ. Each partial slope b₌ is the change in ŷ for a one-unit rise in x₌ with all other predictors held constant, the effect of that variable, net of the rest.
🧭
Same workflow, one new check

The five-step workflow is unchanged, but step 1 gains a question: are the predictors themselves too correlated? That is multicollinearity, and it is the signature failure mode of multiple regression.

1

Reading a Coefficient "Holding the Others Constant"

This four-word phrase is the heart of multiple regression. A partial slope answers a ceteris paribus question: compare two cars of the same power and origin but differing by one pound, the coefficient on weight is the expected mpg difference between them. That is why a predictor's coefficient can shrink, or even flip sign, when you add a related variable, you are now asking a different question.

To judge which predictors truly matter, plot each coefficient with its confidence interval. A whisker that clears zero is a real effect; one that straddles zero could be nothing.

Which predictors really move mpg? Coefficients with 95% intervals Standardized effect of a one-standard-deviation increase, holding the others constant 0 (no effect) -8 -6 -4 -2 2 weight horsepower crosses 0: not significant displacement crosses 0: not significant Japan vs Europe USA vs Europe A whisker that clears the dashed line is a predictor whose effect is convincingly nonzero.

Weight dominates. The origin effects are real and modest. But horsepower and displacement have intervals that cross zero, not because they do not affect mpg, but because they are so entangled with weight that the model cannot give them separate credit. That is your first sight of multicollinearity, diagnosed in Section 3. One more guardrail: use adjusted R², not plain R², to compare models, because plain R² can only rise when you add predictors, even useless ones.

2

Categorical Predictors and Interactions

Regression needs numbers, so a category like origin becomes a set of dummy variables: 0/1 columns, one per level, with one level held out as the reference. Each dummy's coefficient is that group's shift relative to the reference. Geometrically, dummies give every group the same slope but a different intercept, parallel lines.

Dummy variables: one slope, a parallel line per category A categorical predictor shifts the intercept; the slope on weight is shared (weight 2700–3300 shown) weight (lbs) → mpg → Japan +1.4 mpg Europe baseline USA −1.7 mpg 3.1 mpg 2800 3000 3200

Here Europe is the reference; Japan sits about 1.4 mpg above it and the USA about 1.7 below, at any weight. When the effect of one predictor depends on another, you need an interaction term (weight * C(origin)), which lets each group have its own slope, non-parallel lines. Test it before you trust it: in this dataset the interaction is not significant (p ≈ 0.20), so parallel lines are the honest description, adding the interaction would just fit noise.

3

Multicollinearity: the New Hazard

When predictors are strongly correlated with each other, the model struggles to divide credit between them. The coefficients become unstable, their standard errors balloon, and individually significant variables can look worthless, even while the model as a whole predicts beautifully. The standard gauge is the variance inflation factor (VIF): how much a coefficient's variance is inflated by its correlation with the other predictors.

Multicollinearity, measured: the variance inflation factor VIF above 5 is a caution; above 10 the predictor is badly redundant 5 (caution) 10 (serious) weight VIF 8.3 horsepower VIF 6.6 displacement VIF 13.3 displacement is the worst offender; dropping it barely changes R² and stabilizes the rest.

A rough rule: VIF above 5 deserves a look, above 10 is serious. In the car data, weight, horsepower, and displacement are all measuring "how big is the engine and body," so displacement's VIF is 13. The remedies are simple: drop the most redundant predictor, combine them into one index, or use ridge regression (see the Regularization & Flexible Models chapter), which is built for exactly this. Crucially, multicollinearity does not bias predictions, if you only care about forecasting mpg, you can ignore it. It only muddies the interpretation of individual coefficients.

4

Real-World Example: What Drives Fuel Economy?

We model mpg from weight, horsepower, displacement, and origin, then walk the workflow: fit, check for multicollinearity, fix it, and interpret.

📂 Dataset · multiple-linear-regression--cars.xlsx

One row per car with weight, horsepower, displacement, origin (USA / Europe / Japan), and mpg.

We follow the same five-step workflow as the last two chapters, now with the multicollinearity check folded into steps 1 and 4.

Step 1, check the data. Before fitting anything, look at how mpg relates to each numeric predictor:

Step 1: explore. mpg falls as weight, power, and size all rise Each predictor lowers mpg on its own, and they move together, the seed of multicollinearity weight (lbs) → mpg → horsepower → displacement (cu in) →

All three panels slope down, heavier, more powerful, larger-engined cars burn more fuel, so every predictor looks useful. But notice they tell almost the same story: weight, horsepower, and displacement are strongly correlated with one another (r = 0.87 to 0.94), because all three really measure "how big is the car." That overlap is the seed of the multicollinearity we will diagnose in step 4.

Step 2, define and fit. We regress mpg on all four predictors at once, ols("mpg ~ weight + horsepower + displacement + C(origin)", cars).fit(), so every coefficient is read with the others held constant.

Step 3, evaluate adequacy. The model explains the data well, adjusted R² = 0.90, but the coefficient table has a tell:

PredictorCoefficientp-valueReading (others held constant)
weight−0.0074 mpg/lb<0.001heavier cars use more fuel, the dominant driver
horsepower−0.0140.19"not significant", a multicollinearity artifact
displacement−0.0020.78"not significant", entangled with weight and power
origin = Japan+1.5 mpg0.001Japanese cars average 1.5 mpg more than European
origin = USA−1.7 mpg<0.001US cars average 1.7 mpg less than European

Weight and both origin effects are clearly significant, yet horsepower (p = 0.19) and displacement (p = 0.78) look worthless, even though step 1 showed each is strongly related to mpg. That contradiction is the fingerprint of multicollinearity: the predictors are so entangled the model cannot give any one of them separate credit. The coefficient forest plot in Section 1 shows exactly this, weight's interval sits far from zero while horsepower's and displacement's intervals straddle it.

Step 4, check the conditions. The variance inflation factors confirm the diagnosis, displacement 13.3, weight 8.3, horsepower 6.6 (above 10 is serious). The remedy is to drop the most redundant predictors and re-fit:

ModelAdjusted R²weight coefficientVerdict
Full (4 predictors)0.902−0.0074 (unstable)collinear; coefficients hard to trust
Reduced (weight + origin)0.901−0.0081 (95% CI tight)same fit, clean interpretation

Dropping displacement and horsepower barely moves the fit (adjusted R² 0.902 to 0.901) but makes the weight coefficient stable and its interval tight, exactly what VIF told us to expect.

Step 5, interpret and predict. Read the surviving coefficients "holding the others constant", each pound of weight costs about 0.008 mpg, and Japanese cars average 1.4 mpg more (US cars 1.7 mpg less) than European. Then predict by plugging into the fitted line:

mpĝ = 60.15 − 0.00805 × weight + origin adjustment

A 3,000 lb Japanese car (origin +1.41): 60.15 − 0.00805×3,000 + 1.41 ≈ 37.4 mpg. Across the whole fleet, predicted mpg tracks actual mpg tightly, the dots hug the dashed "perfect prediction" line:

The model in action: predicted vs actual fuel economy The reduced model (weight + origin) predicts mpg with adjusted R² = 0.90 perfect prediction actual (mpg) → predicted (mpg) →

The lesson in one line: dropping two redundant predictors cost essentially nothing in fit (0.902 to 0.901) and bought a model you can actually explain. Simpler, when it predicts just as well, wins.

5

Multiple Regression in Machine Learning & AI

Multiple regression is the direct ancestor of supervised learning with many features.

Idea (this chapter)In ML / AI it becomesExample
Many predictorsFeature matrices with hundreds of columnstabular models, the linear head of a network
Dummy variablesOne-hot / categorical encodingpd.get_dummies, embeddings for high-cardinality
Adjusted R² / parsimonyRegularization & model selectionpenalize complexity to avoid overfitting (see Regularization & Flexible Models)
MulticollinearityCorrelated / redundant featuresridge, PCA, feature selection
Coefficient as effectModel interpretabilitycoefficients, permutation importance, SHAP values
🤖
Why this matters for AI research

"Holding the others constant" is the idea that makes model interpretation possible, and also the idea that breaks down when features are correlated. A model can lean on either of two redundant features interchangeably, which is why coefficient magnitudes (and even modern attributions like SHAP) can be unstable under collinearity, the same disease as an exploding VIF, just in a bigger model. It is also why regularization is not optional at scale: ridge and lasso tame correlated features and are the direct descendants of the "drop or combine" remedy here. And the split between prediction (where collinearity is harmless) and interpretation (where it is fatal) is one every applied researcher must keep straight, a model that forecasts well can still be telling you a misleading story about why.

🐍

Fit, diagnose, and prune in Python

The companion notebook fits the multiple model with statsmodels, draws the coefficient forest plot, shows R² rising while adjusted R² does not when a junk predictor is added, encodes the categorical origin and tests an interaction, computes VIFs, and prunes the collinear predictors, all on multiple-linear-regression--cars.xlsx.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scipy, matplotlib, seaborn, statsmodels, and openpyxl and launch jupyter notebook.

🎓 Key Takeaways

  • Each partial slope is an effect "holding the others constant": adding a correlated predictor can shrink or flip a coefficient because the question changes.
  • Judge predictors with coefficient CIs (a forest plot) and compare models with adjusted R², not plain R².
  • Categories become dummy variables (parallel lines, one reference level); an interaction term lets slopes differ, test it before keeping it.
  • Multicollinearity inflates standard errors and destabilizes coefficients; measure it with VIF (>5 caution, >10 serious) and fix by dropping, combining, or ridge.
  • Real data: pruning two collinear car predictors held adjusted R² at 0.90 while making the weight coefficient stable and interpretable.
6

Practice Challenges

Five short challenges. Use statsmodels formulas (C(...), *) and the VIF helper.

1

Fit and interpret a partial slope

Fit mpg ~ weight + horsepower + C(origin) and state the weight coefficient in a "holding others constant" sentence.

Hint: read .params and phrase it per one-pound change.
2

R² vs adjusted R²

Add a column of pure random noise as a predictor; watch R² rise but adjusted R² fall.

Hint: compare .rsquared and .rsquared_adj before and after.
3

Dummy variables & reference level

Interpret the origin coefficients, then change the reference category and confirm the fit is unchanged.

Hint: C(origin, Treatment(reference="Japan")).
4

Diagnose & cure multicollinearity

Compute the VIFs, drop the worst offender, and compare coefficient stability and adjusted R².

Hint: variance_inflation_factor on the numeric design matrix.
5

Test an interaction

Fit mpg ~ weight * C(origin) and decide from the p-values whether the slopes really differ.

Hint: look at the weight:C(origin) terms.
Check your work

A fully-worked solutions notebook walks through all five challenges, each verified in code. Try them yourself first, then compare.

📓 View Solutions ▶ Open Solutions in Colab ⬇ View / Download on GitHub
7

Quiz: Test Yourself

Eight quick questions on multiple regression. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.

🏁
Onward

You can now fit many predictors, read each net of the others, and spot multicollinearity. The Regression Assumptions & Diagnostics chapter zooms in on steps 1 and 4, the full toolkit of residual plots and tests that decide whether a model is trustworthy.