Categorical Predictors & Dummy Coding
Regression runs on numbers — it multiplies each predictor by a coefficient. So what do you do with a predictor like treatment group, country, or education level, where the values are categories, not amounts? You can't just label them 1, 2, 3 (that would falsely claim group 3 is "three times" group 1). The fix is dummy coding.
How dummy coding works
For a categorical variable with k groups, you create k − 1 new 0/1 indicator variables. One group is left out as the reference; each dummy variable flags membership in one of the other groups. Three groups (Control, Drug A, Drug B) with Control as reference becomes two dummies:
🎮 Coefficients Are Just Group Differences
Set each group's average outcome. The intercept equals the reference group's mean; every other coefficient is simply that group's distance from the reference (the dashed line).
Reading the coefficients
This is the part that makes regression with categories so intuitive once it clicks:
- The intercept is the predicted outcome for the reference group (all dummies = 0).
- Each dummy coefficient is the difference between that group's mean and the reference group's mean.
- Each coefficient's p-value tests whether that group differs significantly from the reference.
The big reveal: a regression with a single categorical predictor is a t-test (for two groups) or a one-way ANOVA (for more). t-tests, ANOVA, and regression are the same linear model wearing different clothes.
Choosing the reference
Switch the reference group above and watch the coefficients change — but notice the predicted group means stay identical. The reference is just the baseline you measure everything against, so pick the one that makes your comparisons most meaningful: the control condition, the placebo, the "standard" category. The model is the same either way; only the story the coefficients tell changes.
The other coding scheme you'll meet
Dummy coding (software often calls it treatment coding, and it is R's default) is not the only way to turn groups into numbers. Effect coding uses −1, 0 and 1 instead of 0 and 1, and it moves the baseline: the intercept becomes the grand mean of all groups rather than one group's mean, and each coefficient becomes that group's distance from the grand mean rather than from a reference. Both schemes fit the identical model and give the identical predictions and R²; they differ only in what the individual coefficients mean. The distinction starts to matter once you add an interaction, because under dummy coding the lower-order terms describe the reference group rather than an average, which is the single most common misreading of a factorial regression.
Why it matters: almost every real dataset mixes numeric and categorical predictors. Dummy coding is what lets a single regression handle "dose (mg) and treatment group and sex and region" all at once — the foundation for the rest of applied modeling.
Common questions
Why do I create k − 1 dummy variables instead of k?
Because the k-th dummy is perfectly redundant — if a case is 0 on all others, it must be the reference group, so a full set would be perfectly collinear with the intercept (the "dummy variable trap"; software would drop one anyway). The reference group's mean lives in the intercept, and each dummy coefficient measures a difference from it.
What if my categorical variable has 20 or 50 levels?
Dummy coding still works, but it gets expensive: 50 countries means 49 dummies, 49 degrees of freedom spent, and coefficients for the small categories that rest on a handful of cases each. Three ways out, in rough order of preference. Collapse levels into meaningful groups you can defend in advance (region rather than country), which is a coding decision and belongs in your codebook. Fit the variable as a random effect in a multilevel model, which shares information across levels instead of estimating each one alone. Or, if the levels genuinely have an order and roughly even spacing, enter it as a single numeric predictor and spend one degree of freedom rather than 49.
Is ANOVA just a special case of regression?
Run a regression with one dummy-coded categorical predictor and you get literally the same F, p, and group means as the one-way ANOVA; two groups reduces further to the t-test. ANOVA, t-tests, ANCOVA, and regression are one linear model in different notation, which is why learning regression unlocks all of them at once.