Can anyone of you help me out diagnosing the problem with this simple example model and maybe give some on advice on how to fix it ?
It gives me a bunch of divergent transitions. Funnel like correlations and a highly curved posterior are apparent but I don't really get where those correlations come from.
Maybe I can implement the noncentered paramterization in a different way?
Thanks in advance,
Jökull
nonCentered <- "
data {
int<lower=1> Ntotal;
vector[Ntotal] pred;
vector[Ntotal] pred2;
vector[Ntotal] y;
}
parameters {
real<lower=0.0> sigma;
real<lower=0.0> sigma_w;
real<lower=0.0> sigma_w2;
real mu;
real w_raw;
real w_raw2;
}
transformed parameters {
real w;
real w2;
vector[Ntotal] y_mu;
for (n in 1:Ntotal) y_mu[n] = 0.0;
w = sigma_w * w_raw + mu;
w2 = sigma_w2 * w_raw2 + mu;
y_mu = w * pred + w2 * pred2;
}
model {
sigma_w ~ normal(1,1);
sigma_w2 ~ normal(1,1);
sigma ~ normal(1,1);
mu ~ normal(1,0.2);
w_raw ~ normal(0, 1);
w_raw2 ~ normal(0, 1);
y ~ normal(y_mu,sigma);
}
"
fit <-
stan(
model_code = nonCentered,
data = list(pred = c(0,2,0,0,2,0,0,2,0),
pred2 = c(1,0,1,1,0,1,1,0,1),
Ntotal =9, y = c(3,2,3,3,2,3,3,2,3)),
model_name = 'example',
iter = 1200,
chains = 2
)