Tutorials › Regression Analysis (Undergraduate) › Group Differences in Fitted Outcomes Across Predictor Values

Interactions Among Groups · Tutorial 350 of 991

Group Differences in Fitted Outcomes Across Predictor Values

Use group-specific fitted lines to calculate conditional differences and describe how those differences change across predictor values.

Intermediate 8 min read

What You'll Learn

  • Write the fitted line for each of two groups from an interaction model.
  • Calculate the fitted group difference at a specified predictor value.
  • Interpret the group difference and interaction coefficient in context and units.
  • Find how much the fitted difference changes between two predictor values.
  • Check whether the requested comparisons are supported by the observed predictor ranges.
  • Distinguish fitted differences from observed differences and causal effects.

Introduction

When a quantitative predictor is related to an outcome differently across groups, a single group comparison may not tell the whole story. For example, two groups could have different fitted outcomes at one predictor value, and that difference could be larger or smaller at another value. The useful question is therefore often conditional: what is the fitted difference between the groups at this particular predictor value?

A group-by-predictor interaction model answers this by allowing each group to have its own fitted line. This tutorial focuses on calculating the difference between those fitted lines at specified predictor values and describing how the difference changes as the predictor changes. These are model-based comparisons, not automatically causal effects.

The Group-Specific Lines and Their Difference

Let \(Y\) be a quantitative outcome, \(x\) a quantitative predictor, and \(G\) an indicator for group membership. Set \(G=0\) for the reference group and \(G=1\) for the other group. A linear model with a group-by-predictor interaction is

$$ Y_i=\beta_0+\beta_1x_i+\beta_2G_i+\beta_3x_iG_i+\varepsilon_i. $$

Here, \(\varepsilon_i\) is the error for observation \(i\). The fitted value is the model's predicted outcome, calculated by replacing the coefficients with their estimates and omitting the error term. When \(G=0\), the terms involving \(G\) vanish. When \(G=1\), both the group term and the product term contribute.

Definition: For a two-group linear interaction model, the fitted difference at \(x\), defined as the fitted outcome for group \(G=1\) minus the fitted outcome for group \(G=0\), is the difference between the two group-specific fitted lines at that predictor value. If the fitted coefficients are \(\hat{\beta}_0,\hat{\beta}_1,\hat{\beta}_2,\hat{\beta}_3\), then this difference is \(\hat{\beta}_2+\hat{\beta}_3x\).

The difference formula follows directly from writing both fitted lines and subtracting. For group \(G=0\), the fitted outcome is \(\hat{\beta}_0+\hat{\beta}_1x\). For group \(G=1\), it is \(\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2+\hat{\beta}_3x\). Therefore,

$$ \begin{aligned} \hat{Y}_{G=1}(x)-\hat{Y}_{G=0}(x) &=(\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2+\hat{\beta}_3x) -(\hat{\beta}_0+\hat{\beta}_1x)\\ &=\hat{\beta}_2+\hat{\beta}_3x. \end{aligned} $$

The shared terms cancel. Thus \(\hat{\beta}_2\) is the fitted group difference specifically at \(x=0\), while \(\hat{\beta}_3\) describes how the fitted difference changes for each one-unit increase in \(x\). Equivalently, \(\hat{\beta}_3\) is the difference between the groups' fitted slopes. The units of \(\hat{\beta}_2\) are outcome units; the units of \(\hat{\beta}_3\) are outcome units per predictor unit.

More generally, comparing the fitted differences at two predictor values \(x_1\) and \(x_2\) gives

$$ \big(\hat{\beta}_2+\hat{\beta}_3x_2\big) -\big(\hat{\beta}_2+\hat{\beta}_3x_1\big) =\hat{\beta}_3(x_2-x_1). $$

This makes the change especially clear: if the predictor increases by \(x_2-x_1\) units, the fitted group difference changes by \(\hat{\beta}_3(x_2-x_1)\) outcome units. A positive value means the difference defined as group 1 minus group 0 increases; a negative value means it decreases.

Model Conditions for These Comparisons

The algebra above applies to the specified fitted lines. To use those lines as useful summaries of a relationship, the model should be appropriate for the data and the comparisons should be made where the data provide support. In particular, the conditional mean of \(Y\) should be reasonably represented by a straight line in \(x\) within each group, with group-specific intercepts and slopes. The observations should also be independent when the study design supports that assumption, and the fitted values at the requested \(x\) values should not rely on unsupported extrapolation beyond the groups' observed predictor ranges.

The usual zero-mean error condition is that the expected error is zero conditional on the predictor and group: \(E(\varepsilon_i\mid x_i,G_i)=0\). Constant error variance is commonly used for conventional standard errors and tests, but it is not needed for the subtraction that produces a fitted difference. This tutorial calculates point fitted differences; it does not assess their uncertainty or statistical significance. In each example, the stated predictor values are within the hypothetical data's observed range, and the given equations are assumed to be reasonable fitted linear summaries.

Worked Example: Practice Time and Quiz Scores

Suppose a hypothetical study records quiz score in points (\(Y\)) and hours of practice (\(x\)) for students in two study groups. Group 0 is usual study support, and group 1 is structured practice. The following fitted lines summarize data covering about 1 to 7 practice hours:

$$ \hat{Y}_{G=0}(x)=61+3x,\qquad \hat{Y}_{G=1}(x)=66+2.2x. $$

The lines have different intercepts and slopes, so the fitted difference depends on practice time. Define the difference as group 1 minus group 0:

$$ \hat{Y}_{G=1}(x)-\hat{Y}_{G=0}(x) =(66+2.2x)-(61+3x)=5-0.8x. $$

At \(x=2\) hours, the group 0 fitted score is \(61+3(2)=67\) points, and the group 1 fitted score is \(66+2.2(2)=70.4\) points. Subtracting gives \(70.4-67=3.4\) points. The difference formula gives the same result: \(5-0.8(2)=3.4\) points.

At \(x=6\) hours, the fitted scores are \(61+3(6)=79\) points for group 0 and \(66+2.2(6)=79.2\) points for group 1. The fitted difference is \(79.2-79=0.2\) points, also obtained from \(5-0.8(6)=0.2\). From 2 to 6 hours, the predictor increases by 4 hours and the fitted difference changes by \((-0.8)(4)=-3.2\) points. Thus the model's fitted difference, group 1 minus group 0, decreases by 3.2 points across that interval. This describes a fitted association; it does not show that assigning students to a group would cause the score difference.

Reading the Sign and Units

Always state which group is subtracted from which. If the comparison is group 1 minus group 0, a positive fitted difference means the group 1 fitted outcome is higher at that predictor value; a negative difference means it is lower. Reversing the subtraction reverses the sign, but not the size of the comparison. State the outcome units for the difference and the predictor units for the rate at which it changes.

An intercept difference may be mathematically defined at \(x=0\), even when zero is not a substantively useful predictor value. The conditional difference can still be calculated at a meaningful value within the observed range by using \(\hat{\beta}_2+\hat{\beta}_3x\). Interpret the comparison at the value actually chosen rather than treating the intercept difference as the group difference everywhere.

Worked Example: Building Temperature and Energy Use

Consider a hypothetical set of buildings with monthly energy use \(Y\) measured in kilowatt-hours and average outdoor temperature \(x\) measured in degrees Celsius. Group 0 consists of buildings with standard insulation; group 1 consists of buildings with upgraded insulation. Suppose the fitted lines, based on buildings observed over temperatures from 5 to 25 degrees Celsius, are

$$ \hat{Y}_{G=0}(x)=1200-18x,\qquad \hat{Y}_{G=1}(x)=1050-15x. $$

The fitted difference for upgraded minus standard insulation is

$$ \hat{Y}_{G=1}(x)-\hat{Y}_{G=0}(x) =(1050-15x)-(1200-18x)=-150+3x. $$

At \(x=10\) degrees Celsius, the standard-insulation fitted use is \(1200-18(10)=1020\) kWh, and the upgraded-insulation fitted use is \(1050-15(10)=900\) kWh. The fitted difference is \(900-1020=-120\) kWh. The negative sign means the fitted monthly use for group 1 is 120 kWh lower at this temperature.

At \(x=20\) degrees Celsius, the corresponding fitted values are \(1200-18(20)=840\) kWh and \(1050-15(20)=750\) kWh. The difference is \(750-840=-90\) kWh. As temperature rises from 10 to 20 degrees, the fitted difference increases by \((-90)-(-120)=30\) kWh. The slope-difference calculation agrees: \(3(20-10)=30\) kWh. The difference becomes less negative over this interval; it remains a comparison of fitted energy use, not evidence that insulation alone caused the difference.

Calculate at the Requested Values

A reliable calculation can be organized in three steps: write the two fitted lines, subtract them in the stated order, and substitute the requested predictor value or values. Evaluating both lines separately is a useful check, especially when signs are involved. If comparing two predictor values, calculate the difference at each and subtract, or use the slope-difference formula \(\hat{\beta}_3(x_2-x_1)\); the answers should agree.

Worked Example: Fertilizer and Crop Yield

For a hypothetical field experiment, let \(x\) be fertilizer in kilograms per plot and \(Y\) be crop yield in kilograms per plot. Let group 0 be crop variety R and group 1 be variety S. Suppose the fitted lines summarize plots with fertilizer amounts in the range 2 to 8 kilograms:

$$ \hat{Y}_{G=0}(x)=18+4.5x,\qquad \hat{Y}_{G=1}(x)=25+3.8x. $$

For variety S minus variety R, the fitted difference is

$$ (25+3.8x)-(18+4.5x)=7-0.7x. $$

At \(x=4\) kilograms, variety R has fitted yield \(18+4.5(4)=36\) kg per plot, while variety S has fitted yield \(25+3.8(4)=40.2\) kg per plot. Therefore, the fitted difference is \(40.2-36=4.2\) kg per plot. At \(x=7\) kilograms, the fitted yields are \(18+4.5(7)=49.5\) and \(25+3.8(7)=51.6\) kg per plot, so the difference is \(51.6-49.5=2.1\) kg per plot.

The predictor increases by 3 kilograms between these comparisons. Since the slope difference is \(3.8-4.5=-0.7\) kg of yield per kilogram of fertilizer, the fitted group difference changes by \((-0.7)(3)=-2.1\) kg per plot. This matches the direct calculation, \(2.1-4.2=-2.1\). Within the range considered, variety S has the higher fitted yield at both specified amounts, but the fitted advantage is smaller at the larger amount. The model comparison alone does not establish that one variety would perform better under a different growing context.

Common Mistake: Treating the Group Coefficient as the Difference Everywhere

A common mistake is to report \(\hat{\beta}_2\) as the group difference at every predictor value. That is only correct at \(x=0\), because the fitted difference is \(\hat{\beta}_2+\hat{\beta}_3x\). For example, in the practice-time model, the group coefficient is 5 points, but the difference at 6 hours is \(5-0.8(6)=0.2\) points, not 5 points.

Another mistake is to interpret a positive interaction coefficient as meaning that group 1 always has a higher fitted outcome. The coefficient \(\hat{\beta}_3\) gives the change in the group 1 minus group 0 difference per predictor unit; it does not by itself give the difference at a particular value. Calculate \(\hat{\beta}_2+\hat{\beta}_3x\) at the value of interest, and preserve the direction of subtraction.

Key takeaway: In a two-group linear interaction model, calculate the fitted difference as \(\hat{\beta}_2+\hat{\beta}_3x\), with the group order stated explicitly. The interaction coefficient tells how quickly that difference changes per unit of the quantitative predictor.

Check Your Understanding

Use the group 1 minus group 0 convention unless a question specifies otherwise.

  1. If the fitted group difference is \(8-1.5x\), what is the fitted difference at \(x=4\), and what are its units if the outcome is measured in points?
  2. For that same difference formula, by how much does the fitted difference change when \(x\) increases from 2 to 6?
  3. Explain why the group coefficient in an interaction model is not generally the group difference at every predictor value.
  4. If a calculated group 1 minus group 0 difference is negative, what does its sign mean in context?
  5. Why should fitted group differences generally be calculated within the observed predictor ranges of both groups?