# \[PyMC3\] Non-centered parameterization for rolling regression

**URL:** <https://discourse.pymc.io/t/pymc3-non-centered-parameterization-for-rolling-regression/4291>\
**Category:** Questions\
**Created:** [January 3, 2020, 1:26am UTC](https://discourse.pymc.io/t/pymc3-non-centered-parameterization-for-rolling-regression/4291 "2020-01-03T01:26:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yurong](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yurong/32/8120_2.png) [@yurong](https://discourse.pymc.io/u/yurong)\
**Post date:** [January 3, 2020, 1:26am UTC](https://discourse.pymc.io/t/pymc3-non-centered-parameterization-for-rolling-regression/4291/1 "2020-01-03T01:26:35Z")

</div>

Hi,

I am referring to this post [https://docs.pymc.io/notebooks/GLM-rolling-regression.html](https://docs.pymc.io/notebooks/GLM-rolling-regression.html) to build a rolling regression time series model. My implementation as below is pretty straight forward. The problem is that even with 3000 samples, none of the variables converged (h\_hat \> 2 generally with 4 cores) and ess\_means are generally less than 10.

I wonder if it’s because of the “funnel” problem and if there is a non-centered implementation for GaussianRandomWalk? (I know how to implement non-centered Normal, but GaussianRandomWalk doesn’t have an explicit “mu” parameter. )

Thanks in advance!

* * *

x\_arr = np.array(X[regressors])  
y\_arr = np.array(y)  
n\_var = len(regressors) # number of variables - 4  
n\_t = X.shape[0] # number of timestamps - 108

with pm.Model() as linear\_model:  
# std of random walk  
global\_sigma = pm.Exponential(‘global\_signma’, 0.05)

```
weights = pm.GaussianRandomWalk('weights', sigma=global_sigma, shape=(n_t, n_var))

noise = pm.HalfNormal('noise', sigma=2)

mu = (x_arr * weights).sum(axis=1)
y_observed = pm.Normal('y_observed',
            mu=mu,
            sigma=noise,
            observed=y_arr)

posterior = pm.sample(3000, init="advi", target_accept=0.95)
```

---

<div class="post-metadata">

**Author:** ![twiecki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/twiecki/32/6930_2.png) [@twiecki](https://discourse.pymc.io/u/twiecki)\
**Post date:** [January 3, 2020, 2:08pm UTC](https://discourse.pymc.io/t/pymc3-non-centered-parameterization-for-rolling-regression/4291/2 "2020-01-03T14:08:14Z")

</div>

Hi @yurong!

You can try the following:

```auto
pm.Normal('x', mu=0, sigma=sigma, shape=n).cumsum()

```

To get a random-walk.

---

<div class="post-metadata">

**Author:** ![yurong](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yurong/32/8120_2.png) [@yurong](https://discourse.pymc.io/u/yurong)\
**Post date:** [January 3, 2020, 7:05pm UTC](https://discourse.pymc.io/t/pymc3-non-centered-parameterization-for-rolling-regression/4291/3 "2020-01-03T19:05:47Z")

</div>

Thanks @twiecki! I’ll test this approach
