I have implemented a stan hierarchical model with level 1 within groups to be a linear model and level 2 within subjects Gaussian mixture model. It means the slope obtained from level 1 is used by level model GMM to cluster. When I run the model it has a convergence problem.
WARNING:pystan:Maximum (flat) parameter count (1000) exceeded:
skipping diagnostic tests for n_eff and Rhat. To run all diagnostics call pystan.check_hmc_diagnostics(fit)
WARNING:pystan:2 of 500 iterations ended with a divergence (0.4 %).
WARNING:pystan:Try running with adapt_delta larger than 0.8 to remove the divergences.
WARNING:pystan:Chain 1: E-BFMI = 0.0611
WARNING:pystan:E-BFMI below 0.2 indicates you may need to reparameterize your model
Any comments on improving the model?
multi_level_model = """
data {
int<lower=0> N; // No of observations
int J; // No of subjects
int<lower=1,upper=J> RID[N];
vector[N] x; // Cognitive measure
}
parameters{
real a;
vector[J] b;
real mu_b;
real<lower=0,upper=2> sigma_b;
# Gaussian Parameters for level 2
ordered[2] mu;
real<lower=0> sigma[2];
real<lower=0, upper=1> theta;
}
transformed parameters {
vector[N] y_hat;
for(i in 1:N)
y_hat[i] <- a + x[i] * b[RID[i]];
}
model {
sigma_b ~ normal(0, 1);
b ~ normal (mu_b, sigma_b);
a ~ normal (0, 1);
sigma ~ normal(0, 1);
mu ~ normal(0, 1);
theta ~ beta(5, 5);
for (n in 1:J)
target += log_mix(theta,
normal_lpdf(b[n] | mu[1], sigma[1]),
normal_lpdf(b[n] | mu[2], sigma[2]));
}
"""