Why Build an Indicator Table?
A regression model can include a categorical predictor by representing its categories with indicator variables. The model equation gives the rule, but a row-by-row table makes that rule easier to apply: each category gets a specific pattern of zeros and ones, and that pattern determines the fitted value. This is especially useful when checking calculations or reading a model with several groups.
Here we consider a predictor with three categories, called A, B, and C. We use A as the reference category. Under reference-cell coding, A gets zeros in both indicator columns; the other categories each get a one in their own column.
In this model, \(Y_i\) is the response for observation \(i\), \(\beta_0,\beta_1,\beta_2\) are model coefficients, and \(\varepsilon_i\) is the error. The fitted value, denoted \(\hat{Y}_i\), is obtained by using the model’s estimated coefficients and leaving out the error term. The indicator table itself follows from the category membership, not from the observed response.
The Three Rows of the Indicator Table
The coding rule creates one row for each possible category. The first indicator records membership in B; the second records membership in C. Because each observation belongs to exactly one of the three categories, its two indicators have exactly one of these patterns:
| Category of observation \(i\) | \(D_{Bi}\) | \(D_{Ci}\) | Model expression for fitted value |
|---|---|---|---|
| A (reference) | 0 | 0 | \(\hat{\beta}_0\) |
| B | 1 | 0 | \(\hat{\beta}_0+\hat{\beta}_1\) |
| C | 0 | 1 | \(\hat{\beta}_0+\hat{\beta}_2\) |
The hats indicate estimated coefficients. For an observation in A, substituting zeros into the fitted model leaves only \(\hat{\beta}_0\). For an observation in B, \(D_{Bi}=1\) and \(D_{Ci}=0\), so the fitted value is \(\hat{\beta}_0+\hat{\beta}_1\). For an observation in C, \(D_{Bi}=0\) and \(D_{Ci}=1\), giving \(\hat{\beta}_0+\hat{\beta}_2\). These are the three category-specific fitted values.
The coefficients have a direct interpretation in this setup: \(\hat{\beta}_0\) is the fitted value for A, while \(\hat{\beta}_1\) and \(\hat{\beta}_2\) are the differences between the fitted values for B and A, and C and A, respectively. The units of all three coefficients are the units of the response.
Worked Example: Coding Three Training Groups
Suppose a hypothetical data set records an assessment score, in points, for people in one of three training groups: Standard, Online, or Blended. Use Standard as the reference category. Construct the indicator row for each person below and calculate the fitted value from a model with estimated coefficients \(\hat{\beta}_0=72\), \(\hat{\beta}_1=5\), and \(\hat{\beta}_2=-3\) points.
| Person | Training group | \(D_{\text{Online}}\) | \(D_{\text{Blended}}\) | Fitted score |
|---|---|---|---|---|
| 1 | Standard | 0 | 0 | 72 |
| 2 | Online | 1 | 0 | 77 |
| 3 | Blended | 0 | 1 | 69 |
For person 1, the category is Standard, so the indicator row is \((0,0)\). Substitution gives \(\hat{Y}=72+5(0)-3(0)=72\) points. For person 2, the row is \((1,0)\), giving \(\hat{Y}=72+5(1)-3(0)=77\) points. For person 3, the row is \((0,1)\), giving \(\hat{Y}=72+5(0)-3(1)=69\) points. The negative coefficient for Blended means its fitted score is 3 points below Standard in this model; it does not mean that every person in Blended has a score exactly 3 points lower.
From Group Data to the Fitted Values
The table describes the coding; a fitted model supplies coefficient estimates. In the special case of a model with just this categorical predictor and an intercept, the least-squares fitted value for each category is its sample mean response. The estimates of the indicator coefficients can therefore be obtained from the three group means.
To see why, consider one category with observed responses \(y_1,\ldots,y_m\), and suppose its fitted value is a constant \(a\). The sum of squared residuals in that category is minimized when \(a\) equals its sample mean \(\bar{y}\). This follows by expanding the sum of squares:
The cross-product term disappears because \(\sum_{j=1}^{m}(y_j-\bar{y})=0\). The first term on the right does not depend on \(a\), and the second is nonnegative, reaching its minimum when \(a=\bar{y}\). Applied separately to the three categories, this means the fitted values are the three sample group means. Equating these fitted values to the three rows of the indicator table gives:
Here \(\bar{y}_A,\bar{y}_B,\bar{y}_C\) denote the observed mean responses in categories A, B, and C. This group-mean result is specific to the model containing an intercept and this categorical predictor alone. When other predictors are included, the fitted values also depend on those predictors.
Worked Example: Calculating Coefficients From Group Means
Consider a hypothetical measurement of task-completion time, in minutes, for three groups. The recorded times are A: 8, 10, and 12; B: 13, 15, and 17; C: 9, 11, and 13. Use A as the reference category and fit the model with the categorical predictor alone.
First calculate each group mean:
The fitted value for A is its mean, so \(\hat{\beta}_0=10\) minutes. The B coefficient is the difference between the B and A means: \(\hat{\beta}_1=15-10=5\) minutes. The C coefficient is \(\hat{\beta}_2=11-10=1\) minute. Thus the estimated model is:
The table verifies all three fitted values. For A, the row \((0,0)\) gives \(10+5(0)+1(0)=10\) minutes. For B, \((1,0)\) gives \(10+5(1)+1(0)=15\) minutes. For C, \((0,1)\) gives \(10+5(0)+1(1)=11\) minutes. Each fitted value matches the corresponding sample group mean.
Checking the Model and the Coding
The arithmetic is simple, but the row assignment must match the data. Before interpreting fitted values, identify the categories, choose which one is the reference in the specified coding, and check each observation’s membership. The response is quantitative, and the predictor categories are distinct and exhaustive for the observations being modeled.
The equation also has a statistical interpretation. It represents the conditional mean response as a category-specific value plus an error:
For these statements to describe the group means, the errors must have mean zero within each category. The indicator table and the substitution calculations are algebraic and do not require normally distributed errors. If conventional regression inference is later used, its additional error assumptions must also be assessed; calculating these fitted values alone does not establish those assumptions.
Specify which category is the reference and which categories receive indicator columns.
The reference category receives \((0,0)\); the other two categories receive \((1,0)\) and \((0,1)\), respectively.
Use the estimated coefficients and calculate the fitted value in the response’s units.
All observations in the same category receive the same fitted value when this is the only predictor in the model.
Worked Example: Checking a Mixed List of Observations
A hypothetical model predicts a laboratory measurement in milligrams per liter for samples classified as Low, Medium, or High. Low is the reference category, and the fitted equation is \(\hat{Y}=4.2+1.1D_{\text{Medium}}+2.6D_{\text{High}}\). Find the indicator row and fitted value for a sample from each category.
For a Low sample, both indicators are zero: \((0,0)\). Its fitted value is \(4.2+1.1(0)+2.6(0)=4.2\) mg/L.
For a Medium sample, the row is \((1,0)\). Its fitted value is \(4.2+1.1(1)+2.6(0)=5.3\) mg/L.
For a High sample, the row is \((0,1)\). Its fitted value is \(4.2+1.1(0)+2.6(1)=6.8\) mg/L. The row is determined by the category label, not by the sample’s measured response. If another sample is also classified High, it receives the same fitted value in this model.
Common Mistake: Giving an Observation the Wrong Row
A frequent error is to code A, B, and C as \((0,0)\), \((1,1)\), and \((0,1)\). That assigns both indicators a value of 1 for category B, even though \(D_B\) indicates membership in B and \(D_C\) indicates membership in C. The correct B row is \((1,0)\). Another error is to treat the category labels as numerical scores and substitute them directly into this model. The categories are group labels; the indicator columns specify how each label enters the equation.
Check Your Understanding
Use the indicator-table rule and show the substitution needed for each calculation.
- With A as the reference category, what indicator row corresponds to an observation in C?
- If \(\hat{\beta}_0=20\), \(\hat{\beta}_1=-2\), and \(\hat{\beta}_2=4\), calculate the fitted value for category B.
- For a model with only an intercept and a three-category predictor, the sample means are 6, 9, and 8 units for A, B, and C. Find the three coefficient estimates using A as the reference.
- Explain why an observation’s response value does not determine its indicator row.
- In a model with only the categorical predictor, what fitted value does every observation in category A receive when A is the reference?