Unit 09.02: Same fit, different comparisons
The reference category is chosen alphabetically unless you choose it. It should be the baseline your reader has in mind.
Same fit, different comparisons
Changing the reference level does not change the model. The fitted values, the residuals and R-squared are all identical โ only which comparisons are reported changes.
That makes it a purely presentational choice, and an important one. If the commercial baseline is the standard tier, coefficients relative to 'basic' force every reader to do subtraction in their head.
It follows that a coefficient table is meaningless without the reference level, which is why it belongs in the caption rather than in the analyst's memory.
This block fits the same model with two different references.
import numpy as np, pandas as pd
import statsmodels.formula.api as smf
rng = np.random.default_rng(603)
d = pd.DataFrame({
"tier": np.repeat(["basic", "premium", "standard"], 60),
"spend": np.concatenate([rng.normal(40, 9, 60),
rng.normal(72, 9, 60),
rng.normal(55, 9, 60)]),
})
default = smf.ols("spend ~ C(tier)", data=d).fit()
print("Alphabetical reference (basic):")
print(default.params.round(3).to_string())
chosen = smf.ols("spend ~ C(tier, Treatment(reference='standard'))",
data=d).fit()
print("\nReference set to 'standard', the commercial baseline:")
print(chosen.params.round(3).to_string())
print(f"\nBoth models fit identically -- R-squared {default.rsquared:.5f}"
f" and {chosen.rsquared:.5f}")
print(f"Fitted values identical: "
f"{np.allclose(default.fittedvalues, chosen.fittedvalues)}")
print("\nA coefficient table is unreadable without knowing the reference.")
print("Put it in the caption of every regression table you publish.")
With the alphabetical reference basic, premium reads +30.243 and standard +14.666. Relevelled to standard, the same model reports basic at โ14.666 and premium at +15.576. R-squared is 0.61303 in both cases and the fitted values are confirmed identical โ it is the same fit. Only the comparisons moved, and the second set is the one a commercial reader can use directly.
The mistake this prevents
The mistake is publishing a coefficient table without naming the reference. Every number in it is a difference from something the reader cannot see.
Takeaway
Set the reference to the meaningful baseline with C(var, Treatment(reference=...)) and state it in the table caption. Changing it is presentation, not modelling.
