# Automatic Imputation of Multivariate models

**URL:** <https://discourse.pymc.io/t/automatic-imputation-of-multivariate-models/11029>\
**Category:** Questions\
**Created:** [December 17, 2022, 10:31pm UTC](https://discourse.pymc.io/t/automatic-imputation-of-multivariate-models/11029 "2022-12-17T22:31:25Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [December 19, 2022, 7:31pm UTC](https://discourse.pymc.io/t/automatic-imputation-of-multivariate-models/11029/3 "2022-12-19T19:31:27Z")

</div>

We don’t have an API in place yet, but you can do it easy enough with a Potential

```python
import pymc as pm
import numpy as np

import aesara.tensor as at

data = np.zeros((3,2))
data[[0, 1, 2, 2], [0, 1, 0, 1]] = np.nan
print(data)

with pm.Model() as m:
    # Create a vector of flat variables for the unobserved components of the MvNormal
    x_unobs = pm.Flat("x_unobs", shape=(np.isnan(data).sum(),))

    # Create the symbolic value of x, combining observed data and unobserved variables
    x = at.as_tensor(data)
    x = pm.Deterministic("x", at.set_subtensor(x[np.isnan(data)], x_unobs))

    # Add a Potential with the logp of the variable conditioned on `x`
    pm.Potential("x_logp", pm.logp(rv=pm.MvNormal.dist([0, 0], [[1,0],[0,1]]), value=x))
    idata = pm.sample()

```

---

_[View the full topic](https://discourse.pymc.io/t/automatic-imputation-of-multivariate-models/11029)._
