# Sampling from conditional posterior of p(x\_n | z\_n, s\_n, l\_n, and covariates)

**URL:** <https://discourse.scverse.org/t/sampling-from-conditional-posterior-of-p-x-n-z-n-s-n-l-n-and-covariates/301>\
**Category:** scvi-tools\
**Created:** [February 27, 2022, 11:12pm UTC](https://discourse.scverse.org/t/sampling-from-conditional-posterior-of-p-x-n-z-n-s-n-l-n-and-covariates/301 "2022-02-27T23:12:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hufengling](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/hufengling/32/145_2.png) [@hufengling](https://discourse.scverse.org/u/hufengling)\
**Post date:** [February 27, 2022, 11:12pm UTC](https://discourse.scverse.org/t/sampling-from-conditional-posterior-of-p-x-n-z-n-s-n-l-n-and-covariates/301/1 "2022-02-27T23:12:19Z")

</div>

Thanks for such a great tool and forum for questions.

I’m trying to use scVI to control for batch effect while explicitly preserving biologic information found in a set of categorical and continuous covariates for each cell - the generative process would be that x\_n depends on z\_n, s\_n, l\_n, and the set of covariates. I think entering categorical and continuous covariates to the scVI setup\_anndata function will allow for this explicit modeling, and I was wondering if it was possible to then sample from this conditional posterior.

Thanks again!

---

<div class="post-metadata">

**Author:** ![adamgayoso](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/adamgayoso/32/100_2.png) [@adamgayoso](https://discourse.scverse.org/u/adamgayoso)\
**Post date:** [February 28, 2022, 2:15am UTC](https://discourse.scverse.org/t/sampling-from-conditional-posterior-of-p-x-n-z-n-s-n-l-n-and-covariates/301/2 "2022-02-28T02:15:48Z")

</div>

> [@hufengling](#):
>
> I was wondering if it was possible to then sample from this conditional posterior.

Yes you can just use the [`posterior_predictive_sample()`](https://docs.scvi-tools.org/en/stable/api/reference/scvi.model.SCVI.posterior_predictive_sample.html#scvi.model.SCVI.posterior_predictive_sample) method. However, consider this will generate new data that will contain the effects that your are trying to remove. On the other hand, the latent representation of cells will be corrected.
