# N\_samples ( refers to Monte Carlo sampling for each cell) setting in totalVI

**URL:** <https://discourse.scverse.org/t/n-samples-refers-to-monte-carlo-sampling-for-each-cell-setting-in-totalvi/2340>\
**Category:** scvi-tools\
**Tags:** totalvi\
**Created:** [June 19, 2024, 9:12am UTC](https://discourse.scverse.org/t/n-samples-refers-to-monte-carlo-sampling-for-each-cell-setting-in-totalvi/2340 "2024-06-19T09:12:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qingjiao](https://avatars.discourse-cdn.com/v4/letter/q/f17d59/32.png) [@qingjiao](https://discourse.scverse.org/u/qingjiao)\
**Post date:** [June 19, 2024, 9:12am UTC](https://discourse.scverse.org/t/n-samples-refers-to-monte-carlo-sampling-for-each-cell-setting-in-totalvi/2340/1 "2024-06-19T09:12:05Z")

</div>

Hi 🙂  
I have a question about the n\_samples ( refers to Monte Carlo sampling for each cell) setting in totalVI.  
In the tutorial ( [CITE-seq analysis with totalVI — scvi-tools](https://docs.scvi-tools.org/en/stable/tutorials/notebooks/multimodal/totalVI.html#)), `n_samples` is set to 25 in `get_normalized_expression` function.  
rna\_denoised, protein\_denoised = model.get\_normalized\_expression(  
n\_samples=25, return\_mean=True, transform\_batch=[“PBMC10k”, “PBMC5k”]  
)

However, n\_samples is not a parameter in the function ‘differential\_expression’  
de\_df = model.differential\_expression(  
groupby=“rna\_subset:leiden\_totalVI”, delta=0.5, batch\_correction=True  
)  
As I understand the differential calculation is based on the denoised data, so I checked the source code from github, and found the n\_samples is set as 1 by default  
def \_expression\_for\_de():  
rna, protein = self.get\_normalized\_expression(  
adata=adata,  
indices=indices,  
n\_samples\_overall=n\_samples\_overall,  
transform\_batch=transform\_batch,  
return\_numpy=True,  
n\_samples=1,  
batch\_size=batch\_size,  
scale\_protein=scale\_protein,  
sample\_protein\_mixing=sample\_protein\_mixing,  
include\_protein\_background=include\_protein\_background,  
)  
The source code is located from ([scvi-tools/scvi/model/\_totalvi.py at 95f2e1d2fa921c6433a04e257d844280ba0c25e5 · scverse/scvi-tools · GitHub](https://github.com/scverse/scvi-tools/blob/95f2e1d2fa921c6433a04e257d844280ba0c25e5/scvi/model/_totalvi.py#L657))

So, the question is how you recommend n\_samples setting? If n\_samples=25 works well, can this parameters be passed to the below function  
TOTALVI.differential\_expression(_adata=None_ , _groupby=None_ , _group1=None_ , _group2=None_ , _idx1=None_ , _idx2=None_ , _mode=‘change’_ , _delta=0.25_ , _batch\_size=None_ , _all\_stats=True_ , _batch\_correction=False_ , _batchid1=None_ , _batchid2=None_ , _fdr\_target=0.05_ , _silent=False_ , _protein\_prior\_count=0.1_ , _scale\_protein=False_ , _sample\_protein\_mixing=False_ , _include\_protein\_background=False_ , \*\*_kwargs_ )

Lots of thanks in advance!

---

<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:** [June 28, 2024, 1:22am UTC](https://discourse.scverse.org/t/n-samples-refers-to-monte-carlo-sampling-for-each-cell-setting-in-totalvi/2340/2 "2024-06-28T01:22:39Z")

</div>

Hi. We take mc\_samples for differential expression from all cells within group1 and group2. Usually we create enough values for these group comparison to get a good estimate, whereas for the normalized expression you want one value per cell and need more samples. Were you experiencing issues?
