Tutorials › Exam SRM - Statistics for Risk Modeling › Binary Predictors as Indicator Variables

Exam SRM · Multiple Regression Estimation · Tutorial 42 of 926

Binary Predictors as Indicator Variables

See how a zero-one indicator represents two groups in an OLS model and how its coefficient measures their fitted-response difference under the stated model.

Intermediate 10 min read

What You'll Learn

  • Define a zero-one indicator for a two-level predictor
  • Interpret the intercept and indicator coefficient in an intercept-only model
  • Derive why the indicator coefficient equals the difference in group averages in that model
  • Interpret an indicator coefficient while holding a continuous predictor fixed
  • Distinguish a conditional fitted difference from a raw group-average difference
  • Identify coding and interpretation traps that can reverse or distort a conclusion

Why Use an Indicator Variable?

A regression model can include group membership as a predictor, even though group labels such as “standard” and “enhanced” are not numerical measurements. The usual approach is to represent membership with a zero-one indicator. Its coefficient then describes how the fitted response differs between the two coded groups, within the model being fitted.

The interpretation depends on what else is in the regression. In a model with only an intercept and the indicator, the coefficient is the difference between the two groups’ sample averages. When other predictors are included, the coefficient is a fitted-response difference with those predictors held fixed. These statements are related, but they are not interchangeable.

Definition: For a two-level categorical predictor, an indicator variable \(D\) takes the value \(0\) for one level and \(1\) for the other. In the model \(Y_i=\beta_0+\beta_1D_i+\varepsilon_i\), \(\beta_0\) is the fitted response for the \(D=0\) group, and \(\beta_1\) is the fitted-response difference for the \(D=1\) group relative to the \(D=0\) group.

The Intercept-and-Indicator Model

Suppose \(Y_i\) is a quantitative response and \(D_i\) records membership in one of two groups. The intercept-and-indicator regression is

$$ Y_i=\beta_0+\beta_1D_i+\varepsilon_i,\qquad D_i\in\{0,1\}. $$

The corresponding fitted value is \(\hat{Y}_i=\hat{\beta}_0+\hat{\beta}_1D_i\). If \(D_i=0\), the fitted value is \(\hat{\beta}_0\). If \(D_i=1\), it is \(\hat{\beta}_0+\hat{\beta}_1\). Thus, the difference between the two fitted values is

$$ (\hat{\beta}_0+\hat{\beta}_1)-\hat{\beta}_0=\hat{\beta}_1. $$

This interpretation follows directly from the coding. The coefficient has the same units as the response: if \(Y\) is measured in dollars, \(\hat{\beta}_1\) is in dollars; if \(Y\) is measured in days, it is in days.

For the ordinary least-squares group-average result below, the model includes an intercept and the indicator, both groups have at least one observation, and the fit minimizes the sum of squared residuals. No distributional assumption is needed for that algebraic result. For a statistical interpretation as a conditional mean model, one commonly writes \(E(Y_i\mid D_i)=\beta_0+\beta_1D_i\). The OLS identity itself does not establish that group membership causes a response difference.

Why the OLS Coefficients Equal Group Averages

Let \(\bar{Y}_0\) denote the sample average of the responses with \(D=0\), and let \(\bar{Y}_1\) denote the sample average for \(D=1\). In the indicator-only model, every observation in group 0 has the same fitted value, \(\beta_0\), and every observation in group 1 has the same fitted value, \(\beta_0+\beta_1\). To find the OLS estimates, minimize the residual sum of squares separately over those two fitted values.

1
Write the two groups’ contributions to the residual sum of squares.
For a candidate pair of coefficients, the sum is \(\sum_{D_i=0}(Y_i-\beta_0)^2+\sum_{D_i=1}(Y_i-(\beta_0+\beta_1))^2\).
2
Minimize with respect to each group’s fitted value.
The sum of squared deviations within a group is minimized when its fitted value equals that group’s sample average. Therefore, \(\hat{\beta}_0=\bar{Y}_0\) and \(\hat{\beta}_0+\hat{\beta}_1=\bar{Y}_1\).
3
Subtract to obtain the indicator coefficient.
Subtracting the first fitted value from the second gives \(\hat{\beta}_1=\bar{Y}_1-\bar{Y}_0\).

This result depends on the model having no other predictors. It is not a general rule that an indicator coefficient in every multiple regression equals the difference between the two groups’ unadjusted sample averages.

Worked Example: Estimating the Difference Between Two Groups

A hypothetical monitoring study records response values 12, 16, and 20 for group \(D=0\), and 15 and 19 for group \(D=1\). Fit the OLS model with an intercept and the indicator only. Find the coefficients, fitted values, and residual sum of squares.

Method. In this model, the intercept is the \(D=0\) sample average and the indicator coefficient is the \(D=1\) average minus the \(D=0\) average.

First calculate the group averages:

$$ \bar{Y}_0=\frac{12+16+20}{3}=\frac{48}{3}=16, \qquad \bar{Y}_1=\frac{15+19}{2}=\frac{34}{2}=17. $$

Therefore,

$$ \hat{\beta}_0=16,\qquad \hat{\beta}_1=17-16=1. $$

The fitted value for each observation in group 0 is \(16\), and the fitted value for each observation in group 1 is \(16+1=17\). The residuals, in the order given, are \(-4,0,4\) for group 0 and \(-2,2\) for group 1. Hence,

$$ \mathrm{RSS}=(-4)^2+0^2+4^2+(-2)^2+2^2=16+0+16+4+4=40. $$

Check. The residuals sum to zero within each group: \(-4+0+4=0\) and \(-2+2=0\), as expected when each group’s fitted value is its sample average. A common mistake is to use 15 as the group-1 average and calculate \(15-16=-1\). That ignores the observation 19. Including both group-1 responses gives an average of 17 and a coefficient of \(1\), not \(-1\).

Adding a Continuous Predictor

An indicator is also useful alongside quantitative predictors. Consider the additive model

$$ Y_i=\beta_0+\beta_1D_i+\beta_2x_i+\varepsilon_i. $$

For a fixed value \(x\), the fitted responses for the two indicator values are \(\hat{\beta}_0+\hat{\beta}_2x\) when \(D=0\), and \(\hat{\beta}_0+\hat{\beta}_1+\hat{\beta}_2x\) when \(D=1\). Their difference is \(\hat{\beta}_1\). This is a conditional fitted-response difference: it compares the coded groups at the same value of \(x\) under this additive model.

The additive model specifies that this difference is the same at every \(x\). It does not include a group-by-\(x\) interaction. If the model or the data do not support a common difference, that is a separate modeling issue; the coefficient here should be interpreted according to the model actually written.

Worked Example: Interpreting an Indicator with a Continuous Predictor

A hypothetical service study records response \(Y\), in minutes, and workload \(x\), in units. The observations are:

Indicator \(D\)Workload \(x\)Response \(Y\)
0112
0214
0316
1115
1217
1319

Fit the additive model \(Y_i=\beta_0+\beta_1D_i+\beta_2x_i+\varepsilon_i\), interpret the indicator coefficient, and predict the response at \(D=1,x=4\).

Method. Check whether the observations lie on a common-slope additive model. For group 0, the response increases by 2 when workload increases by 1: \(14-12=2\) and \(16-14=2\). For group 1, the same changes occur: \(17-15=2\) and \(19-17=2\). Thus the fitted workload slope is \(\hat{\beta}_2=2\).

At each workload value, the group-1 response exceeds the group-0 response by 3: \(15-12=3\), \(17-14=3\), and \(19-16=3\). Therefore \(\hat{\beta}_1=3\). Using the group-0 observation at \(x=1\), \(12=\hat{\beta}_0+2(1)\), so \(\hat{\beta}_0=10\). The fitted model is

$$ \hat{Y}=10+3D+2x. $$

At the same workload, the model’s fitted-response difference between \(D=1\) and \(D=0\) is 3 minutes. For \(D=1,x=4\), the prediction is

$$ \hat{Y}=10+3(1)+2(4)=10+3+8=21\text{ minutes}. $$

Check. The model gives fitted values 12, 14, and 16 for group 0, and 15, 17, and 19 for group 1, exactly matching all six observations; the residual sum of squares is zero. The common mistake avoided here is interpreting \(\hat{\beta}_1\) as a change per workload unit. The workload change is represented by \(\hat{\beta}_2=2\); the indicator coefficient is the group difference at fixed workload.

Why the Raw Group Difference Can Change

When a continuous predictor is included, the groups may have different distributions of that predictor. Consequently, their raw response averages can differ by something other than the indicator coefficient. The coefficient compares fitted responses at a common predictor value, whereas a raw average combines responses observed at the values of \(x\) present in each group.

Worked Example: Raw Averages Versus the Adjusted Difference

A hypothetical assessment uses an additive response model with workload \(x\) and group indicator \(D\). The observations are:

\(D\)\(x\)\(Y\)
005
017
029
1213
1315
1417

Determine the additive OLS coefficients, compare the raw group averages, and find the fitted group difference at \(x=2\).

Method. The responses increase by 2 for each one-unit increase in workload within each group: \(7-5=2\), \(9-7=2\), \(15-13=2\), and \(17-15=2\). The fitted workload slope is therefore 2. At the shared workload \(x=2\), the group responses are 9 and 13, a difference of 4. The additive model’s indicator coefficient is consequently 4. The intercept follows from the group-0 observation at \(x=0\), giving \(\hat{\beta}_0=5\). Thus,

$$ \hat{Y}=5+4D+2x. $$

The raw group averages are

$$ \bar{Y}_0=\frac{5+7+9}{3}=7, \qquad \bar{Y}_1=\frac{13+15+17}{3}=15, \qquad \bar{Y}_1-\bar{Y}_0=8. $$

The raw difference is 8, while the model’s conditional difference at \(x=2\) is

$$ (5+4+2(2))-(5+2(2))=13-9=4. $$

Check. Substitution into the fitted model reproduces all six responses, so the residual sum of squares is zero. The raw average difference of 8 includes the fact that the \(D=1\) group has larger workload values overall. The common mistake is to report the raw-average difference as the indicator coefficient in a multiple regression; here that would give 8 instead of 4.

Practical Checks and Common Traps

Before interpreting an indicator coefficient, check exactly which group has been assigned 0 and which has been assigned 1, confirm that an intercept is included, and read the other predictors in the model. In the intercept-and-indicator model, the coefficient is the difference between the two sample averages. In an additive multiple regression, it is the difference between fitted responses at the same values of the other predictors.

  • Reversing the coding without updating the interpretation. The group assigned 1 is the group whose fitted response is compared with the group assigned 0. If the coding is reversed, the direction of that comparison reverses.
  • Confusing an indicator coefficient with a slope. A zero-one indicator changes by one unit between groups, so its coefficient is a group difference in response units, not a rate of change per unit of a continuous predictor.
  • Using raw averages in a multiple regression. Raw averages do not generally equal an adjusted indicator coefficient when other predictors are included.
  • Leaving out a group from the data. If all observations have the same indicator value, the intercept and indicator cannot separately determine fitted values for both groups. A comparison between two observed groups requires observations in both groups.
  • Making a causal claim from the coefficient alone. The regression coefficient describes a fitted association under the specified model. It does not, by itself, establish that group membership caused the response difference.

Correctly interpreting an indicator is a basic multiple-regression skill aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus. The main discipline is to state the coding and the model before describing the coefficient.

Check Your Understanding

For each problem, identify the relevant model and distinguish a group average from a conditional fitted difference where needed.

  1. A hypothetical intercept-and-indicator OLS fit uses responses 8, 10, and 12 for \(D=0\), and 11 and 13 for \(D=1\). Find \(\hat{\beta}_0\), \(\hat{\beta}_1\), and the fitted value for a \(D=1\) observation. (Answer: \(\hat{\beta}_0=10,\ \hat{\beta}_1=12-10=2\), fitted value \(12\).)
  2. In the model \(\hat{Y}=24-5D+3x\), calculate the fitted responses for \(D=0\) and \(D=1\) at \(x=4\), and state the group difference. (Answer: \(36\) for \(D=0\), \(31\) for \(D=1\); the \(D=1\) fitted response is 5 units lower.)
  3. A hypothetical additive model is \(\hat{Y}=6+2D+4x\). Find the fitted response for \(D=1,x=3\), then compare it with the fitted response for \(D=0,x=3\). (Answer: \(20\) for \(D=1\), \(18\) for \(D=0\); the difference is \(2\).)
  4. In an indicator-only fit, group 0 has responses 4 and 10, while group 1 has responses 9, 11, and 13. Compute both fitted group values and the indicator coefficient. (Answer: \(\bar{Y}_0=7,\ \bar{Y}_1=11,\ \hat{\beta}_0=7,\ \hat{\beta}_1=4\).)
  5. A hypothetical additive model is \(\hat{Y}=10+3D+2x\). The raw group-average difference in a data set is 7. Find the model’s fitted group difference at \(x=5\), and explain whether the raw difference replaces that coefficient. (Answer: the fitted difference is \(3\); the raw difference does not replace it because the model compares groups at the same \(x\).)
Clinical Biostats