Tutorials › Multivariate Statistics (Graduate) › Common Errors in Matrix-Valued Regression

Multivariate Regression Models · Tutorial 310 of 975

Common Errors in Matrix-Valued Regression

Check the dimensions and interpretation of every matrix in a multivariate regression, and avoid common errors in residual covariance and response-correlation calculations.

Intermediate 11 min read

What You'll Learn

  • Check compatible dimensions in the multivariate regression model and its fitted values.
  • Distinguish the residual SSCP matrix from an estimated error covariance matrix.
  • Use residual degrees of freedom based on the rank of the design matrix.
  • Interpret off-diagonal residual cross-products and estimated response correlation.
  • State when a Gaussian covariance maximum-likelihood estimate exists.

Why Matrix Bookkeeping Matters

In multivariate regression, a transpose or a divisor that looks harmless can change the meaning of a calculation. A matrix may contain sums of cross-products, estimated covariances, or fitted responses; these objects can have the same dimensions while answering different questions. Careful bookkeeping makes those distinctions explicit.

Use \(n\) for the number of cases, \(p\) for the number of columns in the design matrix, and \(q\) for the number of responses. Write the model as \(Y=XB+U\), where \(Y\) is \(n\times q\), \(X\) is \(n\times p\), \(B\) is \(p\times q\), and \(U\) is \(n\times q\). The rows of \(Y\) and \(U\) correspond to cases; their columns correspond to responses.

Definition: In the multivariate linear model \(Y=XB+U\), the fitted response matrix is \(\hat{Y}=X\hat{B}\), and the residual matrix is \(R=Y-\hat{Y}\). The residual sum-of-squares-and-cross-products matrix, or residual SSCP matrix, is \(E=R'R\), a \(q\times q\) matrix. Its entry \(E_{ab}\) is the sum of the products of the residuals for responses \(a\) and \(b\) across all cases.

The distinction between a data matrix and a coefficient matrix is essential: \(Y\) has one row per case, whereas \(B\) has one row per design column. In particular, the residual SSCP is formed by transposing the residual matrix, not by multiplying it by its transpose in the opposite order. The product \(R'R\) is \(q\times q\); \(RR'\) is \(n\times n\) and summarizes a different set of quantities.

Worked Examples: Dimensions, SSCP, and Covariance

Worked Example: Checking Dimensions Before Multiplication

Suppose \(n=5\), \(p=2\), and \(q=3\). Then \(X\) is \(5\times2\), \(B\) is \(2\times3\), and \(Y\) and \(U\) are each \(5\times3\). The fitted matrix is well-defined because the inner dimensions match:

$$ (5\times2)(2\times3)=5\times3. $$

For a numerical check, take one design row \(x_i'=(1,2)\) and the coefficient matrix

$$ B= \begin{pmatrix} 1&0&-1\\ 2&1&3 \end{pmatrix}. $$

The fitted response row for that case is \(x_i'B=(1,2)B=(5,2,5)\): the first entry is \(1+2(2)=5\), the second is \(0+2(1)=2\), and the third is \(-1+2(3)=5\). It has three entries, one for each response. By contrast, \(BX\) is not a valid multiplication here: \(B\) is \(2\times3\) and \(X\) is \(5\times2\), so the inner dimensions 3 and 5 do not match. Reversing the order is not a harmless alternative formula.

Worked Example: An SSCP Is Not Yet a Covariance Estimate

Consider three cases in an intercept-only model with two responses. The design has rank \(r=1\), so the residual degrees of freedom are \(\nu=n-r=2\). Suppose the fitted residual matrix is

$$ R= \begin{pmatrix} 1&0\\ 0&1\\ -1&-1 \end{pmatrix}. $$

Its columns sum to zero, as required for residuals from an intercept-only fit. Multiplying gives

$$ E=R'R= \begin{pmatrix} 1&0&-1\\ 0&1&-1 \end{pmatrix} \begin{pmatrix} 1&0\\ 0&1\\ -1&-1 \end{pmatrix} = \begin{pmatrix} 2&1\\ 1&2 \end{pmatrix}. $$

The diagonal entries are sums of squared residuals, and the off-diagonal entry is the sum of the paired residual products. Thus \(E\) is an SSCP matrix, not a covariance matrix. Under independent, mean-zero case errors with common covariance matrix \(\Sigma\), the unbiased residual covariance estimate is \(E/\nu\), giving

$$ \hat{\Sigma}_{\mathrm{unb}}=\frac{E}{2} = \begin{pmatrix} 1&0.5\\ 0.5&1 \end{pmatrix}. $$

The estimated residual correlation is \(0.5/\sqrt{1\cdot1}=0.5\). Dividing \(E\) by \(n=3\) instead would give diagonal entries \(2/3\), not the unbiased estimate in this model. The divisor is tied to residual degrees of freedom, not automatically to the number of cases.

Residual Degrees of Freedom and the Covariance Estimate

Let \(r=\operatorname{rank}(X)\), and let \(P_X\) be the orthogonal projection onto the column space of \(X\). Least-squares residuals satisfy \(R=(I-P_X)Y\). The residual projection \(M=I-P_X\) is symmetric and idempotent, and its rank and trace are both \(\nu=n-r\). This remains the appropriate degree-of-freedom count if the design columns are linearly dependent; replacing \(r\) by \(p\) in that situation is an error.

Theorem: Suppose \(X\) is fixed, the rows \(u_i'\) of \(U\) are independent with \(E[u_i]=0\) and \(\operatorname{Cov}(u_i)=\Sigma\) for every case, and the mean model is correctly specified. Then \(E[R'R]=\nu\Sigma\), where \(\nu=n-\operatorname{rank}(X)\). Consequently, \(R'R/\nu\) is an unbiased estimator of \(\Sigma\) when \(\nu>0\).

Proof. Since the mean \(XB\) lies in the column space of \(X\), \(M X B=0\), so \(R=MU\). Therefore \(R'R=U'M'U=U'MU\). For response coordinates \(a\) and \(b\), the corresponding entry is \[ (U'MU)_{ab}=\sum_{i=1}^n\sum_{j=1}^n m_{ij}u_{ia}u_{jb}. \] Independence of different rows and their zero means imply \(E[u_{ia}u_{jb}]=0\) when \(i\ne j\), while \(E[u_{ia}u_{ib}]=\Sigma_{ab}\). Taking expectations yields \[ E[(U'MU)_{ab}]=\sum_{i=1}^n m_{ii}\Sigma_{ab} =\operatorname{tr}(M)\Sigma_{ab} =\nu\Sigma_{ab}. \] This holds for each pair \(a,b\), so \(E[R'R]=\nu\Sigma\). Dividing by positive \(\nu\) proves unbiasedness. \(\square\)

The assumptions matter. The formula does not automatically apply when case errors are correlated or have different covariance matrices. Nor does unbiasedness make \(E/\nu\) a universally correct divisor for every matrix summary: it applies to the residual covariance estimate under the stated model assumptions.

A Gaussian Maximum-Likelihood Caveat

A related pitfall is to state without qualification that the Gaussian maximum-likelihood estimate of \(\Sigma\) is \(E/n\). That expression is valid only when the covariance maximum exists in the positive-definite parameter space. In the Gaussian model with the mean fitted by least squares, the covariance-dependent part of the likelihood is proportional to \[ |\Sigma|^{-n/2}\exp\{-\tfrac12\operatorname{tr}(\Sigma^{-1}E)\}. \]

If \(E\) is positive definite, maximizing this likelihood over positive-definite \(\Sigma\) gives \(\hat{\Sigma}_{\mathrm{ML}}=E/n\). If \(E\) is singular, there is no finite maximum over positive-definite covariance matrices. To see why, diagonalize \(E\) in an orthonormal basis, with \(s<q\) positive eigenvalues and at least one zero eigenvalue. Choose \(\Sigma\) diagonal in the same basis, using eigenvalue \(\lambda_j/n\) for each positive eigenvalue \(\lambda_j\) of \(E\), and eigenvalue \(\epsilon>0\) in each zero-eigenvalue direction. The trace term stays fixed as \(\epsilon\) decreases, while \(|\Sigma|^{-n/2}\) grows without bound. Thus the likelihood is unbounded as \(\epsilon\downarrow0\), and no finite positive-definite covariance MLE exists. Since \(\operatorname{rank}(E)\leq\nu\), \(\nu<q\) guarantees singularity, though \(\nu\geq q\) alone does not guarantee that \(E\) is positive definite.

Worked Example: Residual Degrees of Freedom With a Rank-Deficient Design

Suppose a design matrix has \(n=6\) rows and \(p=3\) columns, but one column is an exact linear combination of the other two. Then \(\operatorname{rank}(X)=r=2\), not 3. The residual degrees of freedom are

$$ \nu=6-2=4, $$

not \(6-3=3\). For \(q=5\) responses, \(\operatorname{rank}(E)\leq\min(q,\nu)=4\), so \(E\) is necessarily singular. The unbiased residual covariance estimate \(E/4\) can still be defined if the model assumptions hold, but the Gaussian covariance MLE over positive-definite matrices does not exist. This example separates two claims that are often incorrectly merged: an unbiased estimate may be defined even when a finite positive-definite covariance MLE is not.

Reading Off-Diagonal Entries and Response Correlation

For residual columns \(r_a\) and \(r_b\), \(E_{ab}=r_a'r_b\). A positive value means the residuals tend to have products with positive sum; a negative value means their products tend to have negative sum. The sign by itself is not a correlation, because the cross-product depends on the scale of both residual columns.

When the diagonal entries are positive, the residual correlation calculated from \(E\) is \[ \frac{E_{ab}}{\sqrt{E_{aa}E_{bb}}}. \] Dividing every entry by the same positive number, such as \(\nu\), leaves this correlation unchanged. But residual response correlation is not generally the same as raw response correlation: raw responses may be associated because their fitted means vary together with the predictors. Residual correlation describes association remaining after the specified mean structure has been fitted.

Worked Example: Interpreting a Cross-Product Without Overclaiming

In the SSCP matrix from the earlier calculation, \(E_{12}=1\), \(E_{11}=E_{22}=2\), and \(\nu=2\). The estimated residual variances are both \(2/2=1\), and the estimated residual covariance is \(1/2=0.5\). Therefore the estimated residual correlation is

$$ \frac{0.5}{\sqrt{1\cdot1}}=0.5. $$

Equivalently, using the SSCP directly gives \(1/\sqrt{2\cdot2}=0.5\). The agreement occurs because the common divisor cancels. It would be wrong to report the cross-product \(1\) itself as the correlation, or to conclude from this residual calculation alone that the two raw outcomes have correlation \(0.5\).

Common Errors and Their Corrections

  • Transposing the wrong product. \(R'R\) is \(q\times q\) and contains cross-products among responses. \(RR'\) is \(n\times n\), with entries pairing cases. Check dimensions and intended interpretation before multiplying.
  • Calling the SSCP a covariance matrix. \(E=R'R\) contains sums. Under the stated common-covariance assumptions, \(E/\nu\), not \(E\), is the unbiased residual covariance estimate.
  • Using \(n-p\) when \(X\) is rank deficient. Residual degrees of freedom are \(n-r\), with \(r=\operatorname{rank}(X)\). The number of listed columns is not necessarily the number of independent fitted directions.
  • Calling \(E/n\) the Gaussian MLE in every case. It is the MLE only when \(E\) is positive definite. If \(E\) is singular, the likelihood over positive-definite covariance matrices is unbounded.
  • Confusing residual and raw response correlation. Off-diagonal residual cross-products describe association left after fitting the mean model; they do not automatically describe the marginal association of the observed responses.
Key takeaway: Check matrix dimensions first, identify whether a matrix contains sums or estimates, compute residual degrees of freedom from the design rank, and interpret response correlation in relation to the fitted mean model.

Check Your Understanding

For each question, state the relevant dimensions or assumptions as part of your answer.

  1. If \(Y\) is \(n\times q\) and \(X\) is \(n\times p\), what dimensions must \(B\) have for \(XB\) to be a fitted response matrix?
  2. Why is \(R'R\) a response-by-response SSCP matrix, while \(RR'\) is not?
  3. A design has \(n=12\) rows and rank 4. What are the residual degrees of freedom, and what divisor gives the unbiased residual covariance estimate under the theorem’s assumptions?
  4. When does \(E/n\) equal the Gaussian covariance MLE over positive-definite matrices, and what happens when \(E\) is singular?
  5. Why can residual response correlation differ from the correlation between the raw responses?
Clinical Biostats