0

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])); 

}
   """
merv
  • 67,214
  • 13
  • 180
  • 245
ADITYA
  • 1
  • 1
  • 1
    My first guess would be that `sigma_a`, `sigma_b`, `sigma[1]` and / or `sigma[2]` has posterior mass near zero or one, in which case you will get a funnel-like shape in the unconstrained space. Second, I you might ultimately need an uncentered parameterization for `a` and / or `b` where for example `real a = mu_a + sigma_a * a_raw;` is in the transformed parameters block and `real a_raw` is in the parameters block. Third, it looks like your mixture is equivalent if you flipped the order of the two components, in which case the posterior distribution is bimodal and needs more structure. – Ben Goodrich Jan 29 '19 at 15:33
  • It's strange to set a normal prior on the standard deviations. The standard deviations are positive parameters. – Stéphane Laurent Jun 03 '19 at 12:37

0 Answers0