Tutorials › Regression Analysis (Undergraduate) › Predicted Means for a Two-Level Factor

Predictions for Conditional Means · Tutorial 696 of 991

Predicted Means for a Two-Level Factor

Use a reference-coded indicator to calculate and interpret a fitted mean for either level of a two-level factor, with or without additional covariates.

Beginner 9 min read

What You'll Learn

  • Identify the reference and comparison levels of a two-level factor.
  • Write the fitted-mean equation for a reference-coded regression.
  • Calculate fitted means for both factor levels from estimated coefficients.
  • Substitute specified covariate values to predict a conditional mean for each level.
  • Distinguish a profile-based fitted mean from a group-wide average or an individual outcome.

From a Two-Level Factor to Two Fitted Means

A regression model can include a factor such as program status, clinic type, or whether a policy is in place. If the factor has two levels, reference coding represents it with one indicator variable. The fitted regression equation can then provide a predicted mean for either level. When the model includes other predictors, each prediction also depends on the values specified for those covariates.

The key is to keep the factor level and the covariate profile explicit. A prediction for one level is not a universal mean for everyone in that group when other predictors are in the model: it is the model’s fitted mean at the particular covariate values entered.

Definition: For a two-level factor, choose one level as the reference level and code it as \(D=0\). Code the other, comparison level, as \(D=1\). In a reference-coded regression, the fitted mean at a specified covariate profile is calculated by substituting the chosen value of \(D\) and the covariate values into the fitted regression equation.

The Model and Its Fitted Means

Suppose \(Y_i\) is a quantitative response for observation \(i\), \(D_i\) is the indicator for a two-level factor, and \(x_{i1},\ldots,x_{ip}\) are additional covariates. An additive linear model is

$$ Y_i=\beta_0+\beta_1D_i+\beta_2x_{i1}+\cdots+\beta_{p+1}x_{ip}+\varepsilon_i. $$

Here the conditional mean is assumed to follow the displayed linear expression, so \(E(\varepsilon_i\mid D_i,x_{i1},\ldots,x_{ip})=0\). The factor has the same additive shift at every covariate profile: this model contains no interaction between \(D_i\) and the covariates. For ordinary least squares fitting, observations are assumed to be independent, and the specified conditional mean must be appropriate for the prediction being made. Constant error variance and normal errors are additional assumptions used for some forms of inference, but are not needed just to substitute values into a fitted equation.

After fitting the model, replace each coefficient by its estimate. With one covariate for illustration, the fitted equation is \(\widehat{Y}=\hat{\beta}_0+\hat{\beta}_1D+\hat{\beta}_2x\). Setting \(D=0\) gives the reference-level fitted mean; setting \(D=1\) gives the comparison-level fitted mean. Covariate values must be supplied for both.

$$ \widehat{Y}_{\text{reference}}(x)=\hat{\beta}_0+\hat{\beta}_2x \qquad \widehat{Y}_{\text{comparison}}(x)=\hat{\beta}_0+\hat{\beta}_1+\hat{\beta}_2x $$

In the model with several covariates, include every estimated covariate term in both calculations. The intercept is the fitted mean for the reference level when all numerical covariates equal zero; it need not describe a practically relevant person or case. The fitted mean for the comparison level also includes \(\hat{\beta}_1\), the estimated indicator coefficient.

Worked Example: Predictions With the Factor as the Only Predictor

Consider hypothetical recovery times, in days, for people in two groups. The reference level is standard care, and the comparison level is a new program. The observed times are 12, 15, 13, and 14 days for standard care, and 10, 11, 12, and 9 days for the new program. Fit a model with an intercept and the indicator \(D\), where \(D=1\) denotes the new program.

The group averages are \((12+15+13+14)/4=54/4=13.5\) days for standard care and \((10+11+12+9)/4=42/4=10.5\) days for the new program. In this model, the fitted equation is \(\widehat{Y}=\hat{\beta}_0+\hat{\beta}_1D\), with \(\hat{\beta}_0=13.5\) and \(\hat{\beta}_1=10.5-13.5=-3.0\).

For standard care, set \(D=0\): \(\widehat{Y}=13.5+(-3.0)(0)=13.5\) days. For the new program, set \(D=1\): \(\widehat{Y}=13.5+(-3.0)(1)=10.5\) days. These are the fitted group means in this factor-only model. They summarize the fitted model; they do not predict that every person in a group will have exactly that recovery time.

Why the Factor-Only Model Gives Group Averages

This result follows directly from least squares. Let \(a\) be the fitted value for the reference group and \(c\) the fitted value for the comparison group. The intercept-and-indicator model can represent these two values because \(a=\beta_0\) and \(c=\beta_0+\beta_1\). Its residual sum of squares is the sum of squared deviations from \(a\) in the reference group and from \(c\) in the comparison group.

For any group with observations \(y_1,\ldots,y_m\) and average \(\bar{y}\), the following identity holds for any proposed fitted value \(q\):

$$ \sum_{i=1}^{m}(y_i-q)^2 = \sum_{i=1}^{m}(y_i-\bar{y})^2+m(q-\bar{y})^2. $$

The first term on the right does not depend on \(q\), and the second is minimized when \(q=\bar{y}\). Thus least squares chooses the average of the observed responses separately in each group. The fitted intercept is the reference-group average, and the indicator coefficient is the comparison-group average minus the reference-group average. This exact group-average result applies to the factor-only model; with covariates included, predictions instead depend on the supplied covariate profile.

Adding Covariates: Predict at a Specified Profile

When covariates are included, calculate a fitted mean by putting the desired values into every term of the fitted equation. To predict for both levels of the factor at the same covariate profile, keep the covariate values fixed and change only \(D\). To predict at a different profile, substitute the new covariate values as well. These are profile-based predictions, not necessarily averages over all people observed at either factor level.

Worked Example: Two Factor Levels at a Given Profile

Suppose a hypothetical fitted model predicts systolic blood pressure, in mmHg, from care type, age, and baseline blood pressure. Standard care is the reference level; \(D=1\) indicates a new care program. The fitted equation is

$$ \widehat{Y}=24-3D+0.20(\text{age})+0.50(\text{baseline blood pressure}). $$

For a hypothetical profile with age 50 years and baseline blood pressure 120 mmHg, the standard-care prediction is

$$ \widehat{Y}=24-3(0)+0.20(50)+0.50(120) =24+0+10+60=94\text{ mmHg}. $$

For the same profile in the new program, set \(D=1\):

$$ \widehat{Y}=24-3(1)+0.20(50)+0.50(120) =24-3+10+60=91\text{ mmHg}. $$

Thus, for this specified age and baseline pressure, the model’s fitted mean is 94 mmHg under standard care and 91 mmHg under the new program. The model is additive, so the age and baseline terms are included in both predictions; the indicator is coded according to the selected care type. This calculation alone does not establish a causal effect of the program.

Worked Example: Updating Predictions When Covariates Change

A hypothetical regression predicts an exam score, in points, using program participation, prior score, and attendance hours. The reference level is no program, and \(D=1\) denotes program participation. Suppose the fitted equation is

$$ \widehat{Y}=22+4D+0.65(\text{prior score})+0.30(\text{attendance hours}). $$

For a hypothetical student profile with prior score 70 points and 10 attendance hours, the prediction without the program is

$$ \widehat{Y}=22+4(0)+0.65(70)+0.30(10) =22+0+45.5+3=70.5\text{ points}. $$

For the same profile with program participation, it is

$$ \widehat{Y}=22+4(1)+0.65(70)+0.30(10) =22+4+45.5+3=74.5\text{ points}. $$

Now consider a second hypothetical profile with prior score 80 points and 12 attendance hours. The prediction without the program is \(22+4(0)+0.65(80)+0.30(12)=22+0+52+3.6=77.6\) points. With the program, it is \(22+4(1)+0.65(80)+0.30(12)=22+4+52+3.6=81.6\) points. The covariate changes alter both fitted means; the factor coding still specifies which of the two factor levels is being predicted.

Reading the Predictions Carefully

A fitted mean is the value of the model’s estimated conditional mean at the specified predictor values. It describes the average response represented by the model for cases with those values, not the exact response of a particular individual. Individual outcomes can vary around the conditional mean.

Check three things before reporting a prediction:

  • Reference coding: state which factor level has \(D=0\) and which has \(D=1\).
  • Profile: report the values used for each additional covariate, including units.
  • Response: give the predicted value in the response’s units and label it as a fitted mean.

It is also important that a profile be meaningful for the fitted model. For example, substituting covariate values far outside the range represented by the data requires extrapolation, and the prediction may not be reliable. A correct substitution is necessary, but it does not by itself ensure that the model is appropriate for every profile.

Common Mistake: Treating the Indicator Coefficient as the Prediction

A common error is to report \(\hat{\beta}_1\) itself as the fitted mean for the comparison group. In the additive reference-coded model, \(\hat{\beta}_1\) is only the indicator’s contribution to the equation. The comparison-level fitted mean also contains the intercept and all covariate contributions. For example, in the blood-pressure model, the fitted mean for the new program at age 50 and baseline pressure 120 mmHg is 91 mmHg, not \(-3\) mmHg.

Another mistake is to give a covariate-based prediction without stating the covariate values. A fitted mean of 94 mmHg in the example is tied to age 50 years and baseline pressure 120 mmHg; it should not be presented as the mean for all people receiving standard care. State the factor level, the covariate profile, and the predicted response together.

Key takeaway: In a reference-coded model, calculate the fitted mean for the reference level with \(D=0\), and for the comparison level with \(D=1\). Include every covariate term in each calculation, and interpret each result at the profile whose values were substituted.

Check Your Understanding

For each question, state the factor level and covariate profile that the prediction refers to.

  1. In a factor-only model with fitted equation \(\widehat{Y}=18+5D\), which level is the reference level, and what are the fitted means for \(D=0\) and \(D=1\)?
  2. A fitted model is \(\widehat{Y}=10-2D+0.5x\). Calculate both fitted means when \(x=8\), and give the response unit as units of \(Y\).
  3. Why does the factor-only intercept-and-indicator model yield the observed average response in each group under least squares?
  4. In a model with a factor and two covariates, what must be specified to report a profile-based fitted mean?
  5. Why is it incorrect to describe a fitted mean as the exact response for every individual with the stated profile?