# Vanilla autoregressive model?

**URL:** <https://discourse.pymc.io/t/vanilla-autoregressive-model/6325>\
**Category:** Questions\
**Created:** [November 30, 2020, 4:35am UTC](https://discourse.pymc.io/t/vanilla-autoregressive-model/6325 "2020-11-30T04:35:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbuddy\_13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jbuddy_13/32/5900_2.png) [@jbuddy\_13](https://discourse.pymc.io/u/jbuddy_13)\
**Post date:** [November 30, 2020, 4:35am UTC](https://discourse.pymc.io/t/vanilla-autoregressive-model/6325/1 "2020-11-30T04:35:44Z")

</div>

I’m curious if someone has implemented a vanilla auto regressive model for time series. I know PyMC3 offers some classes tailored explicitly for time series. But I’m quite new to it and would like to start with something that has not abstracted any details away.

In other words, I’m looking for the simplest model possible. I believe the below is something I came across in a textbook.

Y\_i ~B1 \*X + B2 \* Y\_i-1

---

<div class="post-metadata">

**Author:** ![luisroque](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@luisroque](https://discourse.pymc.io/u/luisroque)\
**Post date:** [November 30, 2020, 3:16pm UTC](https://discourse.pymc.io/t/vanilla-autoregressive-model/6325/2 "2020-11-30T15:16:49Z")

</div>

You have a toy example below. You are lacking the error terms in your equation.

**Data generation process:**

```auto
N = 52*6
y = np.zeros((N,))

true_theta = 0.8
true_tau = 1.0
true_center = 0.0

true_beta = 0.5

x = np.sin(np.arange(N))

for t in range(1, N):
    y[t] = true_theta * y[t - 1] + np.random.normal(loc=true_center, scale=true_tau)

y = np.random.normal(y + true_beta * x, 1)
plt.plot(y);

```

**Model and results:**

```auto
with pm.Model() as model:
    theta = pm.Normal('theta', 0,0.5)
    beta = pm.Normal('beta', 0,0.5)
    
    tau = pm.HalfNormal('tau', 0.5)
    
    ar = pm.AR('ar', theta, tau, shape=N)
    sig = pm.HalfNormal('sig', 0.5)
    
    y_ = pm.Normal('y_', beta * x + ar, sig, observed=y)
    trace = pm.sample(2000)
az.summary(trace, var_names=['theta', 'beta', 'tau', 'sig'])

```

Hope it helps!

---

<div class="post-metadata">

**Author:** ![jbuddy\_13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jbuddy_13/32/5900_2.png) [@jbuddy\_13](https://discourse.pymc.io/u/jbuddy_13)\
**Post date:** [November 30, 2020, 3:31pm UTC](https://discourse.pymc.io/t/vanilla-autoregressive-model/6325/3 "2020-11-30T15:31:26Z")

</div>

Yes- you’re a wizard, thank you!
