# Simple model that converges in JAGS but not in Stan

**URL:** <https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797>\
**Category:** Modeling\
**Created:** [May 12, 2019, 7:07pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797 "2019-05-12T19:07:06Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 12, 2019, 7:07pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/1 "2019-05-12T19:07:06Z")

</div>

Dear All,

I am a relatively new user of Stan struggling with stable behavior of a model that works well with no problems in JAGS. I am wondering if the performance/behavior is linked somehow to the way I wrote the code in Stan. I would appreciate if you could help me with that problem.

The model contains regularly spaced missing observations, and both JAGS and San’s versions account for that.

The variance between observations increases and collapses along with occurrence of the new, consequent observation.

 ![Var](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/d/d0c163ae3fa16e224b9e9ae3db42874e2f5109d0.png)

**JAGS model** :

```
    Model= "model{
        for(i in 2:N0){
          FACTOR1[i] ~ dnorm(FACTOR1[i-1],TAU[i])
       } }"

```

 ![JAGS](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/0/00ebe43e03486585b903d999cb6c5aeab331f2eb.png)

(in all plots gray lines represent 80% confidence interval)

**Stan Model:**

```
data {
  int<lower=1> N0;
  vector[N0] Factor1_0;
  int FCT1_NA_COUNT;
  int FCT1_NA_INDEX[FCT1_NA_COUNT]; 
  vector[N0] FACTOR1_SD;
}
parameters {
  vector<lower=0.3, upper=1.7>[FCT1_NA_COUNT] FCT1_MISSING;
}
transformed parameters {
  vector[N0] FACTORS; 
  FACTORS = Factor1_0; FACTORS[FCT1_NA_INDEX] = FCT1_MISSING;
}
model {
  for(i in 2:N0){
        #FACTORS[i] ~ normal(FACTORS[i-1],0.04); // Version 1
        FACTORS[i] ~ normal(FACTORS[i-1],FACTOR1_SD[i]); // Version 2
  }   
  }

```

Version 1 of the Stan’s code is relatively stable, fast and yields expected results (but not the results that I am trying to model). The 2nd version with the increasing variances (all are below 0.04) doesn’t converge, and simulations don’t produce the expected behavior (I’ll include some plots to present that.

Stan Version 1:

 ![STAN_VER1](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/2/24d13b91a3462c2e7fa80ea5137bf1606d828c9f.png)

Stan Version 2:

 ![STAN_VER2](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/1/1508b8d0bc46badf33deb74980ba611620c87bc9.png)  
Thank you very much in advance for all your help.

Regards  
Peter

[edit: escape model code]

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [May 14, 2019, 6:54pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/2 "2019-05-14T18:54:50Z")

</div>

Are all the FACTOR1\_SDs \> 0?

If so, maybe try adding a bit of extra noise to maybe experiment and see if just being close to zero is causing numerical issues?

Can you post the data for this? I’m not seeing from the plots which data points you have and which are missing, which looks important for interpreting FACTOR1\_SD.

---

<div class="post-metadata">

**Author:** ![Matthijs](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/matthijs/32/718_2.png) [@Matthijs](https://discourse.mc-stan.org/u/Matthijs)\
**Post date:** [May 14, 2019, 8:47pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/3 "2019-05-14T20:47:30Z")

</div>

> [@PeterMax](#):
>
> vector[N0] FACTOR1\_SD;

Wait, shouldn’t that be

```no-highlight
vector<lower=0>[N0] FACTOR1_SD;

```

?

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [May 15, 2019, 7:17pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/4 "2019-05-15T19:17:25Z")

</div>

Since the post talks about variance, I just want to make it clear that JAGS uses precision (inverse variance) and Stan uses scale (standard deviation) to parameterize the normal.

Can you share the JAGS version and data that converges? Why are the `FCT1_MISSING` given those hard interval bounds? Did you first try without that? That can be a real problem computationally and statistically if the missing values are consistent with values near the boundaries.

Finally, you can doe the random walk as

```
FACTORS[2:N0] ~ normal(factors[1:N0 - 1], FACTOR1_SD[2:N0]);

```

but you’d probably just want to just define `FACTOR1_SD` as not having that first element rather than having to slice it each time, given that it’s data. Or you could transform in transformed data to define:

```
transformed data {
  vector[N0 - 1] sigma = FACTOR1_SD[2:N0];

...
model {
  FACTORS[2:N0] ~ normal(FACTORS[1:N0 - 1], sigma);

```

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 16, 2019, 6:59pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/5 "2019-05-16T18:59:36Z")

</div>

Hello Ben again!

Thanks for your time. I think this could be one of factors, but what I realized is that there is some problem with implementation of the model in Stan.

data {  
int\<lower=1\> N0;  
vector[N0] Factor1\_0;  
int FCT1\_NA\_COUNT;  
int FCT1\_NA\_INDEX[FCT1\_NA\_COUNT];  
vector[N0] FACTOR1\_SD;  
int\<lower=1\>N0\_DATA;  
int FACTOR1\_DATA\_IDX[N0\_DATA];

}  
parameters {  
vector\<lower=0.3, upper=1.7\>[FCT1\_NA\_COUNT] FCT1\_MISSING;  
}  
transformed parameters {  
vector[N0] FACTORS;  
FACTORS = Factor1\_0; FACTORS[FCT1\_NA\_INDEX] = FCT1\_MISSING;  
}  
model {  
FACTORS[2:N0] ~ normal(FACTORS[1:N0 - 1], 0.2);  
}

If i increase the standard deviation of the model to 0.2 I am getting the following:  
 ![Capture](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/a/a83d8442bb53ab025addd2570cde371951d4734c.png)

As you might see the median of the realizations (the black line) approaches 1.

Nota bene: the upper gray line represents 90% CI, the lower 10% CI.

I enclose the data and programs both in JAGS and Stan (please note that you would need to update links to files within the code).

[00.SP500OHLCV.csv](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/d/da46fd9304f6a3cfa61de2c7c09c8e1ca24bb11e.csv) (1.2 MB)  
[JAGS\_ver.R](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/5/548ac0e2439527c807fba24ffe1bcd69fad30407.R) (1.9 KB)  
[Stan.R](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/1/1c27cc635dc8999bc83e9b6717d0641bc68e99db.R) (4.3 KB)  
[Stan.stan](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/0/085a8fc5374ecbf543eea78ca1f7ae872b7b24e5.stan) (464 Bytes)  
[WILSHIRE\_GNP.csv](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/e/ec9b98c23115dc86036cf8490b6d812cb22c03a4.csv) (4.4 KB)

Thanks you a lot,

Kind Regards  
Peter

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 16, 2019, 7:00pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/6 "2019-05-16T19:00:47Z")

</div>

Hello Matthijs,

I updated that in the code, thanks!

Kind Regards  
Peter

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 16, 2019, 8:05pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/7 "2019-05-16T20:05:13Z")

</div>

> [@Bob\_Carpenter](#):
>
> FCT1\_MISSING

Hello Bob,

Thank you for replying. I apply precision in JAGS, and the code is enclosed in my response to Ben.

FCT1\_MISSING - my guess is that this is potentially the hart of the problem, but honestly I have some problems with correct implementation. One of versions:

data {  
int\<lower=1\> N0;  
vector[N0] Factor1\_0;  
int FCT1\_NA\_COUNT;  
int FCT1\_NA\_INDEX[FCT1\_NA\_COUNT];  
vector[N0] FACTOR1\_SD;  
int\<lower=1\>N0\_DATA;  
int FACTOR1\_DATA\_IDX[N0\_DATA];

}  
parameters {  
vector\<lower=0.3, upper=1.7\>[N0] FCT1\_MISSING;  
}  
transformed parameters {  
vector[N0] FACTORS;  
FACTORS = Factor1\_0;  
FACTORS[FCT1\_NA\_INDEX] = FCT1\_MISSING[FCT1\_NA\_INDEX];  
}  
model {  
FCT1\_MISSING[2:N0] ~ normal(FACTORS[1:N0 - 1], 0.2);  
}

 ![Capture](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/0/04d7777fa24bc67a722af4f99e88e6f6b05dee06.png)

Which puzzles me a lot.  
For simplicity I replaced FACTOR1\_SD\_t with 0.2, to have a closer look on the implementation.

Without missing I receive no parameters from the simulation.

The advice about the compact version of the random was was spot on - thanks!!!

Best Regards  
Peter

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [May 20, 2019, 11:59pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/8 "2019-05-20T23:59:15Z")

</div>

Real quick, what is the end goal here?

If you’re fitting a time series and want to get estimates of what is happening between points, usually this looks a lot more like a prediction sort of thing than a missing value thing.

So you fit a curve to all the red points and then predict the things in the middle.

Right now what is happening in the plots is kinda weird. Between the red points, the medians drift back to be near 1 and seem to ignore whatever data is on either side of them. This doesn’t seem like the usual assumption for time series.

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 21, 2019, 8:49pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/9 "2019-05-21T20:49:40Z")

</div>

> [@bbbales2](#):
>
> the plots is kind

Hello Ben,

Thank you for your response. I agree this looks very strange, and I would not expect to see that given the specification of the model .

The idea is to estimate points between the known observations (red dots), that are being used in evaluation of an integral in the later part of the code. The unobservable points are known by market participants to certain extent, as they are function of a monthly GNP and daily SP500 (knowing the direction of SP500 gives some idea of where the observable points can be).

I applied two other approaches:

1. regression using SP500 as an explanatory variable - deviations of the red dots from the median are too big to be of practical use.
2. I applied splines - in this case the model is fast if we have exactly the same number of days between observations, but in practice this is not the case as small differences in number of points between observations requires increasing max\_treedepth - given complexity of the overall program this slows down the process substantially.

The most realistic model that I see here is presented in the 2nd plot from the top. Would you have some other suggestions of how to make that code in Stan working?

Thank you again for your help

Kind Regards  
Peter

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [May 21, 2019, 11:15pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/10 "2019-05-21T23:15:19Z")

</div>

If the splines weren’t flexible enough, have you looked at GPs? Does the second picture in Figure 2.2 of [http://www.gaussianprocess.org/gpml/chapters/RW2.pdf](http://www.gaussianprocess.org/gpml/chapters/RW2.pdf) seem interesting? That looks similar to the second plot from the top and you can do this in closed form.

How many days of data and such? Is it 5 data points over 250 days?

What are your goals beyond just fitting this data?

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [May 21, 2019, 11:16pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/11 "2019-05-21T23:16:55Z")

</div>

Also depending on what your data is, there’s a time series package for sales sorta data you might play with: [https://facebook.github.io/prophet/](https://facebook.github.io/prophet/)

And here are some fun plots with it: [https://twitter.com/seanjtaylor/status/1123278380369973248](https://twitter.com/seanjtaylor/status/1123278380369973248)

---

<div class="post-metadata">

**Author:** ![JulianK](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@JulianK](https://discourse.mc-stan.org/u/JulianK)\
**Post date:** [May 24, 2019, 4:15am UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/12 "2019-05-24T04:15:56Z")

</div>

The reason that your black lines curve up is because you’ve specified a prior on `FCT1_MISSING` in the range 0.3 to 1.7. This centre of this range is (0.3+1.7)/2 = 1.0, so you see that your prior encourages the lines to go towards 1.0.

Why do you have this prior?

If you simply remove the bounds on FCT1\_MISSING and replace 0.2 with `sigma`, defined as a parameters `real<lower=0> sigma` then you’ll have a standard random walk model.

In the earlier post, I can’t understand why you pass `FACTOR1_SD` in as data, and similarly why you have a different standard deviation for every time point. How can you know this before in a way that’s consistent with your data points?

I think that you are confused about how a random walk is modelled. You don’t specify individual standard deviations for each point. The graph you’ve drawn first about the variance profile is not correct - the variance does not “collapse back to zero”. If your data follow a random walk then knowing a value at time T+1 places a constraint on the value at time T.

Have a look at [Brownian bridge on Wikipedia](https://en.wikipedia.org/wiki/Brownian_bridge) - if you have a standard Brownian motion (ie continous time random walk where the value of the process is fixed at time 0 and time T) then the variance is t\*(T-t)/T, a concave down parabola with values zero at times t and T. The variance is maximal half way between the two points. It looks nothing like the graph you have first shown.

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 26, 2019, 8:05pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/13 "2019-05-26T20:05:48Z")

</div>

Hello Ben,

Thank you again. This looks indeed very close to what I am looking for. I started working on the implementation, but I have also found figure 9 in the paper [http://www.robots.ox.ac.uk/~sjrob/Pubs/philTransA\_2012.pdf](http://www.robots.ox.ac.uk/~sjrob/Pubs/philTransA_2012.pdf)  
but I ma not sure yet which kernel is capable of generating such process.

Thanks and Regards  
Peter

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 26, 2019, 8:07pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/14 "2019-05-26T20:07:05Z")

</div>

This is very helpful,

Thank you!

Regards  
Peter

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [May 27, 2019, 3:00pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/15 "2019-05-27T15:00:20Z")

</div>

Make sure and check out @JulianK 's response.

Figure 9 in that book might have to do with the difference in what this book calls filtering vs. smoothing: [https://users.aalto.fi/~ssarkka/pub/cup\_book\_online\_20131111.pdf](https://users.aalto.fi/~ssarkka/pub/cup_book_online_20131111.pdf)

In filtering you make predictions about time t based on everything that came before. In smoothing you use information from both directions.

Plots of filtering effects can be kinda deceiving, cause they’re really plots of a bunch of different modes (one model including n points, one with n + 1, etc.). The smoothing models use all the data to inform all the inferences.

When you use GPs to interpolate data, they look like smoothers.

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 27, 2019, 8:56pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/16 "2019-05-27T20:56:01Z")

</div>

> [@JulianK](#):
>
> I think that you are confused about how a random walk is modelled. You don’t specify individual standard deviations for each point. The graph you’ve drawn first about the variance profile is not correct - the variance does not “collapse back to zero”. If your data follow a random walk then knowing a value at time T+1 places a constraint on the value at time T.
> 
> Have a look at [Brownian bridge on Wikipedia](https://en.wikipedia.org/wiki/Brownian_bridge) - if you have a standard Brownian motion (ie continous time random walk where the value of the process is fixed at time 0 and time T) then the variance is t\*(T-t)/T, a concave down parabola with values zero at times t and T. The variance is maximal half way between the two points. It looks nothing like the graph you have

Hello Julian,

Apologies for the late response. I agree with the points you’ve raised. How do I know the prior have those limits - histrionically they’ve never been exceeded, and I would think that it is highly unlikely that they will ever be exceeded. Having said that 0.2 SD was unrealistic, for the purpose of the simulation, and I admit I was a little bit confused by this plot.  
Increasing variance - I overlooked that, initially I tried to apply a simplified model using na.locf and increasing variances.

Brownian Bridge - I considered that earlier on, but it won’t work well in this case - please see the figure 9 in the paper [http://www.robots.ox.ac.uk/~sjrob/Pubs/philTransA\_2012.pdf](http://www.robots.ox.ac.uk/~sjrob/Pubs/philTransA_2012.pdf)

Thanks a lot  
Peter

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [May 27, 2019, 8:57pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/17 "2019-05-27T20:57:38Z")

</div>

> [@bbbales2](#):
>
> he smoothing models use all the data to inform all the inferences.
> 
> When you use GPs to interpolate data, they look like smoothers.

Thank you Ben, I’ll explore that.

Best Regards  
Peter

---

<div class="post-metadata">

**Author:** ![JulianK](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@JulianK](https://discourse.mc-stan.org/u/JulianK)\
**Post date:** [May 28, 2019, 2:05am UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/18 "2019-05-28T02:05:27Z")

</div>

You don’t need Gaussian processes for this. You’re overthinking the problem.

Here’s my modifications to your code, which:

- Estimate the process variance, rather than passing it in, and
- Remove the priors on the values.

```
  int<lower=1> N0;
  vector[N0] Factor1_0;
  int FCT1_NA_COUNT;
  int FCT1_NA_INDEX[FCT1_NA_COUNT]; 
  vector[N0] FACTOR1_SD;
  int<lower=1>N0_DATA;
  int FACTOR1_DATA_IDX[N0_DATA];
  
}
parameters {
  vector[FCT1_NA_COUNT] FCT1_MISSING;
  real<lower=0> sigma;
}
transformed parameters {
  vector[N0] FACTORS;
  
  // Populate the actual data
  for(i in 1:N0_DATA){
    FACTORS[FACTOR1_DATA_IDX[i]] = Factor1_0[FACTOR1_DATA_IDX[i]];
  }
  // Populate the missing data 
  for(i in 1:FCT1_NA_COUNT){
    FACTORS[FCT1_NA_INDEX[i]] = FCT1_MISSING[i];
  }
}
model {
   FACTORS[2:N0] ~ normal(FACTORS[1:N0 - 1], sigma);
}

```

Then here’s your plot with 10k iterations of sampling.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/48bc13c263d7e706764fcc37a823c518366e4310.png)

Works just find, and this is exactly what you expect for a random walk model.

You’re misunderstanding figure 9 in that paper that’s referred to. That’s talking about how the forecast prediction variance evolves UNTIL a data point is seen. That’s the behaviour you see to the right of the right most data point in the graph above. There’s a big difference between the likelihood of the model (ie that there is a random walk at each time step) and the _posterior_ uncertainty. Figure 9 DOES NOT show the posterior uncertainty of the model at a given time step in the case when there is another data point to the right.

Read the caption on that figure: " The GP is run sequentially making forecasts until a new datum is observed. Once we make an observation, the posterior uncertainty drops to zero (assuming noiseless observations)". This figure describes the forecast behaviour in the absence of data vs when data exists.

---

<div class="post-metadata">

**Author:** ![PeterMax](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/petermax/32/4452_2.png) [@PeterMax](https://discourse.mc-stan.org/u/PeterMax)\
**Post date:** [June 9, 2019, 10:08pm UTC](https://discourse.mc-stan.org/t/simple-model-that-converges-in-jags-but-not-in-stan/8797/19 "2019-06-09T22:08:37Z")

</div>

> [@JulianK](#):
>
> n observation, the posterior uncertainty drops to zero (assuming noiseless obse

Hello Julian,

Thank you. This yields exactly like one of my codes in JAGS. On the top of my transition to Stan, I had some problems with implementation of AR(1) with intercept for some reasons - the results I was getting definitely did not look right. Extending your code to AR(1) with intercept is straightforward and solves my problem.

The only discomfort I have here concerns increasing treedepth, but I guess nothing can be done to resolve this apart form increasing the treedepth above 10.

Warning messages:  
1: There were 206 transitions after warmup that exceeded the maximum treedepth. Increase max\_treedepth above 10.

IO use 4k warmup, 10k sims.

I agree this case requires a simple model. Thank you so much.

Kind Regards  
Peter
