# Metropolis algorithm to Bernoulli likelihood and beta prior (Kruschke 7.3.1)

This question pertains to a specific line written in the book Doing Bayesian Data Analysis by John K. Kruschke.

In section 7.3.1, he applies Metropolis algorithm to a case with: $$prior = beta(\theta|1,1), N = 20,$$ and $$z = 14$$. Then he proposes jumps with $$normal(0, \sigma)$$ where $$\sigma$$ can be 0.02, 0.2 or 2.

When $$\sigma = 0.2$$ he writes that jump is between +-0.2 for 68% of the time(which I understand) and proposed jumps are accepted roughly half the time as $$N_{acc}/N_{pro} = 0.495$$. I do not understand this - how do I get to this result.

• Are you sure it's not an empirical result? – jbowman Oct 25 '18 at 18:11
• @jbowman, I am not sure, he just says, author has not written whether it is empirical or mathematical. – Gaurav Singhal Oct 29 '18 at 13:57

Since you do not provide the likelihood, let us assume that $$Z|\theta$$ is a Binomial $$\mathcal{B}(20,\theta)$$ variate and its realisation is $$z=14$$. The posterior distribution on $$\theta$$ is then a Beta $$\mathcal{B}e(15,7)$$ [for which MCMC is not required].

If running a Normal random walk proposal for simulating this target, the moves are accepted with probability $$\min\left\{ \dfrac{\pi(\theta')}{\pi(\theta_t)},1\right\}$$ where $$\pi(\cdot)$$ is the density of the Beta $$\mathcal{B}e(15,7)$$. This means running a code like

T=1e4
p=rep(runif(1),T)
for (t in 2:T){
p[t]=prop=p[t-1]+rnorm(1,sd=.2)
if ((prop<0)|(prop>1)|(runif(1)>dbeta(prop,15,7)/dbeta(p[t-1],15,7)))
p[t]=p[t-1]}
length(unique(p))/T


which returns 0.4862 in my case

• Thanks for the answer, as mentioned in the title it is "Bernoulli Likelihood". I do understand the empirical result, waiting if someone can prove theoretically. – Gaurav Singhal Oct 29 '18 at 13:56