# Embedding number for visualization

**URL:** <https://discourse.scverse.org/t/embedding-number-for-visualization/2482>\
**Category:** scvi-tools\
**Tags:** integration, scvi\
**Created:** [August 29, 2024, 2:13am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482 "2024-08-29T02:13:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [August 29, 2024, 2:13am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/1 "2024-08-29T02:13:17Z")

</div>

Recently I found some standard deviation (sd) of embedding scores after scvi integration were closed to 0 (about 0.02, the information was store in seurat\_object@reductions[[“integrated.scvi”]]@cell.embeddings), even some of the top embeddings (scvi\_1, scvi\_4, scvi\_9, shown as follow: embedding scores in cells belong to different clusters). I wonder if embedding score with sd close to 0 is helpful for visualization. Why do the results turn out like this and how many embeddings should I choose. The analysis was based on Seurat V5, integratelayers function.

 ![图片1](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/2X/4/46e7b5bb09f7c6c831c606fcfac6ad5945138284.png)

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [August 30, 2024, 12:03am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/2 "2024-08-30T00:03:46Z")

</div>

Hi. Unfortunately, I really don’t get what you are doing here. Are those different runs of scVI compared with each other? What’s your expectation and why are you doing it? Sharing some code would additionally be helpful.

---

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [August 30, 2024, 9:25am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/3 "2024-08-30T09:25:44Z")

</div>

Hi, thanks for reply. I used scvi tool to integrate 6 scrna samples. After integration, the functions (FindNeighbors, FindClusters, RunUMAP) were used for clustering and visualization. A parameter specifed the number of embeddings should be input when using FindNeighbors and RunUMAP. Like PCA, the top PCs capture most data variances, and PCs have variances in decreasing order (The first pc has highest variance). But the SD of first, fourth, ninth embedding scores output by scvi were closed to 0 in the above figure, indicated that it is unhelpful of these embeddings (sd closed to 0) for clustering. So I am confused about the results and dont know how many embeddings should I choose for visulization.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [August 30, 2024, 2:43pm UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/4 "2024-08-30T14:43:14Z")

</div>

I see, you should use all latent\_dimensions. The order of latent dimensions doesn’t highlight importance or something. While axes with a higher estimated variance (qz\_v) contain less information, filtering these out is unconventional for VAEs.

---

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [August 31, 2024, 7:04am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/5 "2024-08-31T07:04:34Z")

</div>

Maybe axes with higher estimated variance contain more information? I am not familiar with the VAE and UMAP algorithm, and I should use all latent dimensions for clustering and visulization? (the integration function ‘Integratelayers’ will output 30 latent dimensions). Thanks!

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [August 31, 2024, 7:30am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/6 "2024-08-31T07:30:11Z")

</div>

I think in integratelayers you don’t have access to the estimated variances of each cell but only to the estimated mean position in latent space (so you are displaying here the variances across these means). I was speaking about the per cell variance in a VAE.  
I would highly recommend to not reduce the number of latent parameters post hoc but use all latent dimensions for downstream analysis.

---

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [August 31, 2024, 10:33am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/7 "2024-08-31T10:33:04Z")

</div>

Thanks for reply! Actually, I dont know the relation between VAE and latent dimension. I would like to express this more clearly, in my understanding, the output of integratelayers contains a n x 30 matrix, n represents the number of cells, 30 represents the number of latent dimensions. The matrix indicates the position of each cell in a 30 dimension space, and it is difficult to distinguish cells with dimensions of low variance. I think these 30 latent dimensions are similar to principal components. So if the importance of latent dimensions is unrelated to variance, then I think all latent dimensions should be used for downstream analysis.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [September 9, 2024, 8:18pm UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/8 "2024-09-09T20:18:38Z")

</div>

Yes use all latent dimensions.

---

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [September 22, 2024, 11:27am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/9 "2024-09-22T11:27:51Z")

</div>

Hi. I tried to use 21 dims to plot the UMAP, which removed the dims with low SD (in the above figure, integratedscvi\_29, integratedscvi\_10, integratedscvi\_27, integratedscvi\_1, integratedscvi\_11, integratedscvi\_4, integratedscvi\_9, integratedscvi\_15, integratedscvi\_18). Compared to the UMAP plotted with 30 dims (all dims were used), I found the two plots are similar. So, for the UMAP, maybe it should rank the dims by SD and choose the high ones?

 ![资源 4](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/2X/4/49e63ef7763cf7f936b24272902a133689518864.png)

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [September 22, 2024, 4:18pm UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/10 "2024-09-22T16:18:02Z")

</div>

The one with low variance might be important for lowly abundant celltypes. I would highly recommend against subsetting the latent dimensions based on some criterion. Standard VAEs are not designed to have a sparse set of latent dimensions that are important.

---

<div class="post-metadata">

**Author:** ![vgettaa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/vgettaa/32/1137_2.png) [@vgettaa](https://discourse.scverse.org/u/vgettaa)\
**Post date:** [September 23, 2024, 5:04am UTC](https://discourse.scverse.org/t/embedding-number-for-visualization/2482/11 "2024-09-23T05:04:21Z")

</div>

Thanks! I think I should take some time to learn VAE. 👌
