Why the Count Likelihood Matters
A spatial expression analysis begins with counts: for a given gene, each spot has a nonnegative integer count, and spots can have very different library sizes. A likelihood makes explicit how a model connects those observations to expected expression. It also makes clear which differences in observed counts are attributed to library size, which to modeled expression, and which are left as random variation.
This tutorial specifies Poisson and negative-binomial likelihoods for spot-level counts. The focus is the count distribution and its library-size offset, not a model for spatial dependence. As discussed in the earlier material on separating expression changes from composition changes, a spot’s observed expression can reflect both its cellular composition and expression within cell types. A count likelihood alone does not distinguish those sources.
The exposure \(L_i\) may be a library-size measure or a normalized size factor, depending on the analysis. Its precise definition matters: the model treats it as given, and \(\exp(\eta_{ig})\) is the expected count per unit of that exposure. If the exposures are rescaled by a common constant, the fitted intercept changes to compensate; therefore, the units and normalization of \(L_i\) affect the interpretation of the rate.
The Poisson Likelihood With an Offset
The Poisson model assumes that, conditional on the modeled mean, the count in each spot follows a Poisson distribution. For a single gene, a common specification is
For example, \(\eta_{ig}=\beta_{0g}+x_i^\mathsf{T}\beta_g\), where \(x_i\) contains spot-level predictors. Conditional independence across spots is also assumed in the basic likelihood. The probability mass function and the full likelihood for the gene are
Taking logarithms gives the log-likelihood
The Poisson distribution has conditional mean and variance both equal to \(\mu_{ig}\). Thus the model assumes that, once predictors and exposure are accounted for, the remaining count variation is no greater than the Poisson variance. This is a substantive assumption, not just a convenient formula.
Worked Example: Estimating a Common Poisson Rate
Suppose three hypothetical spots have exposures \(L_i=(1,2,4)\) and counts for one gene \(y_{ig}=(1,5,7)\). Assume a common rate \(\lambda_g\) per exposure unit, so \(Y_{ig}\sim\operatorname{Poisson}(L_i\lambda_g)\), independently. The likelihood is
Ignoring terms that do not depend on \(\lambda_g\), the log-likelihood is \(\ell(\lambda_g)=(\sum_i y_{ig})\log(\lambda_g)-\lambda_g\sum_iL_i+C\). Differentiating and setting the derivative to zero gives
The fitted means are \(13/7\), \(26/7\), and \(52/7\) counts, respectively. The full log-likelihood at this estimate is
This rate is a maximum-likelihood estimate under the stated common-rate Poisson model. It does not establish that the spots truly share one rate or that their counts are independent; those are assumptions to assess in context.
Negative-Binomial Likelihood and Overdispersion
A negative-binomial model allows the conditional variance to exceed the mean. Use the mean-dispersion parameterization in which \(\mu_{ig}>0\) is the mean and \(\alpha_g\geq0\) is the dispersion. For \(\alpha_g>0\), its probability mass function is
Here \(\Gamma(\cdot)\) is the gamma function. As for the Poisson model, set \(\mu_{ig}=L_i\exp(\eta_{ig})\). The negative-binomial variance is
The dispersion parameter is nonnegative: as \(\alpha_g\) approaches zero, the negative-binomial distribution approaches the Poisson distribution. A larger \(\alpha_g\) permits more variability around the same mean. In this parameterization, \(\alpha_g\) is not the variance itself and is not directly comparable across genes without considering their means.
For independent spots, the negative-binomial likelihood is the product of these probabilities, and its log-likelihood is the sum of their logarithms. Regression coefficients and dispersion are generally estimated numerically; unlike the common-rate Poisson example, there is not generally a simple closed-form estimate for both. The model still assumes that the specified mean is appropriate and, in its basic form, that counts are conditionally independent across spots.
Worked Example: Comparing Poisson and Negative-Binomial Probabilities
Consider a hypothetical spot with fitted mean \(\mu=2\) counts. Under a Poisson model, the probabilities of observing 0 and 4 counts are
Now use a negative-binomial model with the same mean and \(\alpha=0.5\). Its shape is \(1/\alpha=2\), and its success-probability parameter in the equivalent shape-probability form is \(2/(2+\mu)=0.5\). The probabilities simplify to \(P(Y=y)=(y+1)/2^{y+2}\), so
The negative-binomial variance here is \(2+0.5(2^2)=4\), compared with the Poisson variance of 2. The negative-binomial model assigns more probability to zero in this particular comparison, while its probability at 4 is slightly lower. The example illustrates that greater variance does not mean every extreme count becomes more probable; the probabilities change across the entire distribution. One observation cannot determine which model is adequate.
Using the Offset to Compare Rates
The offset separates exposure from rate. If two spots have the same rate but one has twice the library-size exposure, its expected count is twice as large. A model without the offset could mistake that technical exposure difference for an expression difference. A coefficient on \(\log(L_i)\) that is freely estimated is not the standard offset model: it allows the count to scale with library size at a rate other than proportionality.
Worked Example: Comparing Two Hypothetical Groups
Suppose group A has counts \(4,6\) at exposures \(1,1\), and group B has counts \(12,18\) at exposures \(2,3\). Fit separate common Poisson rates per exposure unit for the two groups. For group A,
For group B,
The estimated rate ratio is \(6/5=1.20\), or 20% higher in group B per unit of exposure. This is a descriptive maximum-likelihood comparison under the model; it is not, by itself, a significance test or evidence that group membership caused a change. In a log-link regression with group indicator \(z_i\), the corresponding fitted group coefficient is \(\hat{\beta}_1=\log(1.20)\approx0.1823\). The offset remains \(\log(L_i)\) with coefficient fixed at 1.
Assumptions, Diagnostics, and Alternatives
Both likelihoods require a count response, a positive exposure for every modeled spot, and a defensible conditional mean model. The offset should be defined consistently and should represent the intended library-size adjustment. If \(L_i=0\), then \(\log(L_i)\) is undefined and the spot cannot be handled by this offset specification as written. Such a spot requires a principled preprocessing or modeling decision; replacing zero with an arbitrary small number changes the model.
The Poisson model is appropriate when conditional variation is plausibly close to the mean and conditional independence is reasonable for the intended analysis. The negative-binomial model relaxes the mean-equals-variance restriction, but it does not automatically account for dependence between nearby spots. Spatially structured residuals can remain even when the marginal variance is well described by a negative-binomial distribution. Modeling spatial dependence is a separate extension.
| Feature | Poisson likelihood | Negative-binomial likelihood |
|---|---|---|
| Conditional mean | \(\mu_{ig}=L_i\exp(\eta_{ig})\) | \(\mu_{ig}=L_i\exp(\eta_{ig})\) |
| Conditional variance | \(\mu_{ig}\) | \(\mu_{ig}+\alpha_g\mu_{ig}^2\) |
| Main restriction | Mean equals variance | Variance may exceed mean through dispersion |
| What it does not solve | Mean misspecification or spatial dependence | Mean misspecification or spatial dependence |
Useful checks include comparing observed variability with that implied by fitted means, examining Pearson or deviance residuals for systematic patterns, and checking whether residuals vary with fitted count or library size. A Poisson fit with widespread residual overdispersion suggests that its variance assumption may be inadequate. A negative-binomial fit may address that extra variation, but residual patterns across coordinates can still indicate dependence or a missing spatially patterned predictor. Conversely, a flexible negative-binomial model is not automatically preferable if estimated dispersion is negligible and the additional parameter is unsupported.
A common mistake is to say, “The negative binomial allows overdispersion, so it accounts for spatial clustering.” It does not necessarily do so. Its dispersion allows extra marginal count variation under its specified likelihood; it does not encode which spots are neighbors or how their counts covary. Another mistake is to omit the offset and compare raw counts across spots with unequal library sizes. The correction is to specify the exposure and mean model first, then assess variance and residual dependence separately.
Check Your Understanding
Answer each question, then check the solutions below.
- A spot has exposure \(L_i=2\), and a fitted rate per exposure unit is 4. What is its fitted mean count?
- For a negative-binomial count with \(\mu=3\) and \(\alpha=0.2\), calculate the conditional variance.
- Why can a spot with zero library size not be inserted directly into the log-offset model?
- A negative-binomial fit has acceptable marginal dispersion, but residuals remain spatially patterned. Does the dispersion parameter resolve that pattern?
Solutions. (1) The mean is \(L_i\lambda=2(4)=8\) counts. (2) The variance is \(3+0.2(3^2)=3+1.8=4.8\) counts squared. (3) The offset requires \(\log(L_i)\), which is undefined at \(L_i=0\); the spot needs an explicit modeling or preprocessing decision. (4) No. The negative-binomial dispersion permits extra conditional variance but does not represent dependence based on spatial location.