Why Shared Sample Influences Matter
A co-expression network summarizes which genes vary together across samples. But a correlation does not by itself show that the genes are co-regulated, interact, or even share a biological mechanism. If a technical or biological feature changes many genes together across samples, it can create correlation between genes whose expression is otherwise unrelated. Batch, cell-type proportions, RNA quality, and library characteristics are common sources of this pattern.
The relevant question is not simply whether a correlation is large. It is whether the association remains interpretable after considering plausible shared influences, and whether the data contain enough information to distinguish those influences from biology. The checks here are targeted diagnostics: they help identify suspicious patterns, but do not automatically establish the cause of a correlation.
How a Shared Influence Creates Covariance
Let \(X\) and \(Y\) denote measured expression for two genes, and let \(Z\) denote a sample-level factor such as batch or a cell-type proportion. The law of total covariance separates the overall covariance into a within-\(Z\) component and a component due to differences in conditional means:
The first term averages the gene covariance among samples with the same value of \(Z\). The second measures whether the expected expression of the two genes rises and falls together across values of \(Z\). It can be large even when the first term is zero.
For a categorical batch variable, this means that two genes can have similar batch-specific mean shifts and therefore correlate across all samples, even if their within-batch deviations are uncorrelated. A useful justification follows by writing \(X-E(X)\) as \([X-E(X\mid Z)]+[E(X\mid Z)-E(X)]\), and doing the same for \(Y\). The cross-products between a within-\(Z\) deviation and a conditional mean have expectation zero given \(Z\). Taking expectations leaves exactly the two terms in the identity.
This decomposition is descriptive, not a causal conclusion. It says where covariance is distributed relative to \(Z\); it does not prove that \(Z\) caused the expression shifts. The same logic applies to an estimated cell fraction, a quality metric, or a measured phenotype.
Worked Example: A Batch Shift Produces a Large Overall Correlation
Consider eight hypothetical samples processed in two batches. The expression values below are on a normalized scale. The genes have different within-batch deviations, but both have a batch mean that is 10 units higher in Batch 2.
Gene X values are \(8,9,11,12\) in Batch 1 and \(18,19,21,22\) in Batch 2. Gene Y values are \(29,32,28,31\) in Batch 1 and \(39,42,38,41\) in Batch 2. Their overall means are \(\bar{x}=15\) and \(\bar{y}=35\).
Within each batch, the deviations from the batch mean are \((-2,-1,1,2)\) for X. For Y they are \((-1,2,-2,1)\). The sum of paired products in either batch is \( (-2)(-1)+(-1)(2)+(1)(-2)+(2)(1)=0\). Thus, the within-batch covariance is zero in both batches.
Across all eight samples, the sum of products of deviations from the overall means is \(200\), and the corresponding sums of squared deviations are \(220\) for each gene. The sample correlation is therefore
The large overall correlation is entirely due to the shared batch mean shift in this constructed example: the covariance decomposition gives a zero average within-batch covariance and a between-batch covariance of \(25\) (using divisor \(n\)). The result warns against interpreting the raw correlation as evidence that X and Y are biologically linked. In an actual analysis, one would check batch-specific expression patterns and whether the apparent association persists after accounting for batch.
Cell Mixture and Other Shared Sample Features
Bulk expression measurements combine RNA from the cell types present in a sample. If the proportion of a cell type varies across samples, genes that are more highly expressed in that cell type can rise together, even when their expression is not coordinated within the cell type. The mixture effect can be especially strong for marker genes.
For a simple two-cell-type mixture, let \(q\) be the proportion of cell type A. If a gene has mean expression \(a\) in type A and \(b\) in type B, its bulk value in this simplified model is \(b+(a-b)q\). When two genes both have higher expression in type A, both bulk values increase with \(q\). This creates a positive relationship through cell composition.
Worked Example: Cell Proportions Induce Perfect Bulk Correlation
Suppose four hypothetical samples have cell-type A proportions \(q=0.2,0.4,0.6,0.8\). In a simplified mixture model, Gene U has expression 10 in type A and 2 in type B, while Gene V has expression 6 in type A and 1 in type B. Assume these cell-type-specific values are constant across samples, with no within-cell co-regulation represented.
The bulk expression for U is \(2+(10-2)q\), giving \(3.6,5.2,6.8,8.4\). For V it is \(1+(6-1)q\), giving \(2,3,4,5\). The values satisfy \(V=0.625U-0.25\) exactly. Because this is a straight line with positive slope, the bulk correlation is \(r_{UV}=1\).
This perfect correlation does not imply that the genes interact or are co-regulated within either cell type. In this example, their shared variation comes entirely from the changing proportion \(q\). A targeted check would compare the genes with cell-fraction estimates or relevant marker genes, and examine whether their association remains after accounting for composition. Such adjustment is informative only to the extent that the fractions are measured adequately and there is sufficient variation in them separate from other factors.
The same reasoning applies to technical quality measures. For example, if a sample-wide quality factor raises measured expression for many genes, genes can correlate because they share that influence. Associations with library size, RNA integrity, mapping rate, or a broad expression principal component can therefore be diagnostic clues. They are clues, not proof: a principal component may also represent genuine biology.
Targeted Checks and Covariate Adjustment
A useful investigation starts with factors that are plausible for the data and question, rather than adjusting for every available variable. For a categorical batch, compare expression distributions across batches and calculate correlations within batches when there are enough samples. For cell composition, inspect estimated fractions and marker-gene patterns. For technical quality, check gene expression and module summaries against relevant quality metrics.
One general adjustment is to regress each gene’s expression on measured covariates, then calculate the correlation between the residuals. In a linear adjustment, each residual is the observed value minus its fitted value from the covariate model. This asks whether the genes co-vary beyond the linear mean patterns represented by those covariates. It is not a universal correction: a wrong model, noisy covariates, or a poorly measured nonlinear effect may leave confounding behind.
Worked Example: Adjusting for a Sample-Quality Score
Suppose a hypothetical quality score \(Q\) takes values \(-1,-1,1,1\). Gene X has values \(7,9,11,13\), and Gene Y has values \(18,16,22,24\). These values follow the fitted relationships \(X=10+2Q+e_X\) and \(Y=20+3Q+e_Y\), with residuals \(e_X=(-1,1,-1,1)\) and \(e_Y=(1,-1,-1,1)\).
The overall means are 10 and 20. The sums of squared deviations are 20 for X and 40 for Y; the sum of cross-products is 24. Thus the raw correlation is
The fitted slopes are obtained from the sample cross-products with \(Q\): for X, \(\sum(Q_i-\bar{Q})(X_i-\bar{x})/\sum(Q_i-\bar{Q})^2=8/4=2\); for Y, the corresponding value is \(12/4=3\). After subtracting these fitted linear effects, the residual cross-product sum is \((-1)(1)+(1)(-1)+(-1)(-1)+(1)(1)=0\). The residual sums of squares are both 4, so the residual correlation is \(0/\sqrt{4(4)}=0\).
Here the raw association is explained by the shared linear quality pattern, while the adjusted residuals are uncorrelated. In real data, a near-zero adjusted correlation would not prove that quality caused the raw association: it would show that this particular linear adjustment removes the measured association in these samples.
The linear residual check is most straightforward when the association between each gene and the covariate is reasonably represented by the fitted model, samples are independent, and covariates are measured with useful accuracy. If a gene has a nonlinear relationship with a proportion or quality measure, a linear fit may be inadequate. If there are very few samples in a batch, within-batch correlations will also be imprecise and may be unstable.
Choosing a Diagnostic and Recognizing Failure
| Check | What it can reveal | Main caution |
|---|---|---|
| Compare expression across batches or strata | Whether group mean shifts or within-stratum patterns differ | Small strata make correlations imprecise |
| Regress out measured covariates and correlate residuals | Whether linear covariate-associated variation accounts for the correlation | Misspecified models and noisy covariates can leave artifacts |
| Relate genes or a module summary to cell fractions and quality measures | Whether a suspected shared influence tracks the expression pattern | Association with a covariate is not proof of artifact or causation |
| Compare raw and adjusted results | How sensitive the association is to the chosen adjustment | Adjustment can remove real biology if the covariate lies on a biological pathway of interest |
A central failure mode is confounding between batch and the biological condition of interest. If every control sample is in Batch 1 and every treated sample is in Batch 2, the data do not contain comparisons that separate the batch effect from the condition effect. A regression including both cannot identify their separate contributions from these samples alone. No adjustment formula can recover information absent from the design; the limitation must be reported, and independent or better-balanced data may be needed.
Another pitfall is to equate “correlation disappears after adjustment” with “the original correlation was meaningless.” A cell fraction may be part of the biological phenomenon being studied, so removing its contribution could discard relevant biology. Conversely, a correlation that persists after adjustment is not automatically genuine co-regulation: unmeasured or poorly measured sample-level influences may remain. Adjustment changes the question to conditional association, not causal interpretation.
Check Your Understanding
Answer each question, then compare with the solutions below.
- If two genes have positive overall covariance but zero covariance within each batch, what component of the covariance decomposition can explain the overall association?
- In the two-cell-type model, why can two genes that are both more highly expressed in cell type A correlate across bulk samples?
- In the quality-score example, what are the raw and residual correlations, and what does their difference show?
- All treated samples are in one batch and all controls are in another. Can a model using these data cleanly distinguish condition from batch? Explain.
Solutions. (1) The covariance of the conditional means across batches can be positive even though the average within-batch covariance is zero. (2) Both bulk values rise with the proportion of type A, so changing composition supplies a shared source of variation. (3) The raw correlation is \(0.8485\) and the residual correlation is 0; in this constructed example, the fitted linear quality pattern accounts for the raw association. (4) No. Batch and condition are perfectly confounded in the observed design, so their separate effects are not identifiable from these data alone.