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.

Gamma-Poisson GLM

Introduction

The Gamma-Poisson (or Negative Binomial) distribution is a suitable model to describe variation accurately in count matrices of single-cell RNA-sequencing (scRNA-seq) data in both theory and practice Ahlmann-Eltze & Huber, 2021. It plays an essential role in normalizing count data in the SCTransform process before performing downstream analyses, such as principal component analysis (PCA) or clustering.

Although several packages implement this framework, glmGamPoi offers an outstanding and robust performance Ahlmann-Eltze & Huber, 2021.

Workflow

Overall, this workflow fits a raw count matrix to a Negative Binomial (NB) distribution. The primary target is to determine the model coefficients: β\beta, which represented as the log-scaled expected mean counts; and the dispersion parameter (θ\theta) for each gene.

The workflow begins with an initial rough dispersion estimation, followed by estimating the model coefficients β\beta using the Maximum Likelihood method. After fixing β\beta, the maximum likelihood estimation of θ\theta is conducted. These gene-specific dispersion estimates are then stabilized via a shrinkage process.

Rough dispersion estimation

{ξ=(1Nj=1Nexp(oj))1θ^i=max(var(Ci)ξmean(Ci)mean(Ci)2,0)\begin{cases} \begin{aligned} \xi &= \left( \frac{1}{N}\sum_{j=1}^{N}{\exp(o_j)} \right)^{-1} \\ \widehat{\theta}_{i} &= \max \left(\frac{var(C_i) - \xi mean(C_i)}{mean(C_i)^2}, 0 \right) \end{aligned} \end{cases}

Initially, a rough estimate of the dispersion for gene ii (θ^i\widehat{\theta}_{i}) is computed using Equation (1). Here, ξ\xi is an offset correction factor, defined as the reciprocal of the average exponentiated offset (ojo_j) across all NN samples. Since the offset in this context is the natural logarithm of the total counts for each sample, ξ=(C)1\xi = (\overline{C})^{-1}, where C\overline{C} is the mean total count across samples.

The rough dispersion estimator is derived from the mean–variance relationship of the Gamma-Poisson distribution (σ2=μ+θμ2\sigma^2 = \mu + \theta \mu^2) Ahlmann-Eltze & Huber, 2021, adjusted by the factor ξ\xi and constrained to be non-negative.

Here, CiC_i denotes the vector of counts for gene ii, while var()var() and mean()mean() represent the variance and mean functions, respectively.

Beta estimation

{NCij=Cijk=1MCkjβi^=ln(mean(NCi))\begin{cases} \begin{aligned} NC_{ij} &= \frac{C_{ij}}{\sum_{k=1}^{M}{C_{kj}}} \\ \widehat{\beta_i} &= \ln(mean(NC_i)) \end{aligned} \end{cases}

At the beginning, rough beta of each gene (βi\beta_i) is estimated by Equation (2), defined as the logarithm of the gene-oriented mean of normalised counts (NCijNC_{ij}), which are proportion of count on total counts of each sample (MM is the number of genes).

βi(n+1)=βi(n)+dli(βi)dli(βi)\beta_i^{(n+1)} = \beta_i^{(n)} + \frac{dl_{i}(\beta_i)}{dl'_{i}(\beta_i)}

Beta is estimated using the Newton-Raphson method Akram & Ann, 2015, which iterates Equation (3) until the value of beta converges. dlidl_{i} is the derivative of likelihood function that count values of gene ii is of Negative Binomial (NB) distribution.

{μij=exp(βi+oj)dli(βi)=k=1NCikμik1+μikθidli(βi)=k=1Nμik(1+Cikθi)(1+μikθi)2\begin{cases} \begin{aligned} \mu_{ij} &= \exp(\beta_i + o_j) \\ dl_{i}(\beta_i) &= \sum_{k=1}^{N}{\frac{C_{ik}-\mu_{ik}}{1 + \mu_{ik} \theta_i}} \\ dl'_{i}(\beta_i) &= - \sum_{k=1}^{N}{\frac{\mu_{ik}(1+C_{ik}\theta_i)}{(1 + \mu_{ik} \theta_i)^2}} \end{aligned} \end{cases}

Starting with an initial rough estimate of βi\beta_i for gene ii, the sample-specific expected count μij\mu_{ij} is updated in each iteration nn by combining the biological parameter (βi\beta_i) and technical sampling offset (ojo_j). Even though μ\mu represents the theoretical mean of the NB distribution, incorporating these sample-specific offsets allows the model to account for variation in sequencing depth across the samples. This helps strip away library-size biases while computing the log-likelihood function and its derivative according to Equation (4).

Overdispersion (theta) estimation

Hence using the likelihood function l(μ,θ)l(\mu,\theta) to model NB distribution for each gene, the overdispersion parameter θ\theta is estimated after determination of β\beta derived from μ\mu. The vector of mean count μi\mu_i of gene ii is deduced via the equation in (4), which stands for constant count mean across NN samples during optimizing θ\theta.

l(θ)=k=1N[lnΓ(Ck+θ1)lnΓ(θ1)(Ck+θ1)ln(μk+θ1)1θln(θ)]l(\theta) = \sum_{k=1}^{N}{ \left[ \ln\Gamma(C_k + \theta^{-1}) - \ln\Gamma(\theta^{-1}) - \left( C_k +\theta^{-1} \right)\ln(\mu_k+\theta^{-1}) - \frac{1}{\theta} \ln(\theta) \right] }

The likelihood function l(θ)l(\theta) presented in Equation (10) is derived from general likelihood function of NB distribution (7). Here the factorial components in the combination term is substituted with Gamma functions to generalize the domain to continuous real numbers (R\mathbb{R}), while any additive terms independent of θ\theta are omitted.

dldθ=1θ[k=1N(1θ(ψ(Ck+θ1)ψ(θ1))+ln(1+μkθ)+Ckμkμk+θ1)]\frac{d l}{d \theta} = \frac{1}{\theta} \left[ \sum_{k=1}^{N}{ \left( -\frac{1}{\theta} \left( \psi(C_k + \theta^{-1}) - \psi(\theta^{-1}) \right) + \ln(1+\mu_k\theta) + \frac{C_k - \mu_k}{\mu_k + \theta^{-1}} \right) } \right]

To maximize the log-likelihood function, we first compute its derivative with respect to θ\theta, as shown in Equation (11), where ψ(x)\psi(x) denotes the digamma function (the first derivative of lnΓ(x)\ln\Gamma(x)).

1θk=1N(ψ(Ck+θ1)ψ(θ1))D(θ)+k=1N(ln(1+μkθ)+Ckμkμk+θ1)L(θ)=0- \underbrace{\frac{1}{\theta}\sum_{k=1}^{N}{ \left( \psi(C_k + \theta^{-1}) - \psi(\theta^{-1}) \right) } }_{D(\theta)} + \underbrace{\sum_{k=1}^{N}{ \left( \ln(1+\mu_k\theta) + \frac{C_k - \mu_k}{\mu_k + \theta^{-1}} \right) } }_{L(\theta)} = 0

Setting dl/dθ=0dl/d\theta = 0 yields the root-finding problem in Equation (12), which can be separated into two distinct components. The first part, D(θ)D(\theta), accounts for the digamma terms and involves intensive computation. To eliminate redundant calculations for identical count values, glmGamPoi optimizes this step by utilizing a count frequency table Ahlmann-Eltze & Huber, 2021. Meanwhile, the remaining log-mean component, L(θ)L(\theta), is more straightforward to compute.

G(θ)=L(θ)D(θ)G(\theta) = L(\theta) - D(\theta)

Structurally, the gradient G(θ)G(\theta) defined in Equation (13) governs the direction of the variation of θ\theta. When G(θ)>0G(\theta) > 0, the log-likelihood slope is positive, indicating that θ\theta must be increased. Conversely, when G(θ)<0G(\theta) < 0, the slope is negative, meaning θ\theta must be decreased. A state of G(θ)=0G(\theta) = 0 indicates that the log-likelihood has reached a local extremum.

To verify whether this stationary point corresponds to a local maximum or minimum. The second-derivative of the gradient is tested, if d2G/dθ2<0d^{2}G/d\theta^2 < 0, the curvature is concave down, confirming that the extremum is a local maximum representing the Maximum Likelihood Estimate (MLE) of θ\theta.

Shrinkage

Even though NB distribution is able to obtain flexible variance-mean relationship, it is proved virtually being uncertainty in parameter estimation. Quasi-likelihood (QL) comes as a solution to adjust dispersion Lund et al., 2012. The variance-mean equation of quasi-distribution by genes is shown as (16).

σ2=θQL(μ+μ2θtrend)\sigma^2 = \theta_{QL}(\mu + \mu^2\theta_{\text{trend}})

Initially, the trend dispersion (θtrend\theta_{\text{trend}}) is derived from the vector of likelihood estimated dispersion (exp(1/θML)\exp(1/\theta_{\text{ML}})), which is performed local median regression to stablize dispersion. Specifically, the dispersion according to each mean count value (μi\mu_i) would be performed weighted median Cormen et al., 2022 with neighbors (sorted by mean, analyzing 100 neighbors by default), where the weight range originates from the range of probability in the domain [3,3][-3,3] of standard normal distribution.

θQL=1+μθML1+μθtrend\theta_{QL} = \frac{1+\mu\theta_{\text{ML}}}{1+\mu\theta_{\text{trend}}}

θQL\theta_{QL} is defined by (17), which derived from (16) and mean-variance equation of NB distribution, where likelihood dispersion θML\theta_{\text{ML}} was smoothed into θtrend\theta_{\text{trend}}.

θSQL=df0τ02+dfθQLdf0+df\theta_{SQL} = \frac{\text{df}_0\tau^2_0 + \text{df}\theta_{QL}}{\text{df}_0 + \text{df}}

The shrunken quasi-likelihood overdispersion (θSQL\theta_{SQL}) for each gene is estimated by Equation (18). Particularly, df\text{df} is the residual degree of freedom - DOF (#samples1\text{\#samples} - 1), while df0\text{df}_0 and τ02\tau^2_0 are prior parameters representing DOF and dispersion scaler respectively. These prior parameters are estimated by modeling the θQL\theta_{QL} values using a scaled Chi-squared distribution via a natural cubic spline framework. The process successfully yields a theoretical pseudo-sample size (df0\text{df}_0) and a denoised central dispersion trend (τ02\tau_0^2). Ultimately, the resulting θSQL\theta_{SQL} reflects the true amount of informative dispersion captured from the data.

Under the intercept-only model (~1), all samples are treated as a single group. The coefficient vector β\beta is re-estimated using the trend dispersion (θtrend\theta_\text{trend}), which is then used to recalculate the expected mean counts.

Summary

The Gamma-Poisson model is a good fit for overdispersed scRNA-seq data. Ultimately, the function glm_gp() of the glmGamPoi package, which models NB distribution, targets essential regression coefficients (relative log-scaled count mean β\beta and overdispersion θ\theta), by maximizing their likelihood estimations.

References
  1. Ahlmann-Eltze, C., & Huber, W. (2021). glmGamPoi: Fitting Gamma-Poisson Generalized Linear Models on Single Cell Count Data. Bioinformatics, 36(24), 5701–5702. 10.1093/bioinformatics/btaa1009
  2. Akram, S., & Ann, Q. U. (2015). Newton raphson method. International Journal of Scientific & Engineering Research, 6(7), 1748–1752.
  3. Sinharay, S. (2010). Discrete Probability Distributions. In International Encyclopedia of Education (pp. 132–134). Elsevier. 10.1016/B978-0-08-044894-7.01721-8
  4. Cox, D. R., & Reid, N. (1987). Parameter Orthogonality and Approximate Conditional Inference. Journal of the Royal Statistical Society Series B: Statistical Methodology, 49(1), 1–18. 10.1111/j.2517-6161.1987.tb01422.x
  5. 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
  6. 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). 10.1515/1544-6115.1826
  7. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2022). Introduction to algorithms. MIT press.