Why Library Size Enters the Count Model
RNA-seq libraries can contain different numbers of usable reads. If two samples have the same underlying abundance of a transcript but one library has twice as many reads, it can be expected to yield about twice as many reads for that transcript. A model comparing their raw counts should therefore account for this difference in sequencing exposure.
The log-linked model for expected counts provides the needed framework. Here the exposure adjustment is a model offset: a known term added to the linear predictor with its coefficient fixed at 1. It changes the expected count according to library size, without adding a coefficient for the model to estimate.
In a basic negative binomial model, the count distribution is specified by its mean and dispersion. Using the NB2 convention, its variance is \(\mu_{gj}+\phi_g\mu_{gj}^2\), where \(\phi_g\) is the dispersion for gene \(g\). The offset specifies how library size contributes to the mean; it does not change this variance formula or replace the negative binomial distribution.
A typical model for one gene is
Here \(\mathbf{x}_j\) is the sample’s vector of design variables and \(\boldsymbol{\beta}_g\) is the gene-specific coefficient vector. The offset is \(\log L_j\); its coefficient is 1 by definition of the model, not an additional entry in \(\boldsymbol{\beta}_g\). In practical analyses, the exposure supplied to the model may be on a reference scale or may be an adjusted library-size quantity. The derivation below describes the basic library-size exposure.
Deriving the Offset
Suppose the expected count for a gene is proportional to the library’s sequencing exposure. Write \(r_{gj}\) for the expected count per unit of exposure in sample \(j\). The proportional-exposure assumption is
If the log-linked model describes the gene’s expected rate using design variables, let \(\log r_{gj}=\mathbf{x}_j^\mathsf{T}\boldsymbol{\beta}_g\). Taking logarithms of the mean relationship gives
Thus, the log of the exposure enters additively. This algebra explains both the log transformation and the fixed coefficient: the assumed mean is directly proportional to \(L_j\), so multiplying \(L_j\) by a factor \(c\) multiplies \(\mu_{gj}\) by that same factor, all else equal.
The exposure’s units affect the intercept’s numerical value, but not comparisons between samples when the same units are used. For a fixed reference \(L_0\), write
The bracketed term is the remaining linear predictor. Choosing a reference scale changes the intercept representation, not the proportional adjustment across samples.
Worked Example: From Exposure and Rate to Expected Count
Consider a hypothetical gene with a constant expected rate of 3 reads per million units of library exposure in two samples. Their library sizes are 20 million and 40 million reads. Assume the mean is proportional to library size and use millions as the exposure unit. The log-linked rate is \(\log(3)\).
For the first sample, the offset is \(\log(20)=2.9957\), and the linear predictor is \(2.9957+\log(3)=2.9957+1.0986=4.0943\). Therefore, the expected count is \(\exp(4.0943)=60\) reads.
For the second sample, the offset is \(\log(40)=3.6889\), giving \(3.6889+1.0986=4.7875\). The expected count is \(\exp(4.7875)=120\) reads. Doubling the library size doubles the expected count while the expected rate remains 3 reads per million.
These are model expectations, not predictions that every observed count must equal 60 or 120. Under the negative binomial model, observed counts vary around their means.
What “Fixed” Means
In a generalized linear model, a predictor such as treatment usually has an unknown coefficient that is estimated from the data. An offset is different: its values are supplied to the model, and their coefficient is fixed at 1. In the library-size model, \(\log L_j\) is known once the exposure has been specified. The model estimates the biological coefficients in \(\boldsymbol{\beta}_g\), not a separate multiplier for each sample’s log library size.
This restriction expresses a substantive assumption. If a sample’s exposure doubles while its underlying per-unit rate is unchanged, the model requires its expected count to double. Estimating a free coefficient on \(\log L_j\) would instead allow the data to determine the exposure-count relationship. That would be a different model, with a different assumption, rather than an offset version of the same model.
The fixed coefficient does not mean that all samples have the same expected count. Their offsets can differ, and their design variables can differ. Nor does it mean library size is estimated as part of the gene-wise model: it is provided as an exposure. It means only that the model does not estimate an additional coefficient multiplying this known log exposure.
Worked Example: Separating Exposure From a Condition Effect
Suppose a hypothetical two-condition model for one gene uses library sizes of 25 million reads for a control sample and 50 million reads for a treated sample. Assume the fitted baseline rate is 4 expected reads per million, and the fitted treatment coefficient is \(\log(1.5)=0.4055\). The treatment coefficient describes a 1.5 multiplier in the modeled rate, while the offset accounts for the different exposures.
For the control, the linear predictor is \(\log(25)+\log(4)=3.2189+1.3863=4.6052\). The expected count is \(\exp(4.6052)=100\) reads.
For the treated sample, it is \(\log(50)+\log(4)+\log(1.5)=3.9120+1.3863+0.4055=5.7038\). The expected count is \(\exp(5.7038)=300\) reads. The treated sample has twice the exposure and 1.5 times the modeled rate, so its expected count is \(2\times1.5=3\) times the control expectation.
The numbers illustrate the model’s fitted means; they do not assert that any particular observed counts equal those means or establish statistical evidence for a condition difference. The point is that a count difference reflects both exposure and modeled rate.
Assumptions, Checks, and Alternatives
The offset is appropriate when the supplied library size represents a meaningful exposure for the gene counts and the expected count is proportional to that exposure, conditional on the model’s design variables. The model also assumes the chosen negative binomial distribution is a reasonable representation of count variation around the mean. Samples must have positive exposure so that \(\log L_j\) is defined. As with any regression model, the design must represent the comparisons of interest, and the observations must be analyzed with an appropriate dependence structure.
These assumptions are not guaranteed merely because a software function accepts an offset. Useful checks include verifying that all exposures are positive, confirming their units and sample order match the count data, and checking that the fitted means and residual patterns are plausible across samples. An offset entered in the wrong sample order, or in inconsistent units, can distort fitted values. Strong systematic residual patterns across samples or conditions can indicate that the mean model, dispersion model, exposure choice, or design needs review. Residual checks diagnose model fit; they do not by themselves identify the cause of a problem.
Worked Example: Comparing Equal Counts at Different Exposures
Suppose a hypothetical gene has an observed count of 80 reads in each of two samples. Their exposures are 20 million and 40 million reads. To compare the counts on an exposure scale, divide each by its library size expressed in millions.
The first sample’s observed rate is \(80/20=4\) reads per million. The second sample’s observed rate is \(80/40=2\) reads per million. In log terms, subtracting each offset from the log count gives \(\log(80)-\log(20)=\log(4)=1.3863\) and \(\log(80)-\log(40)=\log(2)=0.6931\).
The equal raw counts therefore do not correspond to equal observed rates per unit of exposure. This calculation is descriptive: it does not account for negative binomial sampling variation and does not test whether the underlying rates differ.
One alternative is to scale counts by library size before modeling. That can be useful for some descriptive displays, but a scaled count alone is not the same as specifying a negative binomial likelihood with an offset: the latter retains the count-scale mean-variance relationship in the model. Another alternative is to estimate a free coefficient for log library size. This is not an offset; it estimates how strongly expected counts respond to exposure and can change the model’s interpretation. The offset is the direct choice when proportionality to the supplied exposure is the intended assumption.
The limitation is important: an offset can only adjust for the exposure it is given. It cannot ensure that a raw library size is an adequate measure of effective exposure, correct a misspecified design, or establish that all genes respond proportionally to the supplied quantity. Those questions require scrutiny of the data and the normalization strategy, not a change in the offset’s definition.
Common Mistakes
- Estimating the offset coefficient. Fitting a free coefficient on \(\log L_j\) changes the assumption. In an offset model that coefficient is fixed at 1.
- Adding library size as an ordinary predictor without considering the model. A freely estimated predictor does not impose proportionality; it asks the data to estimate a different relationship.
- Confusing the offset with a change in the count distribution. The offset adjusts the expected mean. The negative binomial distribution still describes count variation around that mean.
- Interpreting raw counts as rates. Counts from different exposures are not directly comparable as measures of abundance without accounting for exposure.
- Assuming the offset repairs every source of bias. It addresses the specified exposure relationship only; it does not validate the exposure choice or the rest of the model.
Check Your Understanding
Answer each question, then compare with the solutions.
- A gene has an expected rate of 2 reads per million, and a sample has 30 million reads of exposure. What are the offset and expected count?
- Why is the coefficient of the log-library-size offset fixed at 1?
- Two samples have the same underlying rate, but one has three times the exposure. What ratio of expected counts does the offset model imply?
- What does fitting a free coefficient on log library size do differently from using it as an offset?
Solutions. (1) With exposure measured in millions, the offset is \(\log(30)=3.4012\). The expected count is \(30\times2=60\) reads; equivalently, \(\exp[\log(30)+\log(2)]=60\). (2) The assumption \(\mu=Lr\) makes \(\log\mu=\log L+\log r\), so the exposure term has coefficient 1. (3) The expected-count ratio is 3, because \(\mu_2/\mu_1=(3L_1r)/(L_1r)=3\). (4) A free coefficient estimates the exposure-count relationship from data instead of enforcing proportionality; it is a different model, not an offset.