# Model convergence issues with growth curve model

**URL:** <https://discourse.mc-stan.org/t/model-convergence-issues-with-growth-curve-model/34356>\
**Category:** Modeling\
**Tags:** rstan, fitting-issues, specification\
**Created:** [March 6, 2024, 12:58am UTC](https://discourse.mc-stan.org/t/model-convergence-issues-with-growth-curve-model/34356 "2024-03-06T00:58:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxyaks](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@oxyaks](https://discourse.mc-stan.org/u/oxyaks)\
**Post date:** [March 6, 2024, 12:58am UTC](https://discourse.mc-stan.org/t/model-convergence-issues-with-growth-curve-model/34356/1 "2024-03-06T00:58:15Z")

</div>

I am trying to estimate a growth curve model, however, despite numerous attempts I have not been able to optimise the model. I keep getting the following warnings:

1: There were 6349 divergent transitions after warmup. See  
[https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup](https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup)  
to find out why this is a problem and how to eliminate them.  
2: Examine the pairs() plot to diagnose sampling problems

3: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.  
Running the chains for more iterations may help. See  
[https://mc-stan.org/misc/warnings.html#bulk-ess](https://mc-stan.org/misc/warnings.html#bulk-ess)

```no-highlight
data {
  int<lower=1> N; // Number of respondents
  int<lower=1> T; // Number of time periods
  matrix[N, T] Y; // Outcome variable matrix
  matrix[N, T] M; // Mediator variable matrix
  real<lower=0> time[N, T]; // Time values
  vector[N] W; // Moderator variable vector
}

parameters {
  vector[N] alpha_raw; // Raw intercept for each individual
  vector[N] beta_raw; // Raw slope for each individual
  real beta_mediator; // Coefficient for mediator variable
  real<lower=0> sigma; // Residual standard deviation
  real<lower=0> sigma_alpha; // Prior std for alpha
  real<lower=0> sigma_beta; // Prior std for beta
  real<lower=0> sigma_med; // Prior std for mediator
  real<lower=0> sigma_growth; // Prior std for growth parameters
  real growth; // Growth parameter
}

transformed parameters {
  vector[N] alpha; // Transformed intercept for each individual
  vector[N] beta; // Transformed slope for each individual

  alpha = alpha_raw * sigma_alpha;
  beta = beta_raw * sigma_beta;
}

model {
  // Priors
  alpha_raw ~ normal(0, 1); // Prior for raw intercept
  beta_raw ~ normal(0, 1); // Prior for raw slope
  beta_mediator ~ normal(0, sigma_med); // Prior for mediator coefficient
  sigma ~ cauchy(0, 2.5); // Prior for residual standard deviation
  growth ~ normal(0, sigma_growth); // Prior for growth parameter

  // Likelihood
  for (n in 1:N) {
    for (t in 1:T) {
      real mu;
      mu = alpha[n] + beta[n] * time[n, t] + beta_mediator * M[n, t] + growth * time[n, t] + W[n];
      Y[n, t] ~ normal(mu, sigma);
    }
  }
}

generated quantities {
  // Extracting the log-likelihood for diagnostics
  vector[N * T] log_lik;
  int idx = 1;
  for (n in 1:N) {
    for (t in 1:T) {
      log_lik[idx] = normal_lpdf(Y[n, t] | alpha[n] + beta[n] * time[n, t] + beta_mediator * M[n, t] + growth * time[n, t] + W[n], sigma);
      idx += 1;
    }
  }
}

```

I appreciate any and all help with this. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Corey.Plate](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/corey.plate/32/20600_2.png) [@Corey.Plate](https://discourse.mc-stan.org/u/Corey.Plate)\
**Post date:** [March 12, 2024, 4:15pm UTC](https://discourse.mc-stan.org/t/model-convergence-issues-with-growth-curve-model/34356/2 "2024-03-12T16:15:13Z")

</div>

The `sigma_med` and `sigma_growth` standard deviations of the normal distributions are uniform improper priors with support over the range [0,inf). That leaves the mediator multipliers, `beta_mediator` and `growth`, pretty much unconstrained over (-inf,inf). `alpha` and `beta` are similarly each the product of parameters drawn from a normal and an improper uniform prior with support over [0,inf), where `alpha` is an additivie term and `beta` is yet another multiplier in the linear function that defines `mu`. That leaves the prior on `Y` with a mean that has a pretty much unconstrained domain over (-inf,inf), and a standard deviation, `sigma`, that is drawn from the heavy-tailed cauchy distribiution.

I am not a modeling expert, but you haven’t been answered in a while and this strikes me as a posterior geometry that the sampler would have a very hard time with.
