Unit 09.01: Levels minus one, all relative to the reference
A numeric predictor gives you one slope. A four-level factor gives you three coefficients, and none of them is 'the effect of region'.
Levels minus one, all relative to the reference
C(region) in a formula encodes a categorical variable as a set of indicators — one fewer than the number of levels. Each coefficient is the average difference between that level and the reference, at the same values of the other predictors.
In an additive model this shifts the line up or down without changing its slope: every group gets a parallel line at a different height. Letting the slope differ is an interaction, which is the next lesson.
There is no single coefficient for the factor as a whole. Asking whether region matters overall is a different question, answered by comparing models rather than by reading one row.
This block fits price on size plus a four-level region factor.
import numpy as np, pandas as pd
import statsmodels.formula.api as smf
rng = np.random.default_rng(602)
d = pd.DataFrame({
"size": rng.uniform(40, 200, 240),
"region": np.repeat(["north", "south", "east", "west"], 60),
})
offset = d["region"].map({"north": 0, "south": 30, "east": -20, "west": 55})
d["price"] = 50 + 2.1 * d["size"] + offset + rng.normal(0, 20, 240)
model = smf.ols("price ~ size + C(region)", data=d).fit()
print(model.summary2().tables[1].round(3).to_string())
levels = sorted(d.region.unique())
print(f"\nOne numeric predictor gives ONE slope: size = {model.params['size']:.3f}")
print(f"A factor with {len(levels)} levels gives {len(levels) - 1} coefficients"
" -- one per level except the reference.")
print(f"Reference level: {levels[0]} (alphabetically first)\n")
print(f"Each region coefficient is that region's average price difference from")
print(f"{levels[0]}, AT THE SAME SIZE. The slope is shared, so the four fitted")
print("lines are parallel; only their height moves.")
Four levels produce 3 coefficients. The reference is east, alphabetically first, and the others read as differences from it: north +19.181, south +50.396, west +73.463, all at the same size. The size slope of 2.098 is shared by every region — four parallel lines at four different heights.
The mistake this prevents
The mistake is reading one factor coefficient as 'the effect of being in that region'. It is the effect *relative to the reference*, and changing the reference changes every number in the column.
Takeaway
Report the reference level with every regression table. Remember that a factor contributes several rows, and that testing it as a whole requires a model comparison rather than one p-value.
