Time series model fitting issue

Hello Stan community.
I am trying to model the following model in rstan:

y_{t}=f_{t} + \sigma*e_{t}
f_{t} = u_{t}*\sqrt{h_{t}}
h_{t}=\alpha +\beta *f_{t-1}^{2}

where e,u~N(0,1). My stan code for the latter model is the following:

data {
  int<lower=0> T;   
  vector[T] y;      
}
parameters {
  real <lower=0> alpha; 
  real<lower=0,upper=1> beta1;  
  real<lower=0> sigma;         
  real x0;
  vector[T] x;               
}

transformed parameters {
  real <lower=0> h[T];
  h[1]=sqrt(alpha + beta1 *pow(x0,2));
   for (t in 2:T)
    h[t]= sqrt((alpha +beta1*pow(x[t-1],2)));
  }

model {
 alpha ~ normal(0,10);
  beta1 ~ uniform(0,1);
 sigma ~ cauchy(0, 5);
 x0  ~ normal(0,1); 
 x ~ normal(0,h);
 y ~ normal(x, sigma);
}

With the code in R below i am generating 1500 sets of simulated data and then trying to fit the model with my STAN model.

set.seed(1)
T <- 1500 
alpha=0.1
beta0=0.8
sigma=0.02

f<- rep(0, T)
y<-rep(0,T)

f[1]=rnorm(1);

for (t in 2:T)
  f[t] <- rnorm(1, 0, sqrt(alpha + beta0 * (f[t - 1]^2)))
for (t in 1:T)
  y[t] <- rnorm(1, f[t], sigma)

The purpose here is to compare the prior and the posterior values of parameters alpha, beta and sigma. The problem is that the model is not fitting regardless of the number of iterations i choose to sample.
Do you have any suggestions for a rookie user?

1 Like

Are you trying to do some kind of garch structure on the mean parameter?

Yes but actually it’s an ARCH model called Unobserved Arch (Or latent ARCH)

Do you have some references?! I really wanna read them (sorry I love time series :) )

Well, I am also running it! And the model has some problems mixing!
Stochastic volatility models have the same problems too! So maybe using more iteration could help. You can read Stan’s SVM post here

I change the priors as well, for example instead of a uniform I use a beta(2,2), and in alpha, a normal(0,1) might be enough. Even so, some x or h parameters are still not mixing, my credible intervals capture the real values in all my simulations. You should get more info of how selecting prior in the Stan’s prior choice recommendations

My code is here: Stantry3.stan (532 Bytes)

I just simulate some time series of 500 observations each and run 1 chain of 5000 iterations using this:

test = list(T = 1,y = y)

sf1 = sampling(object = smodel,data = test,chains = 1,
    iter = 5000,control = list(adapt_delta = 0.8),
    pars = c("x","h"),include = FALSE)

So it might help!

Also try to increase the data variance, in your experiment is practically 0.

When I try your experiments with sigma = 0.2. The sampling does not complains that much! :)

Thank you.
I corrected my model and running it for 50.000 iterations. Waiting for results…

Meanwhile check:
https://www.researchgate.net/publication/255665327_Bayesian_Estimation_of_Change-Point_in_Unobserved-ARCH_Models

50,000? Is not too much?!

10000 iterations and 4 chains are mixing perfectly.
Only got a warning message about low bfmi.
Thank you very much for your help

Sounds good!

Ohh I am keep doing experiments and trying a transformations cause I dont ilke the bfmi warning! And I think I almost got it! So I post you later with the updated and checked model.