Matrix Algebra and Distribution Refresher
In this appendixnotation; basic matrix operations and the centering matrix; inverse, determinant, and rank; quadratic forms, eigenvalues, and positive definiteness; block matrices and the covariance matrix of a cluster; Kronecker products; expectations and covariances of linear forms, GLS, and the REML projection matrix; the multivariate normal distribution and its conditional distributions; derivatives, information, and the delta method; the chi-square, t, and F distributions; distributions for discrete outcomes; mixture distributions for tests on the boundary.
This appendix collects the matrix algebra and distribution theory that the chapters use, in the book’s notation. It is written as a reference rather than as a course: each result is stated, briefly motivated, and connected to the place where the book needs it. A small running example from three schools of the 23-school NELS:88 subsample (Kreft & de Leeuw, 1998) makes the abstract operations concrete. For fuller treatments, see the further reading at the end.
A.1Notation#
Scalars are in italic type (, ), vectors in bold lowercase (, ), and matrices in bold uppercase (, ). All vectors are column vectors, and a prime denotes the transpose, so that is a row vector. For cluster () with units ( units in all), is the vector of outcomes, the matrix of predictors with fixed effects , the matrix of predictors with random effects , the covariance matrix of , and the level-1 residual variance. The multilevel model in matrix form (Chapter 2, Equation (2.6)) is
and it implies the marginal model with . Special vectors and matrices are , a column of ones; , the identity matrix; and , the matrix of ones. Subscripts giving dimensions are dropped when they are clear from the context.
A.2Basic Operations#
Matrices of the same dimensions are added elementwise. The product of an matrix and an matrix is the matrix with elements ; it requires that the number of columns of equal the number of rows of , and in general . The transpose reverses products, . A matrix is symmetric if ; covariance matrices are symmetric. The inner product is a scalar, and , so that the mean of a cluster is . The trace of a square matrix is the sum of its diagonal elements, ; it satisfies whenever both products exist, a rule that simplifies the expectations of quadratic forms (Section A.7). The centering matrix subtracts the mean: contains the within-cluster deviations, and repeats the cluster mean. Both matrices are symmetric and idempotent (), they sum to , and their product is zero, which is the matrix form of the within-between decomposition of Chapters 3 and 7.
In the running example, the first three students of school A (NELS:88 identifier 6467) have outcome vector and predictor matrix with a column of ones for the intercept and a column of homework categories, and the random-intercept design matrix is :
Table A.1 lists the ten students of the excerpt: 3 from school A, 4 from school B (6327), and 3 from school C (7472). The excerpt serves only to illustrate the operations; the variance components used below come from the random-intercept model for all 519 students in 23 schools, fitted by REML (model M1 of Table 2.2), with , for homework, , and .
| School (NELS:88 identifier) | Student | Homework (category) | Mathematics |
|---|---|---|---|
| A (6467) | 3 | 3 | 61 |
| A (6467) | 43 | 0 | 42 |
| A (6467) | 56 | 3 | 67 |
| B (6327) | 4 | 1 | 61 |
| B (6327) | 9 | 1 | 56 |
| B (6327) | 13 | 1 | 46 |
| B (6327) | 15 | 0 | 60 |
| C (7472) | 3 | 1 | 48 |
| C (7472) | 8 | 0 | 48 |
| C (7472) | 13 | 0 | 53 |
Note. The first three, four, and three students, by student number, of three schools of the 23-school NELS:88 subsample. Student: student identification number within the school. Homework: category of weekly time on mathematics homework (0 = none, 1 = less than one hour, 2 = one hour, 3 = two hours, 4 = three hours, 5 = four to six hours, 6 = seven to nine hours, 7 = 10 hours or more); mathematics: achievement test score.
A.3Inverse, Determinant, and Rank#
The inverse of a square matrix is the matrix with . It exists if and only if the determinant is not zero. Then , and for invertible and of the same order, . For a matrix,
The determinant of a product is the product of the determinants, , the determinant of a diagonal matrix is the product of its diagonal elements, and that of a block-diagonal matrix is the product of the determinants of its blocks. The determinant of a covariance matrix is a generalized variance: it enters the normal likelihood (Section A.8) and shrinks toward zero when the variables are nearly collinear. The rank of a matrix is the maximum number of linearly independent columns (equivalently, rows). The stacked design matrix must have full column rank for the fixed effects to be identified (a single need not: a cluster-level variable is constant within a cluster and so collinear with its intercept column); a dummy variable for every cluster together with an intercept, or a cluster-level variable together with cluster dummies (Chapter 32), violates this condition.
A.4Quadratic Forms, Eigenvalues, and Positive Definiteness#
A quadratic form is a scalar with a symmetric matrix . The matrix is positive definite if for every nonzero , and positive semidefinite if . Every covariance matrix is positive semidefinite, because is the variance of the linear combination and cannot be negative. The eigenvalues of a symmetric matrix solve for nonzero vectors ; their product is the determinant and their sum the trace. A positive definite matrix has only positive eigenvalues, a positive determinant, and an inverse; a positive semidefinite matrix that is not positive definite has at least one zero eigenvalue and describes a variable combination without variance. This is what a singular fit in lme4 reports: the estimated is positive semidefinite but not positive definite and so lies on the boundary of the parameter space, for example with a zero variance, a correlation of , or, with three or more random effects, a linear combination of the random effects that has zero variance (Chapter 9).
Every positive definite matrix has a Cholesky factorization with a lower triangular that has positive diagonal elements. Software uses the factorization to compute inverses and determinants stably, , and to parameterize covariance matrices so that they remain positive semidefinite during estimation; lme4, for example, writes with a lower triangular relative covariance factor whose diagonal elements are constrained to be nonnegative (Chapter 9), so that is always positive semidefinite and is singular when a diagonal element of is zero (Bates et al., 2015). Quadratic forms appear throughout the book: the exponent of the normal density, the Wald statistic, and the generalized residual sum of squares are all quadratic forms.
A.5Block Matrices and the Covariance Matrix of a Cluster#
Stacking the clusters gives and , with covariance matrix , a block-diagonal matrix: units in different clusters are independent, and all dependence lies within the blocks. Because the inverse and the determinant of a block-diagonal matrix are obtained block by block, and , estimation never has to invert the full matrix.
For the random-intercept model, and , so that
the compound-symmetry matrix with on the diagonal and off the diagonal. Figure A.1 shows for the ten students of the excerpt: each diagonal element is 92.63, each covariance between two students of the same school is 21.34, and all other elements are zero; for school A,
The correlation between two students of the same school, conditional on homework, is the residual intraclass correlation, 21.34/92.63 = .23. The compound-symmetry matrix has two distinct eigenvalues: , once, with eigenvector , and , times, with the eigenvectors orthogonal to . For school A they are 135.31 and 71.28. The matrix is therefore positive definite as long as and , so that a slightly negative is admissible in the marginal interpretation of the model (Chapter 11).
Note. Rows and columns: students of the excerpt, labeled by school (A, B, C) and position. Cell values: model-implied variances (diagonal) and covariances under the random-intercept model with the variance components estimated from all 23 schools, rounded to one decimal. Black: variances; dark gray: covariances within a school; light gray: zero covariances between schools. Black lines separate the school blocks.
Inverses of patterned matrices. Two identities give closed-form inverses and determinants of such matrices. The Woodbury identity states that, for conformable matrices with and invertible,
and the matrix determinant lemma states that . With , , , and , the identity gives , which requires only the inversion of a matrix. When is singular, the equivalent form avoids . For the random intercept,
For school A with , the diagonal elements of are 0.0118, the off-diagonal elements are 0.0022, and , the product of the three eigenvalues; direct numerical inversion agrees with Equation (A.5) to within in every element, and the determinant computed by software agrees to within a relative difference of . The factor is times the variance of the cluster mean (Section A.7), and it reappears in the shrinkage factor of Section A.8.
A.6Kronecker Products and Balanced Designs#
The Kronecker product of an matrix and a matrix is the block matrix whose block is . Its rules are when the products and exist, , for invertible and , and, for square () and (), . In a balanced design with clusters of units, the covariance matrix of the random-intercept model is
which shows at once that the clusters are independent and identically structured, and that . The vec operator, which stacks the columns of a matrix, is linked to the Kronecker product by . Kronecker products also describe separable covariance structures, for example for repeated measures of several outcomes, and they also express the covariance matrix of a cluster in the multivariate multilevel model of Chapter 27 (outcomes stacked within units, complete data); the balanced-design results of Chapters 3 and 16, such as expected mean squares and design effects, can be derived with them.
A.7Expectations and Covariances of Linear Forms#
If has mean and covariance matrix , and , , and are constant, then
For a quadratic form, ; this result underlies the bias of the maximum likelihood variance estimator and its correction by REML (Chapter 9). Applied to the random-intercept model, Equation (A.7) gives the variance of a cluster mean, , and, divided by , the design effect of Chapter 16, where .
The generalized least squares (GLS) estimator of the fixed effects, for known , is a linear form in :
With the stacked and of Section A.5, and with ; the covariance matrix follows from Equation (A.7), because . In practice the estimated replaces , and the standard errors ignore the uncertainty of the variance components, which is why the small-sample corrections of Chapter 10 (Satterthwaite or Kenward–Roger degrees of freedom and Kenward–Roger standard errors) are needed with few clusters. For the ten students of the excerpt, Equation (A.8) with the variance components of the full data gives an intercept of 49.35 (SE 4.67) and a homework slope of 4.69 (SE 2.70), against 49.78 and 4.42 from ordinary least squares, which weights all students equally. Because the REML estimate of is the GLS estimate evaluated at , Equation (A.8) applied to all 519 students reproduces the lme4 estimates and standard errors to within .
Projection matrices. In ordinary regression, the hat matrix projects onto the fitted values; it is symmetric and idempotent, and produces the residuals. In GLS, the fitted values are with , which is idempotent but not symmetric, and the residuals are weighted by in the matrix , that is,
which satisfies and . The REML log-likelihood depends on only through , which does not involve : up to a constant, (Chapter 9). The CR2 adjustment of cluster-robust standard errors (Chapters 10 and 32) uses the diagonal blocks of the hat matrix, for OLS and for GLS.
A.8The Multivariate Normal Distribution#
An vector with mean and positive definite covariance matrix is multivariate normal, , if its density is
The ML log-likelihood of the multilevel model is the sum over clusters of the logarithm of Equation (A.10) with and , which is where the determinants and inverses of Section A.5 enter; the REML log-likelihood of Section A.7 evaluates it at the GLS estimate and adds , up to a constant (Chapter 9). Three properties are used repeatedly. First, a linear function of a multivariate normal vector is multivariate normal, with the mean and covariance of Equation (A.7); the marginal model follows from Equation (A.1) in this way, because and are independent and therefore jointly normal. Second, uncorrelated elements or subvectors of a multivariate normal vector are independent; for variables that are each normal but not jointly normal, zero correlation does not imply independence. Third, if is partitioned into and with mean and covariance
then the conditional distribution of given is normal with
The conditional mean is a linear regression of on , and the conditional variance does not depend on the observed . The matrix is the Schur complement of , which also appears in the inverse of a partitioned matrix; Chapter 12 uses this inverse of the coefficient matrix of Henderson’s mixed-model equations to obtain the prediction-error variances of the random effects, and Appendix B also uses it to obtain the covariance matrix of .
Empirical Bayes predictions as conditional means. The random effects and the outcomes are jointly normal, with . Applying Equation (A.12) with and (so that , , , , and ) gives the conditional mean and variance
With estimates in place of , , and , the conditional mean is the empirical Bayes prediction, and the conditional variance is the posterior variance that lme4 reports, which ignores the uncertainty of (Chapter 12). For the random intercept, Equation (A.5) reduces these expressions to and , where and is the reliability of the cluster mean (Chapter 5, Equation (5.3)) and the shrinkage factor. In the excerpt, school A has and a mean residual of 2.07 from the GLS fit to the ten students, so its predicted effect is 0.98 with a posterior standard deviation of 3.35; school B, with four students, has , a mean residual of 2.88, and a predicted effect of 1.57. Computed in this way for all 23 schools, the predictions agree with those of lme4.
A.9Derivatives, Information, and the Delta Method#
Newton-type algorithms for maximizing a likelihood, and the standard errors that follow from it, use derivatives with respect to the parameters, and two matrix rules do most of the work. For a covariance matrix that depends on a parameter ,
for the random intercept, and . The vector of first derivatives of the log-likelihood is the score, and the negative expected matrix of second derivatives is the Fisher information , where collects the fixed effects and the covariance parameters of Chapter 9. With many clusters, and when the true values lie in the interior of the parameter space (Section A.12), the ML estimator is approximately normal with covariance matrix ; this is the source of the standard errors of fixed effects and variance components, and Fisher scoring and Newton–Raphson use the same derivatives to find the maximum (Chapter 9).
The delta method gives approximate standard errors for functions of estimates. If is approximately and is a smooth function with gradient , then . Two applications are common in multilevel reports: the standard error of a standard deviation from that of a variance, , and the standard error of the intraclass correlation , whose gradient with respect to is . Because the sampling distributions of variance estimates are skewed when the clusters are few, intervals from profile likelihood or the bootstrap are preferable to delta-method intervals for variance components (profile and bootstrap intervals: Chapter 10; the failure of Wald inference for variances: Chapter 11).
A.10The Chi-Square, t, and F Distributions#
If are independent standard normal variables, has a chi-square distribution with degrees of freedom, , with mean and variance . More generally, if with elements, the quadratic form is . This is the basis of the Wald test of linear hypotheses , with a contrast matrix of rank , whose statistic is approximately when the clusters are many. The likelihood-ratio statistic of nested models that differ by parameters has the same approximate distribution when the null values of these parameters lie in the interior of the parameter space; models that differ in their fixed effects must be compared with ML, not REML, log-likelihoods, whereas models with the same fixed part may be compared with either (Chapters 10 and 11).
If is standard normal and independent of , then has a distribution with degrees of freedom; and if and are independent, has an distribution with and degrees of freedom. In multilevel models, the and reference distributions are approximations whose degrees of freedom must be estimated, for example by the Satterthwaite or Kenward–Roger methods of Chapter 10, because the squared standard errors are not exactly scaled chi-square variables independent of the estimates.
A.11Distributions for Discrete Outcomes#
The generalized linear mixed models of Chapters 23 and 24, and the discrete-time hazard models of Chapter 25, replace the normal distribution of the outcome, given the random effects, by distributions for discrete data. A binary outcome is Bernoulli with success probability , mean , and variance ; the number of successes in independent trials with a common probability is binomial, with mean and variance . A count is often modeled as Poisson, with variance equal to its mean ; a variance larger than the mean is overdispersion, which the negative binomial distribution or an observation-level random effect absorbs (Chapter 24). The Bernoulli, binomial, and Poisson variances are functions of the mean, so that, unlike in the normal model, the level-1 variance is not a separate parameter. The logistic model for a binary outcome can be written as a threshold model for a continuous latent response whose residual has the standard logistic distribution, with mean 0 and variance , where is the mathematical constant; this constant replaces in the latent-scale intraclass correlation of Chapter 23.
A.12Mixture Distributions for Tests on the Boundary#
The chi-square reference distribution of the likelihood-ratio test requires that the null value of the tested parameters lie in the interior of the parameter space. A variance is bounded below by zero, so the null hypothesis places the parameter on the boundary. Under this null hypothesis, and with many clusters, the estimate is zero in about half of the samples (somewhat more often with few clusters, especially under ML; Chapter 11), and the likelihood-ratio statistic is then zero; in the other half it behaves like . Its large-sample distribution is therefore the 50:50 mixture of a point mass at zero () and (Self & Liang, 1987; Stram & Lee, 1994). When a random slope is added to a model with a random intercept, one variance and one covariance are added, and the reference distribution becomes the 50:50 mixture of and . More generally, adding one random effect to a model with correlated random effects adds one variance and covariances, the reference distribution is the 50:50 mixture of and , and the value of an observed statistic is
with . Table A.2 gives critical values, and Figure A.2 compares the tail probabilities with those of the naive chi-square distribution. For one variance, the mixture critical value at is 2.71, which is the 10% critical value of : a statistic of 2.71 has under but under the mixture, and the usual critical value 3.84 corresponds to . The naive test is thus conservative, and its values can be halved in this case. When several variances are tested together, the mixture has more components with weights that depend on the information matrix, and simulation or a parametric bootstrap is the practical route (Chapter 11).
| 50:50 mixture at | Naive at | ||||||
|---|---|---|---|---|---|---|---|
| Reference mixture | Parameters tested | .10 | .05 | .01 | .10 | .05 | .01 |
| 1 | 1.64 | 2.71 | 5.41 | 2.71 | 3.84 | 6.63 | |
| 2 | 3.81 | 5.14 | 8.27 | 4.61 | 5.99 | 9.21 | |
| 3 | 5.53 | 7.05 | 10.50 | 6.25 | 7.81 | 11.34 | |
Note. : 50:50 mixture of chi-square distributions with and degrees of freedom, the reference distribution for adding one random effect to a model with correlated random effects; : point mass at zero. Parameters tested: (one variance and covariances), which is also the degrees of freedom of the naive chi-square distribution. : upper-tail probability.
Note. Solid lines: naive chi-square distributions with 1 (panel a) and 2 (panel b) degrees of freedom; dashed lines: 50:50 mixtures of chi-square distributions with 0 and 1 (panel a) and 1 and 2 (panel b) degrees of freedom. Horizontal dotted line, labeled .05: upper-tail probability .05; vertical dotted line: the corresponding critical value of the mixture.
Further Reading#
- Searle et al. (1992)
-
Matrix results and the distribution theory of variance components models.
- Pinheiro & Bates (2000)
-
The matrix formulation of linear mixed models and its computation.
- Self & Liang (1987); Stram & Lee (1994)
-
Likelihood-ratio tests when parameters lie on the boundary.