From a New Case to a Design Row
A fitted generalized linear model can be used to calculate a linear predictor for a case that was not in the data used to fit it. The arithmetic is simple once the case has been represented correctly. The main task is to translate its recorded predictor values into the exact features used by the model, in the model’s established column order.
A case’s raw information is not necessarily the row of the design matrix. A model might use an intercept and two numerical predictors; it might instead use indicator variables for a categorical predictor, a centered and rescaled covariate, or a transformed covariate. For a new case, the design row must be built by applying those same definitions. The response value is not part of that row.
Here \(v\) denotes the new case’s predictor information, while \(z_j(v)\) denotes the value of the \(j\)th model feature after its definition has been applied. Thus, when a column represents a transformed variable, the entry in that column is the transformed value, not necessarily the raw value. When a column represents an intercept or an indicator, its entry follows that column’s definition.
The row is a row vector and the coefficient vector is a column vector, so their product is a scalar. This is the same matrix multiplication used for an observed case: the difference is that the row is constructed from a new predictor profile. The model’s coefficients and feature definitions stay fixed.
A Reliable Construction Procedure
Start with the original model specification or design-matrix definition, not with a guess about what the row “should look like.” Record the columns in their established order. Then evaluate every column’s feature definition for the new case, including the intercept, indicators, transformations, and any centering or scaling constants. Finally, multiply the completed row by the coefficient vector in the matching order.
List every feature in the exact order used by \(X\), and write its definition. For example, distinguish a raw covariate \(x\) from a column defined as \((x-c)/s\).
Identify the values needed to evaluate each feature. Do not insert a response value into the design row.
Apply each original definition, including the prescribed coding of categories and any fixed transformation constants.
Write the evaluated features in the schema’s order, verify that the row has \(p\) entries, and take its product with the \(p\)-entry coefficient vector.
This procedure is deliberately literal. It prevents a frequent source of incorrect calculations: substituting a new, convenient representation of the predictors even though the fitted coefficients correspond to the original representation.
Worked Example: Two Numerical Predictors and an Intercept
Suppose the model’s design columns, in order, are the intercept, age in years, and years of prior experience. Its coefficient vector in that order is \(\boldsymbol{\beta} = (-1.2, 0.08, 0.5)^\mathsf{T}\). Construct the design row and calculate the linear predictor for a new case aged 50 with 3 years of experience.
The first column is the intercept, so its value is 1. The age column is the case’s age, 50, and the experience column is the case’s experience, 3. In the specified order, \(\mathbf{x}_{\mathrm{new}} = (1,50,3)\).
The row has three entries, matching the three coefficients. The linear predictor is \(\eta_{\mathrm{new}} = (1,50,3)(-1.2,0.08,0.5)^\mathsf{T}\). Evaluating the product gives \(\eta_{\mathrm{new}} = 1(-1.2) + 50(0.08) + 3(0.5) = -1.2 + 4 + 1.5 = 4.3\).
The calculation uses the age and experience values as defined by the model’s columns. It does not add a column for the response, which is not needed to construct this linear predictor.
Features Defined by Indicators or Transformations
Not every design column is a raw numerical measurement. For a categorical predictor represented with indicator columns, first use the model’s stated category coding. For a transformed predictor, evaluate the stated transformation. The resulting entries still occupy ordinary positions in the design row, and the linear predictor is still the corresponding sum of feature values multiplied by coefficients.
For instance, if a categorical predictor has a reference category and a column \(I(B)\), that feature is 1 for category B and 0 otherwise. A case in the reference category receives 0 in that column. If there are multiple indicator columns, evaluate each separately according to its definition. The names or values of the categories alone do not determine the row without knowing the model’s coding.
Worked Example: A Categorical Predictor With a Reference Category
Suppose the column order is intercept, indicator for treatment B, indicator for treatment C, and dose. Treatment A is the reference category. The features are \(1\), \(I(B)\), \(I(C)\), and dose, where each indicator equals 1 for its named treatment and 0 otherwise. The coefficient vector is \(\boldsymbol{\beta} = (-2, 0.7, 1.1, 0.25)^\mathsf{T}\). Find the row and linear predictor for a case receiving treatment C at dose 4.
The intercept entry is 1. Since the case receives C rather than B, \(I(B)=0\) and \(I(C)=1\). The dose entry is 4. Respecting the listed order gives \(\mathbf{x}_{\mathrm{new}} = (1,0,1,4)\).
The product with the coefficient vector is \(\eta_{\mathrm{new}} = 1(-2) + 0(0.7) + 1(1.1) + 4(0.25)\). The contributions are \(-2\), \(0\), \(1.1\), and \(1\), so \(\eta_{\mathrm{new}} = -2 + 0 + 1.1 + 1 = 0.1\).
The zero in the B column does not mean that the case’s treatment information is missing; it records that the B indicator is false. The C indicator records the case’s category under this model’s stated coding.
Worked Example: A Centered and Rescaled Predictor
Suppose the design columns are the intercept, \(z_2(x)=(x-50)/10\), and \(z_3(w)=w^2\), in that order. The values 50 and 10 are the constants specified for this model. Let \(\boldsymbol{\beta}=(0.2,-0.6,0.15)^\mathsf{T}\). Construct the row and linear predictor for a case with \(x=65\) and \(w=2\).
The intercept entry is 1. The second feature is evaluated using its defined centering and scaling: \(z_2(65)=(65-50)/10=15/10=1.5\). The third feature is the square of \(w\), so \(z_3(2)=2^2=4\). Therefore, in the original column order, \(\mathbf{x}_{\mathrm{new}}=(1,1.5,4)\).
The linear predictor is \(\eta_{\mathrm{new}}=1(0.2)+1.5(-0.6)+4(0.15)\). The three contributions are \(0.2\), \(-0.9\), and \(0.6\), which sum to \(\eta_{\mathrm{new}}=0.2-0.9+0.6=-0.1\).
The row contains 1.5 in the second column, not 65: that column is defined using the centered and rescaled feature. It contains 4 in the third column, not 2: that column is defined using the square. The model’s stated constants and transformations determine both entries.
Why the Feature Definitions and Order Must Match
The following basic result makes explicit why the construction procedure gives the model’s linear predictor. It also clarifies that the row’s entries are not chosen independently of the coefficient definitions: each entry must correspond to its matching coefficient.
Proof. By the definition of matrix multiplication for a row vector and a column vector of length \(p\), \(\mathbf{x}_{\mathrm{new}}\boldsymbol{\beta}=\sum_{j=1}^{p}(\mathbf{x}_{\mathrm{new}})_j\beta_j\). The \(j\)th entry of the constructed row is \(z_j(v)\), so this equals \(\sum_{j=1}^{p}z_j(v)\beta_j\), which is the stated definition of \(\eta(v)\). Therefore the constructed row product is the linear predictor. \(\square\)
A consistently reordered schema also gives the same predictor, but only when the coefficient vector is reordered with it. This is useful when software or a written calculation displays the columns in a different order. Reordering a row while leaving the coefficients fixed is not such a consistent change.
Proof. Write the original product as \(\sum_{j=1}^{p}x_j\beta_j\). Under a common permutation, the reordered entries are \(x_{\pi(1)},\ldots,x_{\pi(p)}\), paired with \(\beta_{\pi(1)},\ldots,\beta_{\pi(p)}\). Their product is \(\sum_{k=1}^{p}x_{\pi(k)}\beta_{\pi(k)}\). Because \(\pi\) visits every index \(1,\ldots,p\) exactly once, this sum contains exactly the same terms as \(\sum_{j=1}^{p}x_j\beta_j\), only in a different order. The value is unchanged. \(\square\)
For several new cases, apply the same construction separately to each case and stack the resulting rows in the desired case order. If there are \(m\) new cases and \(p\) design columns, the resulting matrix \(X_{\mathrm{new}}\) has \(m\) rows and \(p\) columns. Its product with the coefficient vector has \(m\) entries, one linear predictor per case: \(X_{\mathrm{new}}\boldsymbol{\beta}\). This dimension check is a quick way to detect an incomplete row or an incompatible coefficient vector.
Common Mistake: Changing the Row but Not the Model
A common mistake is to replace a model feature with a raw value or a newly computed value because it seems more natural for the new case. For example, if a fitted column is \((x-50)/10\), inserting \(x\) directly into that position does not merely express the same feature differently. It changes the value multiplied by the coefficient. Likewise, putting the same entries in a different order without reordering the coefficients pairs features with the wrong coefficients.
The correction is to treat the design specification as fixed: use the same feature definitions and constants used for the fitted model, then use the matching coefficient order. If a different feature definition or column order is intentionally adopted, the coefficients must be represented in the corresponding way as well; it is not valid to change one side of the product alone.
Check Your Understanding
For each question, use the model’s stated feature definitions rather than substituting a different representation.
- A model has columns ordered as intercept, \(x\), and \(z\), with coefficients \((2,-0.5,3)^\mathsf{T}\). What design row and linear predictor correspond to \(x=4\) and \(z=1\)?
- A model uses the features \(1\), \(I(B)\), and \(I(C)\), with A as the reference category. What are the three entries for a case in category A?
- A design column is defined as \((x-20)/5\). What value belongs in that column for a case with \(x=35\), using the stated definition?
- Explain why reordering a design row but not its coefficient vector can change the linear predictor.
- If there are \(m\) new cases and \(p\) model columns, what are the dimensions of \(X_{\mathrm{new}}\) and \(X_{\mathrm{new}}\boldsymbol{\beta}\)?