Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Count models

limma models log counts; edgeR and DESeq2 model the counts themselves, with a negative binomial distribution whose variance grows with the mean. CytePool implements edgeR 4’s quasi-likelihood pipeline and DESeq2’s analysis, each checked against the R package on the same data.

Normalization

Counts depend on how deeply each sample was sequenced and on its composition: a few very highly expressed genes in one sample take reads from all others. Two corrections are standard. edgeR multiplies each library size by a normalization factor, from the trimmed mean of M values (tmm_factors; Robinson & Oshlack (2010)), the upper quartile (upper_quartile_factors; Bullard et al. (2010)) or the relative log expression (rle_factors; Anders & Huber (2010)). DESeq2 replaces library sizes by size factors, the median of each sample’s ratios to the geometric mean of every gene (median_ratio_size_factors; Anders & Huber (2010)). cpm and log_cpm give counts per million, and filter_by_expression keeps genes with enough counts in enough samples for the design Chen et al., 2016.

The negative binomial model

For the count ygiy_{gi} of gene gg in sample ii,

ygi∼NB⁡(μgi,ϕgi),var⁡(ygi)=μgi+ϕgiμgi2,log⁡μgi=xi′βg+ogi,y_{gi} \sim \operatorname{NB}(\mu_{gi}, \phi_{gi}), \qquad \operatorname{var}(y_{gi}) = \mu_{gi} + \phi_{gi} \mu_{gi}^2, \qquad \log \mu_{gi} = x_i' \beta_g + o_{gi},

with ϕ\phi the dispersion and the offset ogio_{gi} usually the log of the effective library size McCarthy et al., 2012. ϕ\sqrt{\phi} is the biological coefficient of variation. The coefficients minimize the deviance

Dg=∑iwgi d(ygi,μgi,ϕgi),d(y,μ,ϕ)=2[ylog⁡yμ−(y+1ϕ)log⁡1+ϕy1+ϕμ],D_g = \sum_i w_{gi}\, d(y_{gi}, \mu_{gi}, \phi_{gi}), \qquad d(y, \mu, \phi) = 2\left[y \log\frac{y}{\mu} - \left(y + \frac{1}{\phi}\right) \log\frac{1 + \phi y}{1 + \phi \mu}\right],

which fit_negative_binomial_model finds for every gene, as edgeR’s glmFit does (NegativeBinomialFit), and which negative_binomial_deviance and negative_binomial_unit_deviance compute exactly Dunn & Smyth, 2018.

edgeR’s quasi-likelihood F-tests

The quasi-likelihood model gives each gene a second, gene-wise dispersion σg2\sigma_g^2 on top of a negative binomial dispersion ϕ\phi shared by all genes Lund et al., 2012:

var⁡(ygi)=σg2(μgi+ϕμgi2).\operatorname{var}(y_{gi}) = \sigma_g^2 (\mu_{gi} + \phi \mu_{gi}^2).

fit_quasi_likelihood follows edgeR 4’s defaults Chen et al., 2025:

  1. ϕ\phi is the Cox-Reid common dispersion of the most highly expressed genes (common_dispersion): the maximum over ϕ\phi of the summed adjusted profile log-likelihoods ℓg(ϕ)−12log⁡det⁡(X′WgX)\ell_g(\phi) - \tfrac{1}{2}\log\det(X' W_g X) Cox & Reid, 1987McCarthy et al., 2012.

  2. Each gene’s quasi-dispersion is its deviance over its residual degrees of freedom, both adjusted for small counts: each unit deviance is approximated by a scaled chi-squared variable with the exact mean and variance of the unit deviance (negative_binomial_unit_deviance_moments, which gives UnitDevianceMoments), where edgeR approximates them.

  3. The quasi-dispersions are moderated by empirical Bayes towards a trend in the average log CPM (average_log_cpm), with limma’s estimator for unequal degrees of freedom (Empirical Bayes moderation).

The fit is a QuasiLikelihoodFit. quasi_likelihood_f_test fits the model without the tested coefficients or contrasts, and divides the likelihood ratio statistic by its degrees of freedom and by the posterior quasi-dispersion; its QuasiLikelihoodTest has edgeR’s columns: log fold change, log CPM, F, p-value and FDR. The edgeR User’s Guide (section 1.4) recommends these F-tests for bulk RNA-seq because they account for the uncertainty of the dispersion estimates, which gives stricter error rate control.

DESeq2

DESeq2 models the same distribution on the log2 scale with size factors sis_i, log⁡2μgi=log⁡2si+xi′βg\log_2 \mu_{gi} = \log_2 s_i + x_i' \beta_g, and shrinks the dispersions in four steps Love et al., 2014, which deseq2_dispersions reproduces (DESeq2Dispersions):

  1. gene-wise estimates, the maxima of the Cox-Reid adjusted likelihood;

  2. a trend in the mean normalized count mm, αtr(m)=a0+a1/m\alpha_{tr}(m) = a_0 + a_1 / m, fitted by a gamma regression;

  3. a normal prior on the log dispersions around the trend, with its variance from the spread of the gene-wise estimates;

  4. maximum a posteriori estimates, keeping the gene-wise estimate of genes far above the trend (dispersion outliers).

fit_deseq2 fits every gene at those dispersions (DESeq2Fit). deseq2_wald_test tests a coefficient or contrast cc by c′β^/c′Σcc'\hat\beta / \sqrt{c'\Sigma c} against the normal distribution; deseq2_likelihood_ratio_test tests a reduced design by the difference of the deviances against a chi-squared distribution, which tests several coefficients at once, such as every level of a factor or every time point. Both report DESeq2’s results() columns (DESeq2Results), filter genes with low mean counts before adjusting the p-values (independent filtering; Bourgon et al. (2010)) and remove the p-values of genes with an influential outlier count (Cook’s distance; Cook (1977)).

What differs from the R packages

CytePool’s fits converge to the maximum where edgeR’s and DESeq2’s stop at a tolerance, and its deviances and unit deviance moments are exact where edgeR approximates them; the differences are reported, with their sizes, on the Validation page. DESeq2’s replacement of outlier counts, shrunken fold changes (lfcShrink) and edgeR’s legacy = TRUE methods are not implemented.

References
  1. Robinson, M. D., & Oshlack, A. (2010). A scaling normalization method for differential expression analysis of RNA-seq data. Genome Biology, 11(3), R25. 10.1186/gb-2010-11-3-r25
  2. Bullard, J. H., Purdom, E., Hansen, K. D., & Dudoit, S. (2010). Evaluation of statistical methods for normalization and differential expression in mRNA-Seq experiments. BMC Bioinformatics, 11(1), 94. 10.1186/1471-2105-11-94
  3. Anders, S., & Huber, W. (2010). Differential expression analysis for sequence count data. Genome Biology, 11(10), R106. 10.1186/gb-2010-11-10-r106
  4. Chen, Y., Lun, A. T. L., & Smyth, G. K. (2016). From reads to genes to pathways: differential expression analysis of RNA-Seq experiments using Rsubread and the edgeR quasi-likelihood pipeline. F1000Research, 5, 1438. 10.12688/f1000research.8987.2
  5. McCarthy, D. J., Chen, Y., & Smyth, G. K. (2012). Differential expression analysis of multifactor RNA-Seq experiments with respect to biological variation. Nucleic Acids Research, 40(10), 4288–4297. 10.1093/nar/gks042
  6. Dunn, P. K., & Smyth, G. K. (2018). Generalized Linear Models With Examples in R. Springer. 10.1007/978-1-4419-0118-7
  7. Lund, S. P., Nettleton, D., McCarthy, D. J., & Smyth, G. K. (2012). Detecting differential expression in RNA-sequence data using quasi-likelihood with shrunken dispersion estimates. Statistical Applications in Genetics and Molecular Biology, 11(5), Article 8. 10.1515/1544-6115.1826
  8. Chen, Y., Chen, L., Lun, A. T. L., Baldoni, P. L., & Smyth, G. K. (2025). edgeR v4: powerful differential analysis of sequencing data with expanded functionality and improved support for small counts and larger datasets. Nucleic Acids Research, 53(2), gkaf018. 10.1093/nar/gkaf018
  9. Cox, D. R., & Reid, N. (1987). Parameter orthogonality and approximate conditional inference. Journal of the Royal Statistical Society: Series B (Methodological), 49(1), 1–18. 10.1111/j.2517-6161.1987.tb01422.x
  10. Love, M. I., Huber, W., & Anders, S. (2014). Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2. Genome Biology, 15(12), 550. 10.1186/s13059-014-0550-8
  11. Bourgon, R., Gentleman, R., & Huber, W. (2010). Independent filtering increases detection power for high-throughput experiments. Proceedings of the National Academy of Sciences, 107(21), 9546–9551. 10.1073/pnas.0914005107
  12. Cook, R. D. (1977). Detection of influential observation in linear regression. Technometrics, 19(1), 15–18. 10.1080/00401706.1977.10489493