Algorithm Search⌘K

Modelcore

Negative binomial model for read counts

Also called negative binomial GLM for RNA-seq.

Model the count of a gene as negative binomial with a mean from a log-linear model of the design and a gene-wise dispersion.

The negative binomial model for read counts says that the count KgjK_{gj} of gene gg in sample jj has a negative binomial distribution with mean μgj\mu_{gj} and dispersion αg\alpha_g, so that Var⁡(Kgj)=μgj+αgμgj2\operatorname{Var}(K_{gj}) = \mu_{gj} + \alpha_g\mu_{gj}^2. The mean is the size factor of the sample times the expression of the gene, and the log of the expression is a linear function of the design, as in a generalized linear model. The term μ\mu is the Poisson noise of sampling reads, and the term αμ2\alpha\mu^2 is the extra variation between biological replicates. Robinson and Smyth (2007) used this model for tag counts, and it is the model of edgeR and DESeq2. It is the model behind differential expression analysis of RNA-seq counts; with few replicates the dispersion is estimated by dispersion shrinkage. The moderated t-statistic is the other main route: it works on log counts with a normal model instead of on the counts.

The machine

Data. A matrix of counts Kgj≥0K_{gj} \ge 0 for genes g=1,…,ng = 1, \dots, n and samples j=1,…,mj = 1, \dots, m, and a design matrix XX with one row xjx_j per sample and pp columns (an intercept, the condition, a batch, and so on). The counts are the raw numbers of reads or fragments assigned to the gene, not normalized values.

Distribution. Given the parameters, the counts are independent and

Kgj∼NB⁡(μgj,αg),P(K=k)=Γ(k+1/α)Γ(1/α) k!(11+αμ)1/α(αμ1+αμ)k,k=0,1,2,…K_{gj} \sim \operatorname{NB}(\mu_{gj}, \alpha_g), \qquad P(K = k) = \frac{\Gamma(k + 1/\alpha)}{\Gamma(1/\alpha)\,k!}\left(\frac{1}{1 + \alpha\mu}\right)^{1/\alpha}\left(\frac{\alpha\mu}{1 + \alpha\mu}\right)^k, \quad k = 0, 1, 2, \dots

With r=1/αr = 1/\alpha this is the negative binomial law with size rr and success probability r/(r+μ)r/(r + \mu).

Mean. μgj=sjqgj\mu_{gj} = s_jq_{gj}, with log⁡2qgj=xj⊤βg\log_2 q_{gj} = x_j^\top\beta_g. The size factors sjs_j come from library size normalization and are fixed, so ln⁡sj\ln s_j is an offset. The coefficients βg\beta_g are log2 fold changes: for a design with an intercept and a 0 or 1 indicator of the treatment, βg1\beta_{g1} is the log2 ratio of the expression in the treated group to that in the control group.

Dispersion. αg≥0\alpha_g \ge 0 is the same for all samples of a gene. It has no unit. Its square root is the biological coefficient of variation (BCV): the coefficient of variation that the true expression would have between replicates if the depth were infinite.

Standing assumptions. The samples are independent. The design captures every systematic difference between them. The size factors are known. The dispersion does not depend on the condition. The model does not describe reads that map to many genes, and it does not by itself model excess zeros.

The gamma-Poisson mixture. The model is what one gets from two stages. The true expression of the gene in the sample is λ∼Gamma⁡(shape 1/α,scale αμ)\lambda \sim \operatorname{Gamma}(\text{shape } 1/\alpha, \text{scale } \alpha\mu), with mean μ\mu and variance αμ2\alpha\mu^2. Given λ\lambda, the count is Poisson with mean λ\lambda. Integrating over λ\lambda gives the negative binomial law above.

What it counts

The model gives the probability of each count, and so a likelihood for the parameters of each gene:

ℓg(β,α)=∑j=1m[ln⁡Γ(kj+r)−ln⁡Γ(r)−ln⁡kj!+rln⁡rr+μj+kjln⁡μjr+μj],r=1/α.\ell_g(\beta, \alpha) = \sum_{j=1}^m \left[\ln\Gamma(k_j + r) - \ln\Gamma(r) - \ln k_j! + r\ln\frac{r}{r + \mu_j} + k_j\ln\frac{\mu_j}{r + \mu_j}\right], \quad r = 1/\alpha.

From it come the maximum likelihood estimates β^g\hat\beta_g, their standard errors, the Wald test of DESeq2 and the likelihood ratio test of a reduced design. It also predicts the spread of counts: the squared coefficient of variation of a count is

Var⁡(K)μ2=1μ+α,\frac{\operatorname{Var}(K)}{\mu^2} = \frac1\mu + \alpha,

the sum of a technical part that falls with depth and a biological part that does not.

A worked case. For μ=100\mu = 100 and α=0.1\alpha = 0.1, the variance is 100+0.1⋅1002=1100100 + 0.1 \cdot 100^2 = 1100 and the standard deviation is 33.2, against 10 for a Poisson count with the same mean. The BCV is 0.1=0.32\sqrt{0.1} = 0.32, so the true expression varies by about 32 percent between replicates. Sequencing ten times as deeply, with μ=1000\mu = 1000, lowers the squared coefficient of variation only from 0.11 to 0.101. More replicates help; more depth beyond this point helps little.

Small values by hand. For μ=2\mu = 2 and α=0.5\alpha = 0.5, the size is r=2r = 2 and the success probability is 1/21/2, so P(K=k)=(k+1)/2k+2P(K = k) = (k + 1)/2^{k+2}: P(0)=0.25P(0) = 0.25, P(1)=0.25P(1) = 0.25, P(2)=0.1875P(2) = 0.1875. The Poisson law with mean 2 gives P(0)=0.135P(0) = 0.135. The negative binomial law puts more mass at 0 and in the tail.

Relation to other models

  • Poisson distribution. The case α=0\alpha = 0. Counts from technical replicates of the same library are close to Poisson. Biological replicates are not, and a Poisson test on them finds far too many changes.
  • Generalized linear model. For a fixed α\alpha, the negative binomial law is an exponential family in μ\mu, so the model is a GLM with a log link and an offset, and it is fitted by iteratively reweighted least squares. The log link is not the canonical link of this family.
  • Normal model on log counts. limma-voom models log⁡2\log_2 counts per million as normal, with precision weights from the trend of the variance against the mean, and then uses the moderated t-statistic. In published benchmarks the two routes give similar results; voom is faster and allows the tools of linear models.
  • Quasi-likelihood. edgeR also fits a quasi-negative binomial model, in which a second, gene-wise factor multiplies the variance and is shrunk by empirical Bayes. Its tests keep the error rate closer to the nominal level when the dispersion is uncertain.
  • Zero-inflated models. For single-cell data, some authors add a point mass at 0. For UMI counts, several studies report that the plain negative binomial model fits well without it. This is a measurement on data, not a result of the model.
  • Beta-binomial model. For counts of two kinds of reads at one site, such as allele-specific expression, the analogue of the gamma-Poisson mixture is a beta-binomial mixture.

Known results in the model

Mean and variance. E[K]=μE[K] = \mu and Var⁡(K)=μ+αμ2\operatorname{Var}(K) = \mu + \alpha\mu^2.

Proof. With λ\lambda gamma and K∣λK \mid \lambda Poisson, E[K]=E[λ]=μE[K] = E[\lambda] = \mu. By the law of total variance, Var⁡(K)=E[Var⁡(K∣λ)]+Var⁡(E[K∣λ])=E[λ]+Var⁡(λ)=μ+αμ2\operatorname{Var}(K) = E[\operatorname{Var}(K \mid \lambda)] + \operatorname{Var}(E[K \mid \lambda]) = E[\lambda] + \operatorname{Var}(\lambda) = \mu + \alpha\mu^2. □\square

Concave in the coefficients. For a fixed α\alpha, ℓg\ell_g is a concave function of βg\beta_g. If XX has full column rank and μj>0\mu_j > 0, it is strictly concave, so any stationary point is the unique maximum.

Proof. Write ηj=ln⁡μj=ln⁡sj+(ln⁡2)xj⊤β\eta_j = \ln\mu_j = \ln s_j + (\ln 2)x_j^\top\beta, which is affine in β\beta. As a function of ηj\eta_j, the term of sample jj is kjηj−(kj+r)ln⁡(r+eηj)k_j\eta_j - (k_j + r)\ln(r + e^{\eta_j}) plus a constant. Its second derivative is −(kj+r)reηj/(r+eηj)2<0-(k_j + r)re^{\eta_j}/(r + e^{\eta_j})^2 < 0. A concave function of an affine map is concave, and a sum of concave functions is concave. With full column rank, the Hessian −(ln⁡2)2X⊤DX-(\ln 2)^2X^\top DX, with DD diagonal and positive, is negative definite. □\square

So IRLS, which is Fisher scoring for this model, has only one maximum to find. It can still fail to converge without step control when some counts are 0 and β^\hat\beta goes to infinity, as when a gene has no reads in one group.

Fisher information. For a fixed α\alpha, the expected information for β\beta (in natural log units) is X⊤WXX^\top WX with wj=μj/(1+αμj)w_j = \mu_j/(1 + \alpha\mu_j).

Proof. The score of ηj\eta_j is kj−(kj+r)μj/(r+μj)=r(kj−μj)/(r+μj)=(kj−μj)/(1+αμj)k_j - (k_j + r)\mu_j/(r + \mu_j) = r(k_j - \mu_j)/(r + \mu_j) = (k_j - \mu_j)/(1 + \alpha\mu_j). Its variance is Var⁡(Kj)/(1+αμj)2=μj/(1+αμj)\operatorname{Var}(K_j)/(1 + \alpha\mu_j)^2 = \mu_j/(1 + \alpha\mu_j). The chain rule through the affine map gives X⊤WXX^\top WX, times (ln⁡2)2(\ln 2)^2 for log2 units. □\square

The weight wjw_j tends to 1/α1/\alpha as μj\mu_j grows: beyond a certain depth a sample gives no more information about the fold change, because the biological variation dominates. This is the formal form of the worked case above.

Two groups with equal size factors. If all sjs_j are equal to ss and the design is one mean per group, the maximum likelihood estimate of the mean of a group is kˉ/s\bar k/s, the mean count of the group divided by ss, for any fixed α\alpha. This follows by setting the score ∑j(kj−μ)/(1+αμ)\sum_j (k_j - \mu)/(1 + \alpha\mu) to 0. With unequal size factors there is no closed form, and IRLS is used.

Exact test. For two groups with equal library sizes and a known α\alpha, the sum of the counts of a group of cc samples is negative binomial with mean cμc\mu and size c/αc/\alpha. Robinson and Smyth (2008) build an exact test from the conditional law of one group's sum given the total. It removes the unknown common mean by conditioning, in the same way as the Fisher exact test conditions on the margins of a table. edgeR uses it after it adjusts the counts to equal library sizes.

Estimating the dispersion. The maximum likelihood estimate of α\alpha is biased downward with few replicates, because it ignores the degrees of freedom used by β\beta. The Cox-Reid adjusted profile likelihood, used by edgeR and DESeq2, corrects for this (McCarthy, Chen and Smyth 2012). With 2 or 3 replicates per group, a gene-wise estimate is still very noisy, which is why dispersion shrinkage borrows information across genes.

References

  1. Mark D. Robinson and Gordon K. Smyth, Moderated statistical tests for assessing differences in tag abundance, Bioinformatics 23(21) (2007), pages 2881 to 2887, the negative binomial model for tag counts with the variance mu + phi mu^2, and the weighted likelihood that moderates the dispersion
  2. Mark D. Robinson and Gordon K. Smyth, Small-sample estimation of negative binomial dispersion, with applications to SAGE data, Biostatistics 9(2) (2008), pages 321 to 332, the conditional maximum likelihood estimate of the dispersion and the exact test for two groups
  3. Simon Anders and Wolfgang Huber, Differential expression analysis for sequence count data, Genome Biology 11(10) (2010), article R106, the negative binomial model with size factors and a variance that is a smooth function of the mean
  4. Davis J. McCarthy, Yunshun Chen and Gordon K. Smyth, Differential expression analysis of multifactor RNA-Seq experiments with respect to biological variation, Nucleic Acids Research 40(10) (2012), pages 4288 to 4297, the negative binomial GLM with a design matrix and offsets, the biological coefficient of variation, and the Cox-Reid adjusted profile likelihood for the dispersion
  5. Michael I. Love, Wolfgang Huber and Simon Anders, Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2, Genome Biology 15(12) (2014), article 550, the model K_ij ~ NB(mu_ij, alpha_i) with mu_ij = s_j q_ij and log2 q_ij = x_j beta_i, and the Wald test

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/2AJH92/text.yaml