From a Design Matrix to Linear-Predictor Values
Once a model’s design matrix and coefficient vector have been specified, calculating its linear predictor is a concrete matrix multiplication. The main tasks are to check that the dimensions agree, multiply each observation’s row by the coefficient vector, and keep the resulting values in the same order as the observations.
Let \(n\) be the number of observations and \(p\) the number of coefficients. Write the design matrix as \(X\), with \(n\) rows and \(p\) columns, and the coefficient vector as \(\beta\), with \(p\) entries. The linear-predictor vector is \(\eta=X\beta\). For this calculation, each row of \(X\) supplies the \(p\) values to multiply by the corresponding \(p\) coefficients.
The matching dimension \(p\) is essential: the number of entries in each design row must equal the number of entries in \(\beta\). The output has one entry per row of \(X\), so it has one linear-predictor value per observation. This tells us the dimensions before doing any arithmetic: \((n\times p)(p\times 1)=n\times 1\).
Worked Matrix Multiplication
Worked Example: Three Observations and One Numerical Predictor
Suppose the design matrix and coefficient vector are $$ X= \begin{pmatrix} 1&0\\ 1&2\\ 1&4 \end{pmatrix}, \qquad \beta= \begin{pmatrix} 1.2\\ 0.5 \end{pmatrix}. $$ The matrix has 3 rows and 2 columns, while \(\beta\) has 2 rows and 1 column. Therefore, the product is defined and \(\eta\) must have dimensions \(3\times1\).
Compute a dot product for each row: $$ \begin{aligned} \eta_1&=(1)(1.2)+(0)(0.5)=1.2,\\ \eta_2&=(1)(1.2)+(2)(0.5)=1.2+1.0=2.2,\\ \eta_3&=(1)(1.2)+(4)(0.5)=1.2+2.0=3.2. \end{aligned} $$ Thus, $$ \eta=X\beta= \begin{pmatrix} 1.2\\ 2.2\\ 3.2 \end{pmatrix}. $$
There are three calculated values because \(X\) has three rows. The first value uses only the first row, the second uses only the second row, and the third uses only the third row. The result is a column vector, matching the specified orientation of \(\beta\).
A reliable hand calculation labels the row being used before combining entries. This makes it easier to catch a misplaced value, especially when there are several predictors. It also distinguishes the observation index \(i\), which identifies a row and an output value, from the coefficient index \(j\), which identifies a position within that row and within \(\beta\).
Complete Calculation With Several Predictors
Worked Example: Four Rows and Three Coefficients
Consider a design matrix with a first column of ones, a second column containing 0 or 1, and a third column with numerical values: $$ X= \begin{pmatrix} 1&0&20\\ 1&1&30\\ 1&0&40\\ 1&1&50 \end{pmatrix}, \qquad \beta= \begin{pmatrix} -2\\ 1.5\\ 0.04 \end{pmatrix}. $$ The dimensions are \(4\times3\) and \(3\times1\), so multiplication is valid and produces a \(4\times1\) vector. Calculate each entry using all three corresponding coefficient positions.
For row 1, the products are \((1)(-2)\), \((0)(1.5)\), and \((20)(0.04)\): $$ \eta_1=-2+0+0.8=-1.2. $$ For row 2: $$ \eta_2=(1)(-2)+(1)(1.5)+(30)(0.04) =-2+1.5+1.2=0.7. $$ For row 3: $$ \eta_3=(1)(-2)+(0)(1.5)+(40)(0.04) =-2+0+1.6=-0.4. $$ For row 4: $$ \eta_4=(1)(-2)+(1)(1.5)+(50)(0.04) =-2+1.5+2.0=1.5. $$ Therefore, $$ \eta= \begin{pmatrix} -1.2\\ 0.7\\ -0.4\\ 1.5 \end{pmatrix}. $$
As a check, each calculation has three multiplication terms because each row has three entries, and the final vector has four entries because there are four rows. The values are listed in the same sequence as the rows of \(X\).
These dimension checks do not verify every arithmetic operation, but they can rule out structural errors before or after calculation. If the number of entries in a row does not match the number of coefficients, the stated product cannot be performed. If the product is defined but the result is recorded with the wrong number of entries, at least one row has been skipped, duplicated, or misread.
Two Checks on the Calculation
The component formula gives a direct way to verify what matrix multiplication means in this setting. It also makes the effect of changing the order of rows precise. Both facts are useful when checking a hand calculation or comparing results displayed in different row orders.
Proof. By the definition of matrix multiplication, the entry in row \(i\) and column \(k\) of a product is the sum of the entries in row \(i\) of the first matrix multiplied by the corresponding entries in column \(k\) of the second matrix. Here \(\beta\) has one column, so \(k=1\) is the only output-column index. Hence the entry in row \(i\) of \(X\beta\) is \(\sum_{j=1}^{p}x_{ij}\beta_j\). Since \(i\) ranges from 1 to \(n\), there are exactly \(n\) such entries. The product has one column because \(\beta\) has one column, so its dimensions are \(n\times1\). \(\square\)
Proof. By the definition of \(X^\ast\), its entry in row \(i\), column \(j\) is \(x_{\pi(i),j}\). Applying the row-by-row formula, $$ (X^\ast\beta)_i =\sum_{j=1}^{p}x_{\pi(i),j}\beta_j =(X\beta)_{\pi(i)}. $$ The equality holds for each \(i=1,\ldots,n\), so the output values appear in the same reordered sequence as the rows. No value is recalculated from a different row; only its position in the vector changes. \(\square\)
Worked Example: Checking a Row-Order Change
Use the matrix and coefficient vector from the first worked example. Their result was \(\eta=(1.2,2.2,3.2)^\mathsf{T}\). Now place the original third row first, the first row second, and the second row third: $$ X^\ast= \begin{pmatrix} 1&4\\ 1&0\\ 1&2 \end{pmatrix}. $$ The dimensions remain \(3\times2\) for \(X^\ast\) and \(2\times1\) for \(\beta\), so the product is still \(3\times1\). Calculating directly gives $$ \begin{aligned} (X^\ast\beta)_1&=(1)(1.2)+(4)(0.5)=3.2,\\ (X^\ast\beta)_2&=(1)(1.2)+(0)(0.5)=1.2,\\ (X^\ast\beta)_3&=(1)(1.2)+(2)(0.5)=2.2. \end{aligned} $$ Thus \(X^\ast\beta=(3.2,1.2,2.2)^\mathsf{T}\), which reorders the original entries in exactly the same way as the rows. This comparison checks both the arithmetic and the observation order.
Common Mistakes and a Practical Audit
A common mistake is to multiply corresponding entries without respecting the row and column layout. For example, seeing four entries in a row and four coefficients does not justify adding the entries directly to the coefficients. Each pair must first be multiplied, and those products must then be summed to obtain that row’s one output value.
A second mistake is to give \(\beta\) as a row vector and proceed as if it were a column vector. In the four-row example, \(X\) has dimensions \(4\times3\). If the three coefficients are incorrectly written as a \(1\times3\) row vector, the proposed product has dimensions \((4\times3)(1\times3)\). The inner dimensions, 3 and 1, do not match, so that product is not defined. Writing the coefficients as a \(3\times1\) column vector gives \((4\times3)(3\times1)\), as required.
A useful audit is to state the dimensions first, then calculate one row at a time, and finally check the output length and order. Keep the coefficient positions fixed throughout: the first entry of every row is multiplied by the first coefficient, the second by the second, and so on. This procedure catches many errors without requiring any additional model assumptions.
- Wrong: “There are four observations, so the answer has four columns.” Correction: The number of rows in \(X\) determines the number of output entries. A single coefficient vector gives one output column.
- Wrong: “The row has three values, so I should add those values to get \(\eta_i\).” Correction: Multiply each row entry by its matching coefficient, then sum the products.
- Wrong: “The values are right, so their order does not matter.” Correction: Entry \(i\) belongs to row \(i\). A reordering of rows must be reflected in the order of the output entries.
Check Your Understanding
For each question, keep the matrix dimensions and row order explicit.
- If \(X\) has dimensions \(5\times3\) and \(\beta\) has dimensions \(3\times1\), what are the dimensions of \(X\beta\)?
- For \(X=\begin{pmatrix}1&2\\1&5\end{pmatrix}\) and \(\beta=\begin{pmatrix}0.4\\0.2\end{pmatrix}\), calculate both entries of \(\eta\).
- Why is a \(1\times3\) coefficient row vector not the stated column-vector form for multiplication by a \(4\times3\) design matrix?
- If the rows of a design matrix are reordered, what happens to the corresponding entries of the linear-predictor vector?
- A matrix has six rows and produces a vector with five entries. What should you check in the calculation?