Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Modeling Gene Expression Along Branches

Branching and Lineage Models · Tutorial 420 of 700

Modeling Gene Expression Along Branches

Build continuous shared-before-branch expression models, compare branch-specific trends with a pooled trend, and interpret the results and their limitations.

Advanced 12 min read

What You'll Learn

  • Specify a gene-expression model with a shared pre-branch curve and branch-specific post-branch deviations.
  • Enforce continuity at the branchpoint using hinge or spline basis functions.
  • Test whether branch-specific trends improve fit using nested-model comparisons.
  • Interpret a branch-by-pseudotime interaction and its confidence interval in context.
  • Diagnose sparse branch coverage, residual misfit, and sensitivity to branchpoint choices.
  • Recognize when Gaussian curve fitting is an approximation and when the conclusion is conditional on model assumptions.

Why Model Gene Expression Along Branches?

A lineage model describes cells moving along a shared trajectory before a branchpoint and into distinct branches afterward. A gene may follow the same expression pattern before that point but change differently along the emerging lineages. The statistical question is not simply whether expression differs between two groups of cells: it is whether the expression trend varies by branch after accounting for the shared developmental path.

Here, \(t_i\) denotes the pseudotime of cell \(i\), \(\tau\) the branchpoint, \(z_i\in\{1,2\}\) its branch, and \(y_{ig}\) the measured expression for gene \(g\). For clarity, the worked calculations use log-normalized expression and treat the branchpoint and pseudotimes as fixed. In practice, pseudotime is an estimated coordinate, and that estimation can affect downstream uncertainty.

Definition: A shared-before-branch expression model gives all cells the same fitted mean expression curve for \(t_i\leq\tau\). After \(\tau\), the mean may vary by branch. A branch-specific trend is supported when allowing that post-branch variation improves fit beyond what would be expected from residual noise under the specified model.

A Continuous Model for Two Branches

A simple model uses straight-line trends after the branchpoint. Define \(x_i=t_i-\tau\) and \(x_{i+}=\max(0,x_i)\). For one gene, consider

$$ y_i=\beta_0+\beta_1x_i+\beta_2x_{i+} +\beta_3 I(z_i=2)x_{i+}+\varepsilon_i. $$

The indicator \(I(z_i=2)\) equals 1 for branch 2 and 0 for branch 1. Before the branchpoint, \(x_{i+}=0\), so both branches have the same fitted mean, \(\beta_0+\beta_1x_i\). At \(x_i=0\), the post-branch terms are also zero, so the fitted curves meet continuously at \(\beta_0\). After the branchpoint, the branch 1 slope is \(\beta_1+\beta_2\), and the branch 2 slope is \(\beta_1+\beta_2+\beta_3\). Thus \(\beta_3\) is the difference in post-branch slopes, in expression units per pseudotime unit.

This model assumes that the conditional mean is adequately described by the specified piecewise-linear curves. For the usual exact small-sample \(t\) and \(F\) tests, it also assumes independent errors with mean zero, a common variance, and normally distributed errors conditional on the predictors. These assumptions concern residuals around the fitted means, not the marginal distribution of all observed expression values. Log-normalized expression can sometimes be modeled this way as an approximation; it is not a claim that raw RNA counts are Gaussian.

For curved trends, replace the single post-branch hinge with a set of basis functions. Let \(B_k(s)\) be post-branch basis functions that equal zero at \(s=0\). A model can include shared terms and branch-by-basis interactions:

$$ y_i=f_{\mathrm{shared}}(t_i)+ \sum_{k=1}^{K}\gamma_k I(z_i=2)B_k(t_i-\tau) +\varepsilon_i,\qquad t_i>\tau. $$

The shared part includes the common pre-branch curve and any shared post-branch trend. The functions \(B_k\) allow branch 2 to deviate from branch 1 after the branchpoint, while their zero value at the branchpoint preserves continuity. For two branches, testing \(H_0:\gamma_1=\cdots=\gamma_K=0\) asks whether the branch-specific deviations improve fit. A linear trend comparison is the special case \(K=1\).

Worked Example: Fitting and Testing a Slope Difference

Suppose a hypothetical experiment yields the following log-normalized expression values for one gene. The branchpoint expression is shared, and the listed \(x\) values are pseudotime units after that point.

Branch\(x\)Observed expression \(y\)
11, 2, 3, 43.2, 4.8, 6.8, 9.2
21, 2, 3, 44.1, 6.9, 9.9, 13.1

Fit the continuous post-branch lines \(y=\beta_0+s_1x\) for branch 1 and \(y=\beta_0+s_2x\) for branch 2, which share the intercept at \(x=0\). The fitted values are \(\hat{\beta}_0=1\), \(\hat{s}_1=2\), and \(\hat{s}_2=3\). For example, branch 1’s fitted values are \(1+2x=(3,5,7,9)\); its residuals are \((0.2,-0.2,-0.2,0.2)\). Branch 2’s fitted values are \(1+3x=(4,7,10,13)\); its residuals are \((0.1,-0.1,-0.1,0.1)\). Within each branch, these residuals sum to zero and their products with the corresponding \(x\) values sum to zero, confirming the stated least-squares fit.

The full model’s residual sum of squares is \(SSE_{\mathrm{full}}=4(0.2^2)+4(0.1^2)=0.20\). It has three fitted parameters: one shared intercept and two slopes, so \(df_{\mathrm{full}}=8-3=5\). Under \(H_0:s_1=s_2\), the reduced model has a shared intercept and slope. Its least-squares fit is \(y=1+2.5x\), giving residuals \((-0.3,-1.2,-1.7,-1.8)\) in branch 1 and \((0.6,0.9,1.4,2.1)\) in branch 2. Therefore, \(SSE_{\mathrm{reduced}}=7.66+7.54=15.20\).

The nested-model statistic is

$$ F=\frac{(SSE_{\mathrm{reduced}}-SSE_{\mathrm{full}})/q} {SSE_{\mathrm{full}}/(n-p_{\mathrm{full}})} =\frac{(15.20-0.20)/1}{0.20/5} =375, $$

where \(q=1\) restriction is tested, \(n=8\), and \(p_{\mathrm{full}}=3\). Under the Gaussian, independent, equal-variance error assumptions, this is compared with an \(F\) distribution with \(1\) and \(5\) degrees of freedom. The p-value is below 0.001, so the data provide strong evidence against equal post-branch slopes under this model. The estimated slope difference is \(3-2=1\) log-normalized expression unit per pseudotime unit. The small hypothetical sample and its very low residual variation make the result especially dependent on the stated assumptions; the calculation is not evidence that those assumptions hold in an actual experiment.

Testing the Branch-Specific Trend

For the linear model, the null hypothesis of no branch-specific slope difference is \(H_0:\beta_3=0\), against \(H_a:\beta_3\ne0\). A coefficient test uses \(t=\hat{\beta}_3/SE(\hat{\beta}_3)\). A confidence interval for \(\beta_3\) expresses uncertainty in the difference in slopes, with units of expression per pseudotime unit. For several post-branch basis functions, compare the full model with a reduced model that removes all branch-by-basis terms.

The nested-model \(F\) statistic follows from comparing residual sums of squares. If the full model has \(p_{\mathrm{full}}\) parameters and the reduced model removes \(q\) parameters, then, under the linear-model assumptions and the null hypothesis,

$$ F=\frac{(SSE_{\mathrm{reduced}}-SSE_{\mathrm{full}})/q} {SSE_{\mathrm{full}}/(n-p_{\mathrm{full}})} \sim F_{q,\,n-p_{\mathrm{full}}}. $$

The numerator measures the decrease in residual variation per restriction released; the denominator estimates residual variance in the full model. A large value indicates that the branch-specific terms reduce residual variation substantially relative to the noise estimate. The test does not establish that a branch caused the expression change, nor does a small p-value measure the size or biological importance of the change.

For a curved model with three branch-deviation coefficients, a joint test is preferable to testing each coefficient separately: the null is that all three equal zero. Testing them jointly asks whether the branch-specific curve differs anywhere in the modeled basis space, while separate tests can miss a combined pattern and inflate the chance of false-positive findings if interpreted as a collection of unadjusted tests.

Worked Example: Interpreting a Slope Difference and Interval

In another hypothetical dataset, a fitted linear model estimates \(\hat{\beta}_3=0.45\) log-normalized expression units per pseudotime unit, with \(SE(\hat{\beta}_3)=0.18\) and \(df=36\). The coefficient test statistic is

$$ t=\frac{0.45}{0.18}=2.50. $$

For a two-sided test, this corresponds to a p-value of approximately 0.017 under the model assumptions. The estimate is evidence that branch 2’s post-branch slope exceeds branch 1’s; it is not the expression difference at every point along the branches. At two pseudotime units after the branchpoint, the fitted branch difference attributable to this slope contrast is \(0.45\times2=0.90\) log-normalized expression units.

Using \(t_{0.975,36}\approx2.028\), a 95% confidence interval for the slope difference is \(0.45\pm2.028(0.18)=0.45\pm0.365\), or approximately \([0.085,0.815]\) log-normalized expression units per pseudotime unit. Under repeated sampling and the model assumptions, this interval procedure would cover the true slope difference 95% of the time. The interval does not imply a 95% probability that this particular fixed parameter lies inside it.

Worked Example: Testing a Curved Branch Deviation

Suppose a hypothetical spline fit uses \(n=80\) cells and a full model with 10 parameters, including three branch-specific basis coefficients. Its residual sum of squares is 12. A reduced model retaining the shared curve but omitting those three coefficients has residual sum of squares 18. The joint null hypothesis is that all three branch-specific coefficients are zero.

Here \(q=3\) and the full-model residual degrees of freedom are \(80-10=70\). The comparison is

$$ F=\frac{(18-12)/3}{12/70} =\frac{2}{0.1714} \approx11.67. $$

The statistic is compared with an \(F_{3,70}\) distribution, yielding \(p<0.001\). Conditional on the model assumptions, there is strong evidence that the branch-specific spline terms improve fit. This joint test does not identify which part of the curve differs; fitted curves and uncertainty bands are needed to describe the pattern and its magnitude.

Diagnostics, Alternatives, and Limitations

A branch-specific test is informative only if the data contain information about the curves being compared. Inspect expression against pseudotime separately by branch, along with fitted curves and residuals. Check that both branches have observations across enough of the post-branch range to distinguish a trend difference from a few isolated cells. Look for residual patterns, changing residual spread, influential cells, and systematic curvature left by a straight-line fit. For spline models, check whether the fitted shape changes sharply with the number or placement of basis functions.

The branchpoint also matters. If \(\tau\) is estimated rather than fixed, treating its estimate as known can understate uncertainty. A reported coefficient test is then conditional on the chosen branchpoint unless the fitting and inference procedure accounts for its estimation. Repeating the fit over plausible branchpoint values is a useful sensitivity check. Likewise, if branch labels are uncertain, assigning each cell to its most likely branch and then treating that assignment as certain can understate uncertainty; use a procedure that carries the branch uncertainty into the fit.

The alternatives answer different questions. A single pooled curve ignores branch-specific trends and may conceal divergence. Fitting unrelated curves on each branch allows divergence, but does not enforce a shared pre-branch segment or continuity at the branchpoint. The constrained shared-plus-deviation model makes that biological structure explicit and permits a direct nested comparison. A more flexible spline can represent curvature, but uses more parameters and may fit noise when data are sparse. In each case, compare models that use the same response scale and observations, and interpret a test in light of the chosen basis and assumptions.

Finally, these calculations are gene-specific. If many genes are tested, the collection of p-values requires an appropriate multiple-testing procedure before making claims across genes. A significant trend difference is statistical evidence of branch-associated expression patterns under the model, not proof of a causal regulatory mechanism. Poor coverage, misspecified mean curves, nonconstant variance, dependence among cells, and uncertainty in pseudotime can all make nominal standard errors and p-values unreliable. In single-cell data, also inspect whether conclusions are robust to the expression scale and to reasonable modeling choices.

Common Mistake

Wrong reasoning: “The branch 1 test is significant and the branch 2 test is not, so the branches have different trends.” Significance in one subgroup and nonsignificance in another is not itself a test of the difference between subgroups. Correction: fit a model containing the branch-by-pseudotime term and test that term directly, or compare the nested shared-trend and branch-specific models. The interaction estimates the difference of interest and its uncertainty.

Key takeaway: State the shared pre-branch structure, ensure post-branch deviations meet at the branchpoint, and test branch-specific terms directly. Interpret the result as conditional on the expression scale, trajectory, branch assignments, and error assumptions used in the fit.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. In the piecewise-linear model, what is the branch 2 post-branch slope, and what parameter represents the difference from branch 1?
  2. A fitted slope difference is 0.30 expression units per pseudotime unit. What is the corresponding fitted difference two units after the branchpoint, under the linear model?
  3. Why does a branch-specific curve need not imply different fitted expression before the branchpoint?
  4. A spline model has four branch-deviation coefficients. What null hypothesis does their joint test assess?
  5. Why is “significant in branch 1, not significant in branch 2” not a valid test that the branch trends differ?

Solutions. (1) The branch 2 slope is \(\beta_1+\beta_2+\beta_3\); \(\beta_3\) is the branch 2 minus branch 1 slope difference. (2) The fitted difference is \(0.30\times2=0.60\) expression units. (3) The post-branch terms are zero at and before the branchpoint, so the model retains the common pre-branch curve. (4) It tests that all four branch-deviation coefficients equal zero, meaning no branch-specific deviation in the modeled basis. (5) Separate significance tests do not test the difference between estimates; the branch-by-pseudotime term or nested-model comparison directly tests whether the trends differ.

Clinical Biostats