# Cells in the center of scVI latent space

When modeling scRNA-seq data with scVI, it is common to notice that some cells of mixed cell types appear in the center of the representation space. Often these are lower quality cells, or in cases where snRNA-seq data is mixed with scRNA-seq data, the snRNA-seq data tend to appear closer towards the middle. This leads to difficulties when assigning cell type labels to these cells, or using label transfer workflows. Why does this happen?

With scVI, gene expression levels in cells are modeled by latent variables, representing their state in a way that is compatible with the observed molecule counts of the transcriptomes. A substantially simplified version of the model can be defined by

Here Z is the latent representation of the cells, ω are observation probabilities for the genes in the cells, and ℓ are the total observed UMI count depths for the cells. This turns the ω⋅ℓ term into rate parameters for the Poisson distribution which is used to generate the UMI counts Y. The goal of scVI is to infer the posterior distribution of Z given the observed counts Y: P(Z | Y).

For an illustration, a simple dataset consisting of one sample from (Ren et al. 2021) can be used as in a previous post. This example has 14,545 cells limited to 141 genes known to be markers of various blood cells. Here the scVI model is fitted with a 2-dimensional representation for the sake of a simple visualization.

After fitting the model we get the following plot of the latent representations for the cells:

To investigate the effect of counting fewer mRNA molecules than were actually counted, binomial thinning can be used. The observed counts are used to estimate probabilities of all observations:

These are passed to a binomial distribution where the number of trials are set to the a number n, lower than the observed number, from which new counts are sampled:

Picking a few cells, these can be binomially thinned to different depths while keeping track of which cells they originated from. These new thinned cells Y^n can be used to infer P(Z^n | Y^n).

In the plot below five cells were selected for thinning and then used to obtain latent representations Z. The thinned versions of the cells are connected by red lines depending on which their original cell was. These thinned cells are colored by their UMI count depth after thinning.

The plot illustrates that as the UMI count depth decreases, the more likely a cell is to be represented by central coordinates, close to the origin, in the scVI latent space.

This effect can be explained by investigating the loss function used for the scVI model. The posterior P(Z | Y) is approximated by a parameterized distribution Q(Z) specifically where Q(zc,d)=N(μc,d,σc,d) and

In inference, the loss is minimized. In this particular version with a Poisson likelihood,

It is worth pointing out that ℓc=∑gyc,g in most situations, so maxyg≤ℓc The consequence of this is that the log_probc term is limited by the total UMI count depth ℓc.

The KL term quantifies how far the approximation of the posterior Q(Z) is from the prior P(Z). Since the prior consists of unit Gaussian distributions, the KL term is

When inferring the approximate posterior Q(zc), the magnitude of log_probc term need to beat the magnitude of the klc term to escape the isotropic unit Gaussian prior N(0,1).

This can be illustrated by repeating the plot above, but coloring the thinned cells by the log_probc term instead of the UMI count depth.

As the log_probc term decreases, cells are more likely to be represented inside the prior N(0,1).

The thinned cells can be used to visualize how the relation between the log_probc term and the klc term depend on the total UMI count depth ℓc.

Below a threshold, the magnitude of the −log_probc term is of the same magnitude as the klc term.

This explains the phenomenon of lower quality cells with fewer UMI counts landing in the center of the latent scVI representation. The intuition to keep in mind is that for count distributions, when you count fewer items you have less information than when you count more items. In these cases, information from the prior is used instead, which constrains the representations to the center.

This also highlights the value of obtaining cells with high UMI counts. If all cells in an analysis have extremely low UMI counts, it will be hard to escape the prior to learn cell states (which manifest as dense regions of the latent representation space). When working with cells that have low UMI counts, be comfortable with their identities being ambiguous; you simply can’t learn as much from them as cells with higher counts.

Notebooks for the analysis in this post are available on Github at https://github.com/vals/Blog/tree/master/230524-center-of-scvi-space.

Ren, Xianwen, Wen Wen, Xiaoying Fan, Wenhong Hou, Bin Su, Pengfei Cai, Jiesheng Li, et al. 2021. “COVID-19 Immune Features Revealed by a Large-Scale Single-Cell Transcriptome Atlas.” Cell 184 (23): 5838. https://doi.org/10.1016/j.cell.2021.10.023.