Closed yu-zhang-oYo closed 4 years ago
You need to write the model in a way that retains all constants, as described in this article. This produces the correct value.
model {
target += beta_lpdf(theta | 1, 1);
target += binomial_lpmf(y | N, theta);
}
I try to calculate the marginal likelihood of the example in the article " a tutorial on bridge sampling", which is estimating the marginal likelihood for a binomial model assuming a uniform prior on the rate parameter θ (i.e., the beta-binomial model). Consider a single participant who answered k = 2 out of n = 10 true/false questions correctly. The analytical result is 1/(n+1), that is 1/11.
And Then I get a stanfit with rstan, and use bridge_sampler(stanfit) to get the log marginal likelihood. After transforming the log marginal likelihood to the marginal likelihood, I find it is totally different from 1/11. I don't know the reason for this.