Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Covariance Structures for Repeated Pseudobulk Measures

Differential Expression With Pseudobulk and Mixed Models · Tutorial 491 of 700

Covariance Structures for Repeated Pseudobulk Measures

Learn how within-donor covariance assumptions affect pseudobulk standard errors, and how compound symmetry compares with unstructured and other covariance models.

Advanced 11 min read

What You'll Learn

  • Define compound symmetry and connect it to a random-intercept model.
  • Distinguish a valid covariance matrix from one that is invertible.
  • Calculate standard errors under compound-symmetry and flexible covariance assumptions.
  • Compare compound symmetry with unstructured and other structured covariance models.
  • Identify diagnostics and design limitations that matter when choosing a covariance structure.

Why the Within-Donor Covariance Matters

A donor may contribute pseudobulk samples at several conditions or collection occasions. Those measurements are not independent simply because each is a separate sample: observations from the same donor can share biological features, and the amount of dependence can differ across pairs of occasions. A covariance structure describes that dependence. It affects how repeated observations contribute to estimated condition means and, in turn, the standard errors used for inference.

The focus here is the covariance among repeated measures, not the mean trend across occasions. The earlier material on random intercepts for donors gives a familiar starting point: a donor-level random effect induces positive within-donor correlation. The key question is what happens when the equal-correlation assumption implied by that model is too restrictive.

Definition: For a donor with \(m\) repeated pseudobulk responses, let \(\mathbf{Y}_i=(Y_{i1},\ldots,Y_{im})^\mathsf{T}\). Its within-donor covariance matrix is \(\mathbf{V}_i=\operatorname{Cov}(\mathbf{Y}_i)\), with diagonal entries equal to the response variances and off-diagonal entries equal to pairwise covariances. A covariance matrix must be symmetric and positive semidefinite. It need not be positive definite; positive definiteness is additionally required when an analysis assumes that the matrix is nonsingular and uses its inverse.

For a Gaussian model, one can write \(\mathbf{Y}_i=\mathbf{X}_i\boldsymbol{\beta}+\boldsymbol{\varepsilon}_i\), where the fixed-effects design matrix \(\mathbf{X}_i\) specifies the mean model and \(\operatorname{Cov}(\boldsymbol{\varepsilon}_i)=\mathbf{V}_i\). Donors are typically assumed independent of one another, so the full covariance matrix is block diagonal, with one block per donor. A covariance structure specifies the form of each block.

Pseudobulk counts are often modeled with count distributions rather than a Gaussian response. Covariance statements must therefore be tied to the model scale: the following Gaussian calculations apply directly to a modeled continuous response or to an appropriate working or latent scale, not automatically to raw counts. In a count model, the likelihood and covariance assumptions must be compatible with that model.

Compound Symmetry and Its Random-Intercept Connection

Compound symmetry (CS) assumes that every observation has the same marginal variance and every distinct pair of observations from one donor has the same covariance. If the marginal variance is \(v\) and the common covariance is \(c\), the \(m\)-occasion covariance matrix is:

$$ \mathbf{V}_{\mathrm{CS}}= \begin{pmatrix} v & c & \cdots & c\\ c & v & \cdots & c\\ \vdots & \vdots & \ddots & \vdots\\ c & c & \cdots & v \end{pmatrix}. $$

When \(v>0\), the common pairwise correlation is \(\rho=c/v\). For this matrix to be a valid covariance matrix, its eigenvalues must be nonnegative: \(v-c\), with multiplicity \(m-1\), and \(v+(m-1)c\), with multiplicity one. Thus the CS parameters must satisfy \(v-c\geq 0\) and \(v+(m-1)c\geq 0\). The common special case \(c\geq0\) and \(c\leq v\) satisfies these conditions.

A random-intercept model produces CS under specific assumptions. Suppose \(Y_{ij}=\mathbf{x}_{ij}^\mathsf{T}\boldsymbol{\beta}+b_i+e_{ij}\), where \(b_i\) has mean zero and variance \(\tau^2\), the errors \(e_{ij}\) have mean zero and variance \(\sigma^2\), and the donor effects and errors are mutually independent. Assume also that errors are independent across occasions and have equal variance. Then each response has variance \(\tau^2+\sigma^2\), while two different responses from the same donor share covariance \(\tau^2\). Equal residual variances and independent residuals are essential: with unequal variances or residual correlation, this simple random-intercept construction does not imply CS.

Worked Example: Obtaining CS From a Random Intercept

Suppose, hypothetically, that a transformed pseudobulk expression response has donor-intercept variance \(\tau^2=1.5\) squared expression units and independent residual variance \(\sigma^2=2.5\) squared expression units. There are three repeated measurements per donor. The model’s assumptions are that the donor effects are independent across donors, residuals are independent across measurements and donors, and both variance components are the same across occasions.

Each measurement has variance \(1.5+2.5=4.0\) squared expression units. Each within-donor pair has covariance \(1.5\) squared expression units because the shared random intercept is the only shared term. The resulting matrix is:

$$ \mathbf{V}_i= \begin{pmatrix} 4.0&1.5&1.5\\ 1.5&4.0&1.5\\ 1.5&1.5&4.0 \end{pmatrix}, \qquad \rho=\frac{1.5}{4.0}=0.375. $$

Thus this model assumes a within-donor correlation of 0.375 for every pair, whether the measurements are adjacent or far apart. The matrix is positive definite: its eigenvalues are \(4.0-1.5=2.5\) twice and \(4.0+2(1.5)=7.0\) once, all positive. The equal-correlation assumption is a property of this model, not a general fact about repeated pseudobulk data.

More Flexible Structures

A more flexible choice is an unstructured covariance matrix. It estimates a separate variance for each occasion and a separate covariance for each pair. For \(m\) occasions, that is \(m(m+1)/2\) distinct parameters: \(m\) variances and \(m(m-1)/2\) covariances. The estimates must still form a symmetric positive semidefinite matrix. This flexibility can represent unequal variances and pair-specific dependence, but costs many parameters and can be difficult to estimate with few independent donors.

Other structures impose different, more economical patterns. For example, an autoregressive structure of order one (AR(1)) for equally spaced occasions assigns a common marginal variance and makes correlation decrease geometrically with the separation between occasions: the correlation at lag \(k\) is \(\rho^k\), with \(|\rho|<1\). It can represent greater dependence between nearby measurements without estimating every pairwise covariance. Independent residuals are the limiting simple alternative with zero off-diagonal covariance. These are substantive assumptions; the most complex model is not automatically the best choice.

One can compare structures through their implied covariance patterns, whether the design supports estimation of their parameters, and whether fitted models show plausible residual dependence. Likelihood-based comparisons require models fitted to the same response and mean structure, and their inferential conditions must be met. A numerical fit criterion alone cannot establish that a covariance pattern is biologically appropriate.

Worked Example: A Pair-Specific Contrast Under Two Structures

Consider hypothetical measurements at three occasions. Suppose a CS model has marginal variance 4 and common covariance 2, all in squared expression units. As a flexible alternative, consider:

$$ \mathbf{V}_{\mathrm{flex}}= \begin{pmatrix} 4&1&2\\ 1&4&1\\ 2&1&9 \end{pmatrix}. $$

This proposed matrix is symmetric. Its leading principal minors are \(4\), \(4(4)-1(1)=15\), and its determinant is \(4(36-1)-1(9-2)+2(1-8)=140-7-14=119\). Since all leading principal minors are positive, it is positive definite. In particular, the different occasion variances and pairwise covariances form a valid covariance matrix.

For the contrast between occasion 3 and occasion 1, the variance of the within-donor difference is \(\operatorname{Var}(Y_{i3}-Y_{i1})=\operatorname{Var}(Y_{i3})+\operatorname{Var}(Y_{i1})-2\operatorname{Cov}(Y_{i3},Y_{i1})\). Under CS this is \(4+4-2(2)=4\), giving a standard deviation of \(2\) expression units. Under the flexible matrix it is \(9+4-2(2)=9\), giving a standard deviation of \(3\) expression units. The flexible model assigns a larger uncertainty to this contrast because occasion 3 has larger variance; the fact that the shared covariance for this pair is the same in both structures does not make their contrast variances equal.

How Covariance Assumptions Change Standard Errors

For a linear model with known covariance matrix \(\mathbf{V}\), generalized least squares estimates the fixed effects using \(\widehat{\boldsymbol{\beta}}=(\mathbf{X}^\mathsf{T}\mathbf{V}^{-1}\mathbf{X})^{-1}\mathbf{X}^\mathsf{T}\mathbf{V}^{-1}\mathbf{Y}\). Under the model, its covariance matrix is \((\mathbf{X}^\mathsf{T}\mathbf{V}^{-1}\mathbf{X})^{-1}\); a standard error is the square root of the corresponding diagonal entry. In practice, covariance parameters are estimated, and the reported model-based standard errors generally treat the fitted structure as correct, subject to the method’s estimation and inference approximations.

A useful derivation shows the effect of CS on a balanced average. For one donor, let \(\bar{Y}_i=m^{-1}\sum_{j=1}^{m}Y_{ij}\). The variance of a sum is the sum of all variances and covariances, so:

$$ \operatorname{Var}(\bar{Y}_i) =\frac{1}{m^2}\{mv+m(m-1)c\} =\frac{v+(m-1)c}{m} =\frac{v\{1+(m-1)\rho\}}{m}. $$

If \(n\) independent donors each contribute all \(m\) measurements under the same structure, the variance of the average of their donor averages is \(v\{1+(m-1)\rho\}/(mn)\). Treating all \(mn\) observations as independent would instead use \(v/(mn)\), which is too small when \(\rho>0\). This derivation assumes a balanced design, equal variances, common correlation, and independent donors. With unequal variances or pair-specific covariances, the relevant variance is computed from the full matrix and the particular contrast weights.

Worked Example: Comparing Standard Errors for a Group Difference

Suppose, hypothetically, there are 8 independent donors in each of two groups, with three repeated measurements per donor. The outcome is a transformed expression value in expression units. Assume each group has the same within-donor covariance, donors are independent, and the covariance is known for this illustration. Under CS, the diagonal entries are 4 and the off-diagonal entries are 2. Under the flexible matrix from the previous example, the diagonal entries are 4, 4, and 9, and the off-diagonal entries for the three pairs are 1, 2, and 1.

The donor-average variance under CS is the sum of all nine matrix entries divided by \(3^2\): \(\{3(4)+6(2)\}/9=24/9=2.667\) squared expression units. Under the flexible structure it is \(\{4+4+9+2(1+2+1)\}/9=25/9=2.778\) squared expression units.

The estimated group difference is the difference between the two groups’ average donor means. Each group has 8 independent donor averages, so its variance is the donor-average variance divided by 8. The variance of the difference is the sum of the two group variances. Under CS, \(SE=\sqrt{2(2.667/8)}=\sqrt{2/3}=0.8165\) expression units. Under the flexible structure, \(SE=\sqrt{2(2.778/8)}=\sqrt{25/36}=0.8333\) expression units.

If the hypothetical estimated difference is 1.20 expression units, the corresponding estimate divided by its standard error is \(1.20/0.8165=1.470\) under CS and \(1.20/0.8333=1.440\) under the flexible structure. The flexible structure gives slightly greater estimated uncertainty here. This comparison isolates the covariance effect under the stated assumptions; it does not show that either structure is correct or establish a causal group effect.

Diagnostics, Limitations, and Common Pitfalls

Covariance structure is rarely known with certainty. Useful checks include inspecting within-donor residual patterns by occasion and separation, comparing observed pairwise residual associations with those implied by the fitted model, and checking whether estimated variances or correlations are near parameter boundaries. Such checks can be noisy when donor numbers are small. A complex unstructured matrix may fail to converge or yield unstable estimates because there is insufficient independent donor information to estimate all its parameters. Conversely, a converged CS model can still be inadequate if residual variances differ by occasion or correlations clearly vary across pairs.

A covariance matrix must be symmetric and positive semidefinite, but it need not be positive definite. For instance, if two components of a random vector are exactly the same random variable, their covariance matrix is singular and positive semidefinite. A fitting method that requires an inverse may need positive definiteness; that computational requirement should not be mistaken for the definition of a covariance matrix.

Common mistake: “There are many repeated samples, so treating them as independent gives a more precise estimate; each sample adds information.” The correction is that observations from the same donor share dependence, so the information gained from another measurement depends on its covariance with existing measurements. Positive within-donor correlation often makes the independent-observation standard error too small. A more flexible covariance model can change that standard error, but does not necessarily increase it for every coefficient or contrast: the direction and size of the change depend on the covariance pattern and the design.

Covariance modeling also has practical limits. Estimating many parameters consumes information, especially when the number of independent donors is modest. If a structure is misspecified, model-based standard errors can be inaccurate even when the mean model is reasonable. A robust variance approach can be an alternative in suitable settings, but it has its own sample-size and design requirements. No covariance choice compensates for a design with too few independent donors or for a poorly specified mean model.

1
State the repeated unit and response scale.
Identify which pseudobulk observations belong to each donor, and specify the scale on which the covariance model applies.
2
Choose a defensible pattern.
Use CS only when equal marginal variances and common within-donor covariance are plausible; consider a structured or unstructured alternative when the design and donor count support it.
3
Check validity and fit.
Confirm that the estimated covariance is symmetric and positive semidefinite, and inspect convergence, boundary estimates, and residual dependence.
4
Reassess the target’s uncertainty.
Compute standard errors from the fitted covariance and report how sensitive the target contrast is to plausible alternative structures.

Check Your Understanding

Try each question, then compare your reasoning with the solutions.

  1. Under a random-intercept model with independent residuals, what determines the covariance between two different measurements from the same donor?
  2. For \(m=4\), marginal variance \(v=5\), and common correlation \(\rho=0.2\), calculate the variance of a donor’s four-measurement average under CS.
  3. Why is an unstructured covariance model harder to estimate as the number of occasions increases?
  4. A covariance matrix is symmetric and singular. Must it be invalid as a covariance matrix? Explain.
  5. Does changing from CS to a more flexible covariance structure necessarily increase every standard error? Explain.

Solutions. (1) The shared random intercept: if its variance is \(\tau^2\), the covariance is \(\tau^2\), provided residuals are independent across measurements. (2) The formula gives \(5\{1+3(0.2)\}/4=8/4=2\) squared response units. (3) It estimates \(m(m+1)/2\) distinct variances and covariances, so the parameter count grows quadratically and can exceed what the independent donors can support. (4) No. A covariance matrix may be positive semidefinite and singular; singularity prevents inversion but does not by itself make the matrix invalid. (5) No. Standard-error changes depend on the particular contrast, design, and covariance estimates; the flexible model can increase or decrease a given standard error.

Clinical Biostats