Tutorials › Regression Analysis (Undergraduate) › Calculating Predictions With a Design-Matrix Row

Building and Reading Model Terms · Tutorial 139 of 991

Calculating Predictions With a Design-Matrix Row

Build a design-matrix row from a predictor profile, then use the matching coefficient estimates to calculate and interpret its fitted outcome.

Intermediate 9 min read

What You'll Learn

  • Identify the predictor values and coding needed for a specified profile.
  • Match each row entry to its term in the fitted regression equation.
  • Calculate a fitted outcome using the row and coefficient estimates.
  • Check that the design-matrix row and coefficient vector use the same order.
  • Distinguish a fitted outcome from an observed or future outcome.
  • Recognize common errors involving omitted intercepts and indicator coding.

From a Predictor Profile to a Fitted Outcome

A fitted regression equation can be evaluated by substituting predictor values, as in the earlier material on calculating a fit. The design-matrix row gives the same calculation a compact, organized form: it records the predictor profile in the order used by the model, and the coefficient vector records the matching estimates. Pairing them correctly produces the fitted outcome for that profile.

This is useful when an equation has several terms, especially when some predictors are coded as zero-one indicators. The essential discipline is to preserve the model’s term order and coding. A row that contains the right numbers in the wrong positions describes a different profile and can give a different prediction.

Definition: For an additive regression model with an intercept and \(p\) predictor terms, a design-matrix row for a predictor profile is the row vector containing the intercept entry \(1\), followed by the profile’s values for the \(p\) terms in the model’s specified order. If the coefficient estimates in that same order are collected in the column vector \(\hat{\boldsymbol{\beta}}\), the fitted outcome for the profile is the row’s scalar product with that vector, denoted \(\hat{y}_0\).

For example, if the model has an intercept, \(x_1\), and \(x_2\), then the row for a profile with values \(x_{01}\) and \(x_{02}\) is \([1,x_{01},x_{02}]\). The coefficient vector must list the intercept estimate first, then the estimate for \(x_1\), then the estimate for \(x_2\). The subscript \(0\) here labels the profile being evaluated; it does not mean the predictor values are zero.

Model and Calculation

Suppose the fitted equation is additive, includes an intercept, and has \(p\) predictor terms. The terms may be numeric predictors or indicators whose coding has been specified. For a particular profile, let \(x_{0j}\) be its value for term \(j\), and let \(\hat{\beta}_j\) be the estimate of the coefficient for that term. The intercept estimate is \(\hat{\beta}_0\).

$$ \hat{y}_0 = \begin{bmatrix} 1 & x_{01} & x_{02} & \cdots & x_{0p} \end{bmatrix} \begin{bmatrix} \hat{\beta}_0\\ \hat{\beta}_1\\ \hat{\beta}_2\\ \vdots\\ \hat{\beta}_p \end{bmatrix} = \hat{\beta}_0+\sum_{j=1}^{p}x_{0j}\hat{\beta}_j $$

This formula is an arithmetic rule for the fitted model, not a way to estimate new coefficients. It requires the fitted equation and its coefficient estimates to be available. It also requires that the profile values use the same units and indicator definitions as the model terms, and that the row and coefficient vector list those terms in matching order. Under those conditions, multiply each row entry by the coefficient estimate in the corresponding position and add the products. The initial row entry \(1\) contributes the intercept estimate.

The resulting \(\hat{y}_0\) is the fitted outcome on the response scale. It is not the observed outcome for a particular person or item, nor does the calculation alone tell us the outcome that a future individual will have. The arithmetic evaluates the fitted equation at the stated profile; it does not establish whether the model is suitable for a particular use.

1
Write the model’s terms in order.
Include the intercept, then list every predictor term exactly as it appears in the fitted equation.
2
Record the profile in that order.
Put \(1\) in the intercept position. For each remaining position, use the profile’s value for the corresponding term, applying its stated indicator coding.
3
Pair entries with estimates.
Check that each row entry and coefficient estimate refer to the same term.
4
Multiply and add.
Calculate the products entry by entry, sum them, and report the fitted outcome with its context and units.

Worked Calculations

Worked Example: Two Numeric Predictors

Suppose a hypothetical fitted model predicts a study group’s mean quiz score, in points, from weekly study hours and commute time in minutes:

$$ \widehat{\text{score}} = 12.4+1.8(\text{study hours})-0.35(\text{commute minutes}) $$

Calculate the fitted score for a hypothetical profile with 6 study hours per week and a 20-minute commute. First, keep the term order from the equation: intercept, study hours, commute minutes. The design-matrix row is therefore \([1,6,20]\), and the matching coefficient vector is \([12.4,1.8,-0.35]^T\).

$$ \hat{y}_0 = [1,6,20] \begin{bmatrix} 12.4\\ 1.8\\ -0.35 \end{bmatrix} = (1)(12.4)+(6)(1.8)+(20)(-0.35) $$

The products are \(12.4\), \(10.8\), and \(-7.0\), respectively. Thus,

$$ \hat{y}_0=12.4+10.8-7.0=16.2 $$

The model’s fitted score for this profile is 16.2 points. This is the fitted value from the stated equation, not a guarantee that a particular student with this profile will score exactly 16.2 points.

Worked Example: Including a Zero-One Indicator

Suppose a hypothetical fitted model predicts a symptom score from weekly exercise hours and a binary group indicator. The indicator is \(1\) for the group receiving a specified program and \(0\) for the comparison group:

$$ \widehat{\text{score}} = 72-2.5(\text{exercise hours})+6(\text{program indicator}) $$

For a hypothetical profile with 4 exercise hours per week in the program group, the numeric value is 4 and the indicator value is 1. In equation order, the row is \([1,4,1]\), while the coefficient vector is \([72,-2.5,6]^T\).

$$ \hat{y}_0 = [1,4,1] \begin{bmatrix} 72\\ -2.5\\ 6 \end{bmatrix} = (1)(72)+(4)(-2.5)+(1)(6) $$

The arithmetic gives \(72-10+6=68\). The fitted symptom score for this profile is 68 points. The indicator contributes its coefficient because the profile has indicator value 1; a profile in the comparison group would have 0 in that position, so the corresponding product would be zero.

The indicator value is determined by the model’s coding, not by a guess about what seems like the “main” group. If the coding were reversed, the profile’s row entry would have to follow the reversed definition, and the coefficient estimates would need to come from that fitted model.

Worked Example: Keeping Several Terms in Their Positions

Consider a hypothetical model for predicted service waiting time, in minutes:

$$ \widehat{\text{waiting time}} = 8+0.6(\text{workload})+4(\text{weekend indicator})+2(\text{urgent indicator}) $$

The weekend indicator is 1 for a weekend and 0 otherwise. The urgent indicator is 1 for an urgent case and 0 otherwise. Calculate the fitted waiting time for a hypothetical weekend case that is not urgent and has workload 15. In equation order, the profile values are workload \(15\), weekend indicator \(1\), and urgent indicator \(0\), so the row is \([1,15,1,0]\). The matching coefficient vector is \([8,0.6,4,2]^T\).

$$ \hat{y}_0 = [1,15,1,0] \begin{bmatrix} 8\\ 0.6\\ 4\\ 2 \end{bmatrix} = (1)(8)+(15)(0.6)+(1)(4)+(0)(2) $$

The four contributions are \(8\), \(9\), \(4\), and \(0\). Their sum is \(21\), so the fitted waiting time for this profile is 21 minutes. The zero in the urgent-indicator position is essential: it records that this profile is not urgent. It does not remove the urgent term from the model or shift the other entries.

Why Order and Coding Matter

A design-matrix row is meaningful only in relation to the model’s specified term order. If the coefficient vector lists workload before weekend status, then the row must put workload before the weekend indicator. Multiplication is position-based: each entry is paired with the estimate in the same position. Reordering only the row, or only the coefficients, changes those pairings and generally changes the result.

Likewise, an indicator entry must describe the profile using the indicator’s definition. For a zero-one indicator, a value of 1 means the category named by that indicator is present, and 0 means it is absent. A row entry of 2 is not an alternative way to say “present” under this coding. Before calculating, check both what each column represents and how it is coded.

A useful check is to expand the row calculation back into the fitted equation. For the waiting-time example, the row calculation corresponds to \(8+0.6(15)+4(1)+2(0)\). If this substitution does not match the stated predictor profile, the row has been assembled incorrectly.

Key takeaway: The design-matrix row contains the predictor values for one profile, in the model’s term order, with \(1\) in the intercept position. Pairing that row with the coefficient estimates in the same order gives the profile’s fitted outcome by multiplying corresponding entries and adding the products.

Common Mistakes

  • Leaving out the intercept entry. A student writes \([6,20]\) for a model with an intercept, study hours, and commute time. The correction is to include the intercept column’s \(1\): the row is \([1,6,20]\).
  • Putting a coefficient estimate in the row. A row describes the predictor profile; it does not contain the fitted coefficients. Keep profile values in the row and coefficient estimates in the matching vector.
  • Using the wrong term order. If the model order is intercept, workload, weekend indicator, urgent indicator, the row must follow that same order. The correction is to label the terms before filling in the entries.
  • Using an indicator value that contradicts its definition. If \(1\) means “weekend,” a weekday profile gets 0, not 1. State the indicator’s coding before forming the row.
  • Calling the fitted value an observed outcome. The row calculation evaluates the fitted equation. It does not report an actual measurement or promise an individual’s future result.

Check Your Understanding

For each question, pay attention to the model’s term order and the meaning of the profile values.

  1. A fitted equation has terms in the order intercept, distance, and group indicator. The profile has distance 12 and indicator value 0. What is its design-matrix row?
  2. A fitted model is \(\hat{y}=5+3x-2z\). For \(x=4\) and \(z=1\), write the row and coefficient vector, then calculate the fitted outcome.
  3. In a model, a zero-one indicator is defined as 1 for weekend and 0 for weekday. What entry belongs in the row for a weekday profile, and what does the corresponding product contribute?
  4. Why is \([1,4,1]\) not interchangeable with \([1,1,4]\) when the coefficient vector remains unchanged?
  5. True or false: a fitted outcome calculated from a design-matrix row must equal the observed outcome for a person with that predictor profile. Explain briefly.