From a Coefficient Vector to Several Fitted Values
A regression equation can be used to calculate a fitted outcome for one record, but practical output often contains many records at once. The same rule applies to every row: combine that record’s predictor values with the estimated coefficients in the equation. Organizing the calculations in a table makes it easier to check that the predictors are matched to the right coefficients and that the resulting fitted values agree with software output.
This tutorial works with an additive multiple linear regression model. “Additive” means that each predictor contributes a coefficient times its value, and the terms are added together. The goal here is to evaluate the fitted equation for a set of records, not to estimate the coefficients or assess how well the model fits overall.
The corresponding statistical model is \(Y_i=\beta_0+\beta_1x_{i1}+\cdots+\beta_px_{ip}+\varepsilon_i\), where \(Y_i\) is the outcome and \(\varepsilon_i\) is the error for record \(i\). In the usual linear-model interpretation, the errors have conditional mean zero given the predictors; standard assumptions for regression inference also include independent errors and constant error variance. Normal errors are used for some exact small-sample inference procedures, but are not needed for the arithmetic in this tutorial. Once the estimated coefficients and predictor values are given, calculating fitted values is an algebraic operation; the assumptions do not change the multiplication and addition.
Write the Calculation as a Matrix Product
Suppose the coefficient vector is written in the order \((\hat{\beta}_0,\hat{\beta}_1,\ldots,\hat{\beta}_p)\). For \(n\) records, the design matrix has one row per record. Its first column consists of 1s for the intercept, and the remaining columns contain the predictor values in the same order as the coefficients. Multiplying the design matrix by the coefficient vector produces one fitted value per row.
The dimensions help check that the setup is consistent: \(X\) has \(n\) rows and \(p+1\) columns, \(\mathbf{\hat{\beta}}\) has \(p+1\) entries, and \(\mathbf{\hat{y}}\) has \(n\) entries. Each fitted value is the dot product of one row of \(X\) with the coefficient vector. In particular, the first entry of that row, 1, multiplies the intercept.
This row-by-row description follows directly from matrix multiplication. If row \(i\) of \(X\) is \((1,x_{i1},\ldots,x_{ip})\), multiplying it by the coefficient column gives the sum of the products of matching entries:
The matrix notation therefore does not introduce a different prediction rule. It applies the same fitted equation to several records in one organized calculation.
Worked Example: Fitted Quiz Scores for Four Records
Suppose a hypothetical model predicts quiz score, in points, from hours of study and the number of classes missed. The estimated equation is \(\hat{y}=42+3.2(\text{study hours})-1.5(\text{classes missed})\). Calculate fitted scores for the four records below.
| Record | Study hours | Classes missed |
|---|---|---|
| A | 4 | 1 |
| B | 6 | 0 |
| C | 2 | 3 |
| D | 5 | 2 |
Use the coefficient order \((\text{intercept},\text{study hours},\text{classes missed})\). The coefficient vector is \((42,3.2,-1.5)^\mathsf{T}\), and each design-matrix row begins with 1. For record A, the calculation is \(42+3.2(4)-1.5(1)=42+12.8-1.5=53.3\) points.
For record B, \(42+3.2(6)-1.5(0)=42+19.2=61.2\) points. For record C, \(42+3.2(2)-1.5(3)=42+6.4-4.5=43.9\) points. For record D, \(42+3.2(5)-1.5(2)=42+16-3=55.0\) points.
The fitted-value vector, in the same order as the records, is \((53.3,61.2,43.9,55.0)^\mathsf{T}\). These are outcomes calculated from the model, not the records’ observed quiz scores. If observed scores were also available, each residual would be the observed score minus its fitted score.
Keep the Columns and Coefficients Aligned
A calculation can be arithmetically accurate and still be wrong if a predictor is placed in the wrong column. Before multiplying, write down the coefficient order and use that order in every design-matrix row. In a table, make the column labels explicit; do not rely on memory or on the apparent position of a term in software output.
A binary indicator can be included as a predictor just like a numerical predictor. Its recorded value, often 0 or 1, goes in its own column, and its coefficient occupies the corresponding position in the coefficient vector. The fitted-value calculation remains the same: multiply matching entries and add. No separate prediction rule is needed.
Worked Example: Including a Binary Predictor Across Records
A hypothetical model predicts task-completion time in minutes using the number of tasks assigned and a remote-work indicator, where 1 means remote and 0 means on-site. Suppose the estimated equation is \(\hat{y}=18+4.5(\text{tasks})-3(\text{remote indicator})\). Calculate the fitted times for three records.
| Record | Tasks | Remote indicator |
|---|---|---|
| E | 2 | 0 |
| F | 2 | 1 |
| G | 5 | 1 |
The coefficient vector is \((18,4.5,-3)^\mathsf{T}\), in the order intercept, tasks, remote indicator. For E, the design-matrix row is \((1,2,0)\), so \(\hat{y}_E=18+4.5(2)-3(0)=18+9=27\) minutes.
For F, the row is \((1,2,1)\), giving \(\hat{y}_F=18+4.5(2)-3(1)=18+9-3=24\) minutes. For G, the row is \((1,5,1)\), giving \(\hat{y}_G=18+4.5(5)-3(1)=18+22.5-3=37.5\) minutes. Thus the fitted values in record order are 27, 24, and 37.5 minutes.
The only change between E and F is the indicator entry, from 0 to 1, so their calculated fitted times differ by 3 minutes in this model. That observation is a check on the arithmetic: changing that entry changes its product from \(-3(0)=0\) to \(-3(1)=-3\). The fitted values are still model calculations, not claims about what caused any difference in actual completion times.
Checking Hand Calculations Against Software Output
A software package may show the coefficient estimates and fitted values in separate parts of its output. To check that the displayed fitted values follow from the displayed coefficients, confirm that both use the same records, predictor coding, and coefficient precision. Then calculate a few rows directly—or all rows for a small table—and compare the results at the precision shown by the software.
Displayed coefficients are often rounded. If the software used more decimal places internally than it printed, calculations using only the printed coefficients can differ slightly from its fitted values. A small discrepancy consistent with rounding is not automatically evidence of an error. If the difference is larger than rounding can explain, check the column order, the predictor values, the indicator coding, and whether an intercept is present in the equation being evaluated.
Worked Example: Comparing Calculations With Rounded Output
Suppose a hypothetical model predicts a performance score from training hours, workload count, and a remote-work indicator. The coefficient vector, in that order after the intercept, is \((10.25,1.4,-0.75,3.2)^\mathsf{T}\). The software displays the following fitted values to two decimal places.
| Record | Training hours | Workload count | Remote indicator | Software fitted value |
|---|---|---|---|---|
| H | 2 | 4 | 0 | 10.05 |
| I | 5 | 2 | 1 | 18.95 |
| J | 0 | 3 | 1 | 11.20 |
For H, the design-matrix row is \((1,2,4,0)\). Its fitted value is \(10.25+1.4(2)-0.75(4)+3.2(0)=10.25+2.8-3+0=10.05\). This matches the displayed output.
For I, the row is \((1,5,2,1)\). The calculation is \(10.25+1.4(5)-0.75(2)+3.2(1)=10.25+7-1.5+3.2=18.95\), again matching. For J, the row is \((1,0,3,1)\), so \(10.25+1.4(0)-0.75(3)+3.2(1)=10.25+0-2.25+3.2=11.20\). This also matches the software value to two decimal places.
The comparison checks the fitted-value arithmetic for these records. It does not by itself show that the model is appropriate or that its predictions are accurate for other records. It only confirms that the displayed coefficients and predictor values produce the displayed fitted outcomes at the reported precision.
Common Mistakes and a Reliable Check
A frequent error is to treat the coefficient vector as if its entries were fitted outcomes. Coefficients describe the fitted equation; a fitted value is obtained only after the row’s predictor values are supplied and the products are added. Another common error is to leave out the intercept, or to multiply a predictor’s value by the coefficient from the neighboring column. Either mistake can affect every record in a table.
Use a short, repeatable check before trusting a list of fitted values:
List the intercept first, followed by the predictors in the exact order used for the coefficient vector.
Confirm that the row begins with 1 and that each predictor value is under its matching column label.
For each record, show the intercept and every predictor-by-coefficient product before summing.
Match the record order and allow for small differences caused by rounded displayed coefficients.
The most important distinction is between the model’s estimated coefficients and the fitted outcomes computed from them. The matrix product \(X\mathbf{\hat{\beta}}\) keeps that distinction clear: the coefficient vector is shared across records, while each row of \(X\) supplies the predictor values that produce one fitted value.
Check Your Understanding
Use the definitions and row-by-row calculation rule to answer these questions.
- A model has coefficient vector \((8,2,-1)^\mathsf{T}\), ordered as intercept, \(x_1\), and \(x_2\). What is the fitted value for a record with \(x_1=3\) and \(x_2=2\)?
- For a model with an intercept and two predictors, how many entries should each design-matrix row and the coefficient vector contain?
- Why must predictor columns in the design matrix follow the same order as the corresponding coefficients?
- A hand calculation differs slightly from a software fitted value. Name one reason related to how coefficients are displayed and two other setup details to check.
- Explain why a fitted value is not the same quantity as a regression coefficient.