From observation-level equations to one matrix equation
A generalized linear model assigns a linear predictor to each observation. With several observations, it is useful to collect these separate equations into one expression. The matrix equation \(\eta=X\beta\) does exactly that: each row of \(X\) contains the covariate values for one observation, and multiplying by the coefficient vector gives that observation’s predictor.
The goal here is to derive this equation carefully, including the dimensions that make the multiplication valid. The result is a compact way to write the same observation-by-observation model, not a different model. No assumption about the rank of \(X\) is needed for this derivation.
Dimensions and the row convention
The transpose in \(x_i^T\beta\) is essential. The covariate vector \(x_i\) is a column with \(p\) entries, so \(x_i^T\) is a row with \(p\) entries. Its product with the \(p\)-by-1 column \(\beta\) is a \(1\)-by-1 scalar, which is \(\eta_i\).
Stack the \(n\) row vectors \(x_i^T\), in the same order as the observations, to form \(X\). Stack the corresponding scalar predictors in that order to form \(\eta\). The dimensions then give
The observation index labels rows; the coefficient or predictor index labels columns. In particular, \(X_{ij}=x_{ij}\), so the entry in row \(i\), column \(j\) is the value of the \(j\)th design variable for observation \(i\). The order of rows in \(X\) must match the order of entries in \(\eta\).
Worked Example: Three Poisson Predictors with One Covariate
Suppose \(Y_i\) are independent Poisson responses with means \(\mu_i\), and use the log-link model \(\log(\mu_i)=\eta_i\). For three observations, suppose the model has an intercept and one numerical covariate \(z\):
There are \(n=3\) rows and \(p=2\) coefficients. Include the intercept by giving its design column the value 1 for each observation. Thus
Transposing each \(x_i\) makes it a row, and stacking those rows gives a \(3\)-by-\(2\) matrix. Stacking the three predictors gives a \(3\)-by-\(1\) vector:
The first row of the product represents \(1\beta_0+0\beta_1=\eta_1\); the second represents \(1\beta_0+2\beta_1=\eta_2\); and the third represents \(1\beta_0-1\beta_1=\eta_3\). These are exactly the three observation-level equations. The dimensions check as \((3\times2)(2\times1)=3\times1\). The response distribution and link specify the GLM context; the matrix equation stacks its linear predictors.
The stacking result
Proof. By the definition of matrix multiplication, the \(i\)th entry of \(X\beta\) is the dot product of row \(i\) of \(X\) and \(\beta\):
This equality holds for every \(i=1,\ldots,n\). Therefore \(X\beta\) and \(\eta\) have the same entries in the same order, so they are equal as vectors. The dimensions are valid because \(X\) is \(n\)-by-\(p\) and \(\beta\) is \(p\)-by-1. \(\square\)
The theorem shows why the matrix equation is equivalent to the observation-level equations: its \(i\)th component is precisely the equation for observation \(i\). It does not say that the coefficients can necessarily be recovered uniquely from \(X\); that is a separate question. Here, \(X\beta\) is well-defined for every \(n\)-by-\(p\) matrix \(X\) and \(p\)-by-1 vector \(\beta\).
Worked Example: Bernoulli Model with Two Numerical Predictors
Suppose \(Y_i\) are independent Bernoulli responses with success probabilities \(\pi_i\), and the logit model has an intercept and two numerical predictors:
For two observations, let \((a_1,b_1)=(4,1)\) and \((a_2,b_2)=(3,5)\). The coefficient vector has three entries, so \(p=3\). The design vectors, written as columns, are
The intercept is the first component of both design vectors. Transposing the vectors and stacking them in observation order yields
The row-by-row expansion confirms the correspondence:
The matrix is \(2\)-by-\(3\), the coefficient vector is \(3\)-by-\(1\), and the result is \(2\)-by-\(1\), as required. This construction organizes the linear predictors; it does not require evaluating the predictors at particular coefficient values.
How additive terms appear in matrix form
An observation-level equation may be written as a sum of contributions, with each contribution involving one or more coefficients. In matrix form, those contributions occupy corresponding blocks of columns in \(X\), while the matching coefficients occupy blocks of \(\beta\). The full product adds the blockwise contributions for each observation.
Proof. Write the horizontal block partition as \(X=[X_1\ \cdots\ X_K]\) and the corresponding vertical partition as \(\beta=(\beta_1^T,\ldots,\beta_K^T)^T\). By the definition of block matrix multiplication, the product is the sum of the products of matching blocks:
Each \(X_k\beta_k\) has \(n\) entries, so the sum is an \(n\)-by-\(1\) vector. Its \(i\)th entry is the sum of the \(K\) contributions for observation \(i\). This is the matrix version of adding the corresponding observation-level terms. \(\square\)
Worked Example: Intercept-Only Normal Model
Suppose \(Y_i\) are independent with \(Y_i\sim N(\eta_i,\sigma^2)\), where \(\sigma^2\) is a common variance, and the model has an intercept only: \(\eta_i=\beta_0\) for \(i=1,\ldots,4\). There is one coefficient, so \(p=1\), and each observation has the same one-entry design vector \(x_i=(1)\). Stacking the four rows gives
The dimensions are \((4\times1)(1\times1)=4\times1\). The \(i\)th row gives \((X\beta)_i=1\beta_0=\eta_i\), for each of the four observations. Thus one coefficient contributes the same constant predictor to every row, and the matrix equation records all four equations at once.
Common mistakes and why the notation matters
- Putting design vectors in columns instead of rows. With the convention here, \(x_i\) is a column vector but \(x_i^T\) is the \(i\)th row of \(X\). Stacking the untransposed \(x_i\) as rows would not follow this definition and can change the intended product.
- Multiplying in the wrong order. \(X\beta\) is \(n\)-by-\(1\). The product \(\beta X\) is generally not defined, and \(\beta X^T\) is not the stated representation of the stacked predictors.
- Forgetting the intercept column. If the observation-level equation includes \(\beta_0\), the matrix representation needs a corresponding coefficient and design value for each observation, conventionally a column of ones.
- Mixing row order. If rows of \(X\) are rearranged, entries of \(\eta\) must be rearranged in the same way. Otherwise the \(i\)th matrix-product entry no longer corresponds to the intended observation.
The dimension check is a quick safeguard: an \(n\)-entry predictor vector requires \(n\) rows in \(X\), and the number of columns in \(X\) must equal the number of entries in \(\beta\). But dimensions alone do not catch every mistake; the \(i\)th row must also contain the design values for observation \(i\), in the same coefficient order used in \(\beta\).
Check Your Understanding
Use the observation-level equations and dimensions to answer these questions.
- If there are \(n=12\) observations and \(p=4\) coefficients, what are the dimensions of \(X\), \(\beta\), and \(\eta\)?
- For a model \(\eta_i=\beta_0+\beta_1u_i+\beta_2v_i\), how many columns does \(X\) have, and what are the three entries in its \(i\)th row?
- Explain why the \(i\)th entry of \(X\beta\) equals the observation-level predictor \(\eta_i\).
- If two predictor terms are stored in separate blocks \(X_1\) and \(X_2\), how does their combined matrix product relate to \(X_1\beta_1\) and \(X_2\beta_2\)?
- What must be changed in the predictor vector if the rows of \(X\) are reordered?