Bayes Factor using Bridgesampling for mark-recapture model

Hi all,

I have a mark recapture model that is very similar to the model found on page 105 of the Stan User’s Guide. The model allows me to code for individual effects; However, I am unsure whether I have coded it right to using the bridgesampling package in R to estimate posterior probabilities. According to the paper associated with the bridgesamplingg package, the “models need to be implemented in a way that retains the constants” using target +=. I am not sure how to do this in the model as specified in the manual, which looks like this:

    model {for (i in 1:I) 
        {if (first[i] > 0) {
            for (t in (first[i]+1):last[i]) {
                1 ~ bernoulli(phi[t-1]);
                y[i, t] ~ bernoulli(p[t]);
            }
            1 ~ bernoulli(chi[last[i]]);
         }
        }
    }

I know this is not a lot to go on, so I apologize in advance.

Retaining the constants means writing

target += distr_lpdf(y|...);

instead of

y ~ distr(...);

In your case (although I don’t think it actually matters for bernoulli)

model {
  for (i in 1:I) {
    if (first[i] > 0) {
      for (t in (first[i]+1):last[i]) {
        target += bernoulli_lpmf(1|phi[t-1]);
        target += bernoulli_lpmf(y[i, t]|p[t]);
      }
      target += bernoulli_lpmf(1|chi[last[i]]);
    }
  }
}
1 Like

Thanks. I reran my code with your suggested edits, and as you stated, it didn’t actually matter.