Tutorials › Regression Analysis (Undergraduate) › Calculate Fitted Outcomes from an Interaction Equation

Quantitative Predictor Interactions · Tutorial 321 of 991

Calculate Fitted Outcomes from an Interaction Equation

Use a fitted equation with a product term to calculate predicted outcomes for specified predictor pairs and compare those predictions carefully.

Intermediate 8 min read

What You'll Learn

  • Identify the predictor values and fitted coefficients needed for a calculation.
  • Substitute a pair of quantitative predictor values into an interaction equation.
  • Keep track of product terms, signs, and units when evaluating predictions.
  • Compare fitted outcomes for two or more specified predictor combinations.
  • Distinguish a predicted mean outcome from an individual observed outcome.
  • Recognize when a calculation uses predictor values beyond the observed data.

Introduction

A fitted regression equation can be used to calculate an outcome prediction for a particular combination of predictor values. When the equation includes a product term, the calculation must include that term for each specified pair. Omitting it changes the prediction, sometimes substantially.

This tutorial focuses on evaluating the equation and comparing the resulting predictions. A numerical prediction is an output of the fitted equation for the inputs supplied; it is not, by itself, evidence that a predictor caused an outcome to change.

The Fitted Interaction Equation

For two quantitative predictors \(X_1\) and \(X_2\), an interaction regression model with a product term can be written as

$$ Y_i=\beta_0+\beta_1X_{1i}+\beta_2X_{2i}+\beta_3X_{1i}X_{2i}+\varepsilon_i. $$

Here, \(Y_i\) is the outcome for observation \(i\), \(X_{1i}\) and \(X_{2i}\) are that observation's predictor values, the \(\beta\) terms are model coefficients, and \(\varepsilon_i\) is the error. After fitting the model, the estimated coefficients are used to form the fitted equation:

$$ \hat{y}=b_0+b_1x_1+b_2x_2+b_3x_1x_2. $$

The lower-case \(x_1\) and \(x_2\) denote the particular predictor values at which a prediction is requested. The \(b\) terms are the estimated coefficients from the fitted model. To calculate a fitted outcome, use the same predictor units and coefficient values as in that fitted equation, multiply the two predictor values to form \(x_1x_2\), and evaluate the whole expression.

Definition: The fitted outcome \(\hat{y}\) at the predictor pair \((x_1,x_2)\) is the value calculated by substituting that pair into the fitted regression equation. It is a model-based prediction of the mean outcome for observations with those predictor values, not a guarantee of the outcome for any particular individual.

The model's mean structure and error assumption explain why the fitted equation represents an outcome prediction. The model specifies a mean that has the displayed product-term form, with the error having conditional mean zero. In fitting and using a regression model, observations are also ordinarily treated as independent; more detailed distributional assumptions are relevant to inference, but are not needed simply to substitute values into an already fitted equation.

$$ E(Y_i\mid X_{1i}=x_1,\ X_{2i}=x_2) =\beta_0+\beta_1x_1+\beta_2x_2+\beta_3x_1x_2, \qquad E(\varepsilon_i\mid X_{1i},X_{2i})=0. $$

Replacing the unknown coefficients in this conditional mean with their fitted estimates gives \(\hat{y}\). Thus, the plug-in calculation estimates a mean outcome at the supplied pair. It does not remove the natural variation of individual outcomes around that mean.

A Reliable Calculation Procedure

Before doing the arithmetic, write down the exact predictor pair and the fitted equation. Then calculate the product term separately, substitute every term with its sign, and simplify. When comparing two pairs, calculate each fitted outcome independently before subtracting or describing the difference. This makes it easier to catch mistakes such as carrying the product from one pair into another.

1
Record the requested pair.
Write the values of \(x_1\) and \(x_2\), with their units, in the order used by the equation.
2
Calculate the product.
Find \(x_1x_2\) using the two values for this prediction.
3
Substitute every term.
Include the intercept, both individual predictor terms, and the product term, preserving coefficient signs.
4
Evaluate and report.
Simplify the arithmetic, retain sensible precision, and state the predicted outcome and its units.
5
Compare only after both predictions are calculated.
State which specified combination has the larger fitted outcome and give the difference in outcome units.

Worked Predictions

Worked Example: Comparing Two Predictor Pairs

Suppose a hypothetical training program has been summarized by the fitted equation below. The outcome is a recovery score in points, \(x_1\) is weekly training hours, and \(x_2\) is a baseline symptom score in points. Calculate and compare the fitted outcomes at \((x_1,x_2)=(2,4)\) and \((5,4)\).

$$ \hat{y}=42+3.2x_1+1.5x_2+0.4x_1x_2. $$

For the first pair, the product is \(2(4)=8\). Substitution gives

$$ \hat{y}(2,4)=42+3.2(2)+1.5(4)+0.4(8) =42+6.4+6+3.2 =57.6\text{ points}. $$

For the second pair, the product is \(5(4)=20\). Therefore,

$$ \hat{y}(5,4)=42+3.2(5)+1.5(4)+0.4(20) =42+16+6+8 =72\text{ points}. $$

The fitted outcome at \((5,4)\) is \(72-57.6=14.4\) points higher than the fitted outcome at \((2,4)\). This comparison is specific to these two predictor pairs and this fitted equation. It does not say that every person who trains for three additional hours will gain 14.4 points.

Worked Example: Checking Signs and the Product Term

In a hypothetical task study, \(Y\) is the number of errors, \(x_1\) is practice time in hours, and \(x_2\) is a fatigue score in points. The fitted equation is

$$ \hat{y}=12-1.5x_1+0.8x_2-0.10x_1x_2. $$

Calculate the fitted number of errors for the pairs \((4,3)\) and \((4,8)\). For \((4,3)\), the product is \(4(3)=12\), so

$$ \hat{y}(4,3)=12-1.5(4)+0.8(3)-0.10(12) =12-6+2.4-1.2 =7.2\text{ errors}. $$

For \((4,8)\), the product is \(4(8)=32\), and

$$ \hat{y}(4,8)=12-1.5(4)+0.8(8)-0.10(32) =12-6+6.4-3.2 =9.2\text{ errors}. $$

The fitted outcome at \((4,8)\) is \(2.0\) errors higher than at \((4,3)\). Both fitted values are mean predictions, so a fractional value such as 7.2 is not an arithmetic error: a fitted mean need not be a whole-number count. Notice also that the product term is negative in both calculations. Dropping its minus sign would yield a different fitted outcome.

Worked Example: Comparing Combinations That Differ in Both Predictors

Suppose a hypothetical assessment model predicts a score in points from study hours \(x_1\) and a preparation rating \(x_2\), measured in rating points. Its fitted equation is

$$ \hat{y}=25+4x_1+2x_2+0.5x_1x_2. $$

Compare the fitted scores at \((2,2)\) and \((6,5)\). At the first pair, \(x_1x_2=2(2)=4\), giving

$$ \hat{y}(2,2)=25+4(2)+2(2)+0.5(4) =25+8+4+2 =39\text{ points}. $$

At the second pair, \(x_1x_2=6(5)=30\), so

$$ \hat{y}(6,5)=25+4(6)+2(5)+0.5(30) =25+24+10+15 =74\text{ points}. $$

The fitted outcome for \((6,5)\) is \(74-39=35\) points higher than for \((2,2)\). Since both predictor values differ between the pairs, this calculation compares the two combinations as wholes. It does not isolate the contribution of either predictor.

Why the Product Must Be Recalculated

The product term is part of the equation, so it must be evaluated at the same predictor pair as the other terms. For example, in the task-study equation, the pair \((4,3)\) has product \(12\), whereas \((4,8)\) has product \(32\). Using 12 in both predictions would not evaluate the stated equation at \((4,8)\).

A short justification also clarifies what the calculation does and does not deliver. Under the model's conditional-mean assumption, the error contributes zero to the mean outcome at fixed predictor values. Consequently, the model's mean at a pair is its intercept and predictor terms evaluated at that pair. The fitted prediction follows by using estimated rather than unknown coefficients:

$$ E(Y\mid x_1,x_2) =\beta_0+\beta_1x_1+\beta_2x_2+\beta_3x_1x_2 \quad\Longrightarrow\quad \hat{y} =b_0+b_1x_1+b_2x_2+b_3x_1x_2. $$

This is a fitted mean, not an exact prediction of an individual's observed response. In the model, an observed response also contains an error term:

$$ Y_i=\hat{y}_i+\text{prediction error for observation }i $$

The equation above expresses the distinction informally: an observed value can differ from its fitted value. The difference for a particular observation is called its residual, \(e_i=y_i-\hat{y}_i\). Knowing \(\hat{y}\) alone does not determine that residual or the individual outcome.

Units, Range, and Interpretation

The fitted outcome is reported in the units of \(Y\). Predictor values must be entered in the units used to fit the equation: if \(x_1\) was recorded in hours, substitute hours rather than minutes unless the equation has been converted accordingly. The product \(x_1x_2\) has the combined units of the two predictors, and its coefficient makes the product term compatible with the outcome units.

A calculation can be arithmetically correct yet give a prediction that should be treated cautiously. In particular, check whether the requested pair is within the range of predictor combinations represented by the data used to fit the model. A prediction far outside those combinations is an extrapolation: the equation supplies a number, but the data may provide little support for the model's behavior there. Also check that the combination is meaningful in context. For example, a mathematical pair of predictor values may not be possible for the people or objects being studied.

The calculation itself does not establish that the model fits well, that the product-term form is appropriate, or that a difference between fitted outcomes is causal. Those are separate questions about model adequacy and study design. For the task here, report the supplied equation's fitted outcomes accurately and describe comparisons as comparisons between those predictions.

Common Mistakes

  • Leaving out the product term. The wrong reasoning is to use only the intercept and the two separate predictor terms. The correction is to calculate \(x_1x_2\) for every pair and include \(b_3x_1x_2\).
  • Using the wrong product for a pair. A product calculated for one row cannot be reused for another pair unless it happens to have the same value. Recalculate it each time.
  • Losing a negative sign. Keep the coefficient sign attached to its term during substitution; for example, \(-0.10(32)=-3.2\), not \(+3.2\).
  • Calling a fitted mean an individual's certain outcome. A prediction of 7.2 errors is a model-based mean, not a claim that a particular person will make exactly 7.2 errors.
  • Attributing a combined comparison to one predictor. If both coordinates of the compared pairs differ, the difference in fitted outcomes compares both combinations, not the isolated effect of either predictor.
  • Ignoring the observed range. Substitution is possible for any numerical pair, but predictions outside the data's supported range may be unreliable.
Key takeaway: For each requested predictor pair, evaluate the complete fitted equation, including its product term. Report the fitted outcome in context, and interpret a comparison as a difference between the specified model-based predictions.

Check Your Understanding

Use the fitted equation and show the product-term arithmetic in each calculation.

  1. For \(\hat{y}=10+2x_1+3x_2+0.5x_1x_2\), calculate the fitted outcome at \((x_1,x_2)=(2,4)\).
  2. Using the same equation, calculate the fitted outcomes at \((1,3)\) and \((3,3)\). Which is higher, and by how much?
  3. Why can a fitted outcome for a count response be fractional?
  4. What does it mean if a requested predictor pair is outside the range of combinations represented in the fitting data?
  5. Two predictor pairs differ in both coordinates. What can be concluded from subtracting their fitted outcomes, and what cannot be isolated from that subtraction alone?