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:
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.20Read 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.