# How to write & evaluate state space model in PyMC4

**URL:** <https://discourse.pymc.io/t/how-to-write-evaluate-state-space-model-in-pymc4/2080>\
**Category:** Development\
**Created:** [October 21, 2018, 12:47pm UTC](https://discourse.pymc.io/t/how-to-write-evaluate-state-space-model-in-pymc4/2080 "2018-10-21T12:47:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiangze](https://avatars.discourse-cdn.com/v4/letter/x/fbc32d/32.png) [@xiangze](https://discourse.pymc.io/u/xiangze)\
**Post date:** [October 21, 2018, 12:47pm UTC](https://discourse.pymc.io/t/how-to-write-evaluate-state-space-model-in-pymc4/2080/1 "2018-10-21T12:47:57Z")

</div>

I’m tring to write down state space model in PyMC4 and sample posterior distributions of parameters as in PyMC3.  
But the acceptance ratio of all variables are 0 and chain values do not change.  
Is there some mistake in this code?

```python

data=pd.read_csv("https://raw.githubusercontent.com/statsmodels/statsmodels/master/statsmodels/datasets/nile/nile.csv",index_col='year',)
N=len(data)
datay=np.array(data["volume"])

model = pm.Model(N=N, y=datay)

@model.define
def st(cfg):    
    mu0 = ed.Normal(name='muZero', loc=0.0, scale=1.0)
    sigmaW = ed.InverseGamma(name='sigmaW', concentration=1.0, rate=1.0)    
    sigmaV = ed.InverseGamma(name='sigmaV', concentration=1.0, rate=1.0)
    
    y=[0]*cfg.N
    mu =[0]*cfg.N
    mu[0] = ed.Normal(name='mu0', loc=mu０, scale=sigmaW)
    for n in range(1, N):
        mu[n] = ed.Normal(name='mu'+str(n), loc=mu[n-1], scale=sigmaW)    
    for n in range(N):
        y[n]= ed.Normal(name='y'+str(n), loc=mu[n], scale=sigmaV)
    
    return y

trace = pm.sample(model)

```

> <https://gist.github.com/xiangze/c76ce89bf354ba6d636abd7c5e78938e>

---

<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:** [October 21, 2018, 9:39pm UTC](https://discourse.pymc.io/t/how-to-write-evaluate-state-space-model-in-pymc4/2080/2 "2018-10-21T21:39:00Z")

</div>

At this point PyMC4 is more of a prototype and I would expect many bugs. If you don’t want to actively develop the package I would stick to PyMC3 which we will continue to support.
