# MvGaussianRandomWalk prediction

**URL:** <https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576>\
**Category:** Questions\
**Created:** [July 25, 2018, 4:18pm UTC](https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576 "2018-07-25T16:18:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximelecactus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/maximelecactus/32/922_2.png) [@maximelecactus](https://discourse.pymc.io/u/maximelecactus)\
**Post date:** [July 25, 2018, 4:18pm UTC](https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576/1 "2018-07-25T16:18:13Z")

</div>

Hi,

I am trying to model two time series (columns of `observed`) as Gaussian Random Walks with a drift that is a function of a linear regression. Everything works fine except when it comes to inspection and prediction.

```
with model:
    packed_L = pm.LKJCholeskyCov('packed_L', n=shape, eta=2, sd_dist=pm.HalfCauchy.dist(2.5))
    L = pm.expand_packed_triangular(shape, packed_L)
    Σ = pm.Deterministic('Σ', L.dot(L.T))
    
    one_mu = mu_variable(f_data, 'one') # linear combination of regressor and regressor beta
    two_mu = mu_variable(f_data, 'two')
    mu = T.stack([eps_mu, pe_mu]).T
    
    obs = pm.MvGaussianRandomWalk('obs', mu=mu, chol=L, observed=target)
    
    trace = pm.sample(3000, cores=1)

trace['obs']
KeyError: 'Unknown variable obs'

```

I would like to visually inspect how the model performed. In the [stochastic volatility model](https://docs.pymc.io/notebooks/stochastic_volatility.html) the author simple inspect the trace. However, in this case, the trace does not have an “obs” variable.

How can I check what the model predicted against the observed time series?

Many thanks,

Maxime.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [July 25, 2018, 6:22pm UTC](https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576/2 "2018-07-25T18:22:17Z")

</div>

Usually you can do sample\_ppc and display it just like a trace, but in this case `pm.MvGaussianRandomWalk` does not have a random method, so it might be a bit difficult…

---

<div class="post-metadata">

**Author:** ![maximelecactus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/maximelecactus/32/922_2.png) [@maximelecactus](https://discourse.pymc.io/u/maximelecactus)\
**Post date:** [July 26, 2018, 7:09am UTC](https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576/3 "2018-07-26T07:09:28Z")

</div>

Thank you for your answer.

Do you have an idea on how I could do that? From what I could understand, `MvGaussianRandomWalk` implements a `MvNormal` under the hood ([link](https://github.com/pymc-devs/pymc3/blob/aaaa00fe6a17f1687cff819f7a42b0edb24db70b/pymc3/distributions/timeseries.py#L292)).

Could it be possible to leverage the random method of `MvNormal`? For example, `MvGaussianRandomWalk` could be extended with:

```
def random():
    return self.innov.random()

```

The goal is to return samples of the innovation and standard deviation.

Would you see another way ?

Many thanks,

Maxime.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [July 26, 2018, 5:54pm UTC](https://discourse.pymc.io/t/mvgaussianrandomwalk-prediction/1576/4 "2018-07-26T17:54:52Z")

</div>

In principle you can write a custom random generation function, which take posterior sample as input, and output a stochastic prediction. However, given that the distribution is a random walk, when you generate prediction (posterior prediction samples) it wont have the usual nice property eg a region of uncertainty around the actual observed.
