Skip to the workspace
Pebellslearn by building
Experiments and Causal Effects  ›  Lesson

Regression: Holding Other Things Fixed

Econometrics 15 minA regression coefficient is the change in the outcome per unit of one input while the other inputs in the model are held fixed, and leaving out a confounder shifts its effect onto the inputs that remain.

ai data scientist / Regression: Holding Other Things Fixed

Explore each scene at your own pace.

01 · The rule

The rule

Regression: Holding Other Things Fixed

The operations head wants to know how much a late delivery costs Pantry in customer ratings. You cannot randomly make deliveries late to find out. You have months of order data instead, but there is a catch: deliveries run late more often on rainy days, and rain puts customers in a worse mood on its own. A simple comparison of late and on-time orders blends the two effects together.

The rule

A regression coefficient is the outcome's change per unit, others held fixed.

A linear regression writes the outcome as a sum of parts, one per input:

rating=b0+b1⋅minutes late+b2⋅rain+error\text{rating} = b_0 + b_1 \cdot \text{minutes late} + b_2 \cdot \text{rain} + \text{error}

Here rain is 1 on a rainy day and 0 on a dry one. In Python with the statsmodels library, the fit is one line:

import statsmodels.formula.api as smf

fit = smf.ols("rating ~ minutes_late + rain", data=orders).fit()
print(fit.params.round(2))
# Intercept       4.60
# minutes_late   -0.03
# rain           -0.20

Read each coefficient as a sentence:

  • Intercept, 4.60: the predicted rating for an on-time order on a dry day.
  • minutes_late, −0.03: comparing orders on the same kind of day, each extra minute late goes with a rating 0.03 lower. Ten minutes late costs about 0.3 stars.
  • rain, −0.20: at the same lateness, rainy-day orders are rated 0.2 lower.

When the same data are fitted with lateness alone, its coefficient is −0.04. The difference is omitted variable bias: without rain in the model, lateness was quietly taking the blame for some of rain's effect, because the two travel together.

Regression can only hold fixed what you put in it. A confounder you never recorded, such as a rider who is both slow and rude, still biases the result. So a coefficient from observational data is an estimate of an effect only if you believe the important confounders are in the model.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.