Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Outlier Counts and Robust Gene-Level Inference

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

Outlier Counts and Robust Gene-Level Inference

Learn to distinguish a genuinely unusual count from a technical or modeled difference, and assess how outlier handling changes gene-level estimates and tests.

Advanced 10 min read

What You'll Learn

  • Define count outliers relative to fitted means, offsets, and dispersion.
  • Use residuals and influence checks to investigate unusually large counts.
  • Compare exclusion, downweighting, robust fitting, and ordinary inference.
  • Calculate how outlier handling can change a gene-level contrast and test.
  • Distinguish robust coefficient estimation from robust standard errors.
  • Report sensitivity and limitations without treating an outlier flag as proof of error.

Why a Large Count Needs Context

In pseudobulk differential expression, a gene’s count is recorded for each biological sample, such as a donor-condition combination. A count can look large in isolation yet be entirely plausible given the sample’s library size, the gene’s expected expression, and the gene’s variability across samples. Conversely, a count that is not the largest in the table can be surprising under the fitted model and substantially affect a gene-level comparison.

The relevant question is therefore not simply whether a count is numerically high. It is whether it is unusually high relative to a suitable model, and whether it has enough influence to alter an estimate or its uncertainty. A flagged count is a diagnostic signal to investigate, not evidence by itself that the observation is erroneous or should be removed.

Definition: A gene-level count outlier is a sample’s observed count for a gene that is unusually far from the count expected under the fitted gene-level model, after accounting for modeled sample factors and the gene’s dispersion. An influential count is one whose presence has a substantial effect on an estimated coefficient, standard error, or test result. A count can be unusual without being influential, or influential without being an obvious extreme in the raw count table.

A Model-Based Reference for Counts

A common starting point for pseudobulk counts is a negative binomial generalized linear model, fitted separately for each gene. Let \(Y_{gj}\) be the count for gene \(g\) in biological sample \(j\), \(s_j\) a sample-specific size factor, and \(\mathbf{x}_j\) the row of the design matrix. One parameterization is

$$ Y_{gj}\sim \operatorname{NB}(\mu_{gj},\alpha_g),\qquad \log(\mu_{gj})=\log(s_j)+\mathbf{x}_j^\mathsf{T}\boldsymbol{\beta}_g,\qquad \operatorname{Var}(Y_{gj})=\mu_{gj}+\alpha_g\mu_{gj}^{2}. $$

Here \(\mu_{gj}\) is the fitted mean, \(\alpha_g\) is the gene-specific dispersion, and \(\log(s_j)\) is an offset. The design encodes the comparison and any appropriate covariates. The model assumes that the conditional mean structure and dispersion adequately describe the counts, that the offset is appropriate, and that biological samples are independent conditional on the model (or that their dependence is handled by the specified model). A misspecified design, an inadequate mean-variance relationship, or unmodeled dependence can make outlier diagnostics misleading.

A simple diagnostic is the Pearson residual:

$$ r_{gj}=\frac{Y_{gj}-\widehat{\mu}_{gj}} {\sqrt{\widehat{\mu}_{gj}+\widehat{\alpha}_g\widehat{\mu}_{gj}^{2}}}. $$

This scales the difference between observed and fitted count by the model’s estimated standard deviation. A large positive residual indicates a count above the fitted mean relative to the expected variability. It is a diagnostic, not a formal outlier test with a universal cutoff: parameters were estimated from the data, and leverage, small sample size, and dispersion estimation affect the residual’s behavior. Examine residuals alongside fitted values, sample quality, design, and influence measures rather than applying one threshold mechanically.

Worked Example: Scaling a High Count by Model Variability

Suppose a hypothetical gene has a fitted mean of 100 counts in one pseudobulk sample and estimated dispersion \(\widehat{\alpha}=0.10\). The observed count is 220. Calculate its Pearson residual and explain what it indicates.

The model variance is \(100+0.10(100)^2=100+1{,}000=1{,}100\), so the model standard deviation is \(\sqrt{1{,}100}\approx33.17\) counts. Thus

$$ r=\frac{220-100}{\sqrt{1{,}100}} =\frac{120}{33.17}\approx3.62. $$

The count is about 3.62 model standard deviations above its fitted mean, which warrants investigation. It does not establish that the count is an error: a genuine biological response, a sample-specific technical issue, or an inadequate model could each produce this pattern. The model’s mean and dispersion assumptions should be checked before deciding how to handle it.

From a Flag to an Inference Decision

A useful investigation proceeds in stages. First verify the observation: check count generation, sample identity, library size, cell-type assignment, and relevant quality-control information. Then ask whether the fitted mean and dispersion are credible for that gene and design. A condition-specific pattern may be real and should not be “corrected” just because it is large. Finally, assess influence by comparing the gene-level estimate and test with and without the observation, or by using a fitting method that limits the influence of extreme residuals.

The main handling choices have different meanings:

  • Retain the count and use the ordinary model. This is appropriate when the count is plausible and the model is adequate. It preserves the observation but may leave inference sensitive to an extreme value.
  • Exclude a sample. Exclusion may be justified by a documented sample-level failure, not merely because removing the sample improves a p-value. It reduces information and can change the target population or design balance.
  • Downweight or robustly fit the gene model. A robust coefficient procedure limits how strongly large residuals affect estimation. Its weighting rule and assumptions matter; robust fitting is not a license to ignore sample quality or model misspecification.
  • Use an outlier replacement procedure, if appropriate and pre-specified. Replacement changes the data entering the test and requires a method that accounts for the replacement in its inferential procedure. Ad hoc substitution with a convenient value generally does not provide valid uncertainty or testing.
  • Report a sensitivity analysis. Show whether the estimated effect and conclusion are stable under defensible alternatives. A sensitivity result complements, rather than replaces, the primary analysis rationale.

Robust standard errors are not the same as robust coefficient estimation. A sandwich-type standard error can protect uncertainty estimates against some forms of variance misspecification, but it does not necessarily stop an extreme count from pulling the fitted coefficient. Conversely, robust coefficient estimation changes the way observations contribute to the estimate; its standard error and test must be calculated for that procedure. State which quantity is robust.

Worked Example: How a Large Count Changes a Fitted Contrast

In a hypothetical gene analysis, an ordinary fit gives a control normalized fitted mean of 95 and a treated mean of 232.4. A robust fit, which limits the contribution of one unusually large treated count, gives fitted means of 95 and 110. Calculate the log-base-2 contrasts and describe the change. These fitted means are illustrative outputs, not raw counts.

For the ordinary fit, the treated-to-control contrast is \(\log_2(232.4/95)=\log_2(2.446)\approx1.291\) log-base-2 units. For the robust fit, it is

$$ \log_2\left(\frac{110}{95}\right) =\log_2(1.1579)\approx0.2115. $$

The estimated contrast changes from about 1.291 to 0.2115 log-base-2 units. The ordinary fit suggests a larger treated mean relative to control; the robust fit suggests a smaller positive difference. This illustrates how a count can materially affect an estimate. It does not establish that the robust result is the truth: the observation’s provenance, the model assumptions, and the method’s suitability still need assessment. The contrast is a relative expression effect, not evidence that treatment caused the observed difference.

Effects on Tests, Diagnostics, and Interpretation

For a gene-level test of a coefficient \(\beta_g\), a Wald statistic is often formed as \(\widehat{\beta}_g/SE(\widehat{\beta}_g)\), with a reference distribution appropriate to the model and inferential method. An influential count can change the coefficient, its standard error, or both. Consequently, the test statistic and p-value may change even if the underlying biological pattern has not. A small p-value from one fit does not validate the model or prove that a flagged count is a measurement error.

Worked Example: Comparing Gene-Level Tests

Suppose an ordinary fit for a hypothetical gene estimates a log-base-2 condition effect of 0.80 with standard error 0.30. A robust coefficient fit estimates 0.35 with standard error 0.25. For illustration, use two-sided standard normal Wald tests of \(H_0:\beta_g=0\). Calculate each statistic and approximate p-value.

For the ordinary fit, \(z=0.80/0.30=2.667\), giving a two-sided standard-normal p-value of approximately 0.0077. For the robust fit, \(z=0.35/0.25=1.40\), with a two-sided p-value of approximately 0.162. Under this illustrative approximation, the ordinary fit is inconsistent with the null at \(\alpha=0.05\), while the robust fit is not. The result is not a claim that the null is true; it shows that the evidence under these two fits differs. In real analyses, use the reference distribution and degrees of freedom prescribed by the fitted model, rather than assuming a normal approximation automatically.

Diagnostics should be interpreted together. A large positive residual may arise from a bad offset, a missing covariate, an incorrect condition label, an influential sample, or a genuinely unusual biological response. A dispersion that is too small can make many counts appear extreme; an incorrect mean structure can make residuals systematically positive in one group. Examine residual patterns across samples and genes, compare fitted and observed counts, and assess whether the flagged sample has broader quality concerns. The earlier material on residual diagnostics, dispersion fit, and donor-sample influence provides relevant complementary checks.

No single outlier rule is universal. A residual cutoff does not account in a simple way for all genes and samples being examined, and a gene selected because it has the most extreme residual is subject to selection. With few biological replicates, one observation can dominate an estimate, while the data provide limited ability to distinguish a true sample-specific response from an anomaly. Robust procedures can reduce sensitivity, but may sacrifice efficiency when the ordinary model is correct and may not protect against design errors or systematic bias.

Key takeaway: Define an outlier relative to a fitted count model, investigate its cause, and assess its influence on the gene-level estimate and uncertainty. Do not remove or replace a count solely because it is large or because its removal produces a preferred result.

Common Pitfall: Treating “Large” as “Wrong”

Incorrect reasoning: “This is the largest count in the table, so it must be an error; I will remove it and report the smaller p-value.” This confuses raw magnitude with model-based surprise, ignores the possibility of a real effect, and makes inference depend on a post hoc decision.

Correction: Compare the count with its fitted mean and dispersion, verify sample and design information, and evaluate how the estimate and test change under defensible procedures. If there is independent evidence of a technical failure, document the exclusion rule and its consequences. Otherwise, retain the observation in the primary analysis or use a justified robust procedure, and report sensitivity when the result depends on the choice.

Check Your Understanding

Answer each question, then compare with the short solutions.

  1. If two samples have the same count for a gene but very different fitted means and dispersions, should that count have the same outlier interpretation in both? Why?
  2. A Pearson residual is large and positive. Name two explanations other than a data-entry error.
  3. What does a robust standard error change, and why is that different from robust coefficient estimation?
  4. A gene is significant in the ordinary fit but not after robust fitting. What is a responsible interpretation?

Solutions. (1) No. The residual compares the count with the fitted mean relative to model variability, both of which can differ between samples. (2) A genuine sample-specific biological response or a misspecified mean, offset, or dispersion are possible explanations, among others. (3) A robust standard error adjusts uncertainty under certain variance misspecifications; robust coefficient estimation limits how strongly observations affect the estimated effect. One does not automatically accomplish the other’s task. (4) The result is sensitive to the fitting procedure, so investigate the flagged observation and model assumptions, report the estimates and methods transparently, and avoid claiming either fit proves the null or the alternative.

Clinical Biostats