stan-dev / example-models

Example models for Stan
http://mc-stan.org/
772 stars 479 forks source link

Error in BPA Ch.10 js_super.stan with possible fix #146

Closed njhostet closed 3 years ago

njhostet commented 5 years ago

js_super.stan line 222 uses (1 - z[i, t - 1]) instead of q for the recruitment process. A possible fix is to create and incorporate q into lines 216:222 (see js_rest_occ.stan lines 212:224 for similar example and also Kery and Schaub BPA pg 327). Possible fix is described below.

  // Generate w[] and z[]
  for (i in 1:M) {
  int q = 1;
  if (bernoulli_rng(psi)) {      // Included
      z[i, 1] = bernoulli_rng(nu[1]);
      for (t in 2:n_occasions) {
      q = q * (1 - z[i, t - 1]);
      z[i, t] = bernoulli_rng(z[i, t - 1] * phi[i, t - 1]
                                 + q * nu[t]);

This prevents dead individuals from recruiting back into the population.

ito4303 commented 5 years ago

Thank you for your comment. I confirmed this is really a bug and your proposal works fine. I will fix it by incorporating your proposal soon.