Unit 09.01: Levels minus one, all relative to the reference
A numeric predictor gives you one slope. A factor with four levels gives you three coefficients, and none of them is 'the effect of region'.
Levels minus one, all relative to the reference
R encodes a factor as a set of indicator variables — one fewer than the number of levels. Each coefficient is the average difference between that level and the reference level, 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 between groups 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.
suppressPackageStartupMessages(library(broom))
set.seed(602)
n <- 240
d <- data.frame(
size = runif(n, 40, 200),
region = factor(rep(c("north", "south", "east", "west"), each = 60))
)
offset <- c(north = 0, south = 30, east = -20, west = 55)[as.character(d$region)]
d$price <- 50 + 2.1 * d$size + offset + rnorm(n, 0, 20)
model <- lm(price ~ size + region, data = d)
print(tidy(model)[, c("term", "estimate", "std.error", "p.value")])
cat("\nOne numeric predictor gives ONE slope.\n")
cat("A factor with", nlevels(d$region), "levels gives",
nlevels(d$region) - 1, "coefficients -- one per level except the reference.\n")
cat("Reference level:", levels(d$region)[1], "\n\n")
cat("Each region coefficient is that region's average price difference from\n")
cat(levels(d$region)[1], ", at the same size. The line is parallel for every\n")
cat("region; only its height moves.\n")
Four levels produce 3 coefficients. The reference is east, alphabetically first, and the others read as differences from it: north +16.2, south +46.5, west +66.4, all at the same size. The size slope of 2.10 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 the factor as a whole requires a model comparison rather than reading a single p-value.
