Folks, I am trying to estimate a state space model on some simulated data taken from the nimble manual.
I want to get any feedback on how to improve the model to recover the parameters better.
The data is simulated as below:
t <- 25; mu_0 <- 1
x <- rnorm(1 ,mu_0, 1)
y <- rnorm(1, x, 1)
a <- 0.5; b <- 1; c <- 1
for(i in 2:t){
x[i] <- rnorm(1, x[i-1] * a + b, 1)
y[i] <- rnorm(1, x[i] * c, 1)
}
The stan code used:
// non-centered version
data {
int <lower=0> T;
real x[T];
real y[T];
}
parameters {
real u_err[T];
real <lower=0> s_obs;
real <lower=0> s_level;
real<lower=0, upper=1> a;
real b;
}
transformed parameters {
real u[T]; //Level
u[1] = u_err[1];
for (t in 2:T) {
u[t] = a * u[t-1] + b + s_level * u_err[t] ;
}
}
model {
u_err ~ normal(0,1);
y ~ normal(u,s_obs);
}
I have ignored estimating the c parameter here.
I run this code with defaults, 4000 iterations per chain and adapt_delta=0.9999 with the following warnings:
There were 2 divergent transitions after warmup. Increasing adapt_delta above 0.9999 may help. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmupThere were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
http://mc-stan.org/misc/warnings.html#bfmi-lowExamine the pairs() plot to diagnose sampling problems
I get the following results:
4 chains, each with iter=4000; warmup=2000; thin=1;
post-warmup draws per chain=2000, total post-warmup draws=8000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
a 0.27 0.00 0.21 0.01 0.09 0.21 0.39 0.78 1871 1.00
b 1.51 0.01 0.46 0.45 1.22 1.59 1.85 2.20 2168 1.00
s_level 0.34 0.01 0.26 0.01 0.13 0.29 0.51 0.94 411 1.01
s_obs 0.83 0.01 0.22 0.25 0.72 0.84 0.96 1.24 308 1.01
Samples were drawn using NUTS(diag_e) at Tue Aug 28 15:15:21 2018.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
The parameter estimates are somewhat off with expected values of
- a=0.50,
- b=1, and
- s_level / s_obs = 1.
Hoping that I can improve the code.
Thanks.
Raghu