# Calculating acceptance probability in Metropolis-Hastings algorithm

In the Metropolis-Hastings algorithm, acceptance probability is given as $$\alpha = \min \left( 1,\frac{f(\theta^{'}|y)q(\theta|\theta^{'})}{f(\theta|y)q(\theta^{'}|\theta)} \right)$$ which simplifies to $$\alpha = \min \left( 1,\frac{f(y|\theta^{'})f(\theta^{'}) q(\theta|\theta^{'})}{f(y|\theta)f(\theta) q(\theta^{'}|\theta)} \right)$$

My questions are:

1. Is it possible to evaluate $$f(y|\theta^{'})$$ and $$f(y|\theta)$$ without knowing its analytical form?
2. If not, does that mean that we need to know the analytical form of the posterior and the likelihood to use the Metropolis-Hastings algorithm? Also, what is the purpose of the data then?
3. If yes, how do we do it?

• the key is that the stuff we don't know (namely, f(y)) is the same on top and on the bottom, so we can compute the ratio. If we can't compute $f(y|\theta)$, MH is not going to help. Nov 7, 2022 at 20:10
• @JohnMadden - might want to expand that comment into an answer, so you get the credit you deserve (+1)! Nov 7, 2022 at 20:13

When $$\alpha = \min \left( 1,\frac{f(y|\theta^{'})f(\theta^{'}) q(\theta|\theta^{'})}{f(y|\theta)f(\theta) q(\theta^{'}|\theta)} \right)$$ involves an intractable likelihood function $$f(y|\cdot)$$ that cannot be computed, several (exact) alternatives are available:

1. the intractable part of $$f(y|\theta)$$ may also appear in $$q(\theta|\theta')$$ and hence cancels in the ratio. This is the idea of the auxiliary variable device of Møller et al. (2006). Also pursued by Murray et al. (2012). They mostly address the setup of doubly intractable distributions where the likelihood function $$f(y|\theta)$$ involves a multiplicative factor $$\mathfrak c(\theta)$$ that is itself intractable.

2. the intractable likelihood $$f(y|\theta)$$ may unbiasedly estimated by a random variable $$\xi(y,\theta)$$, even up to a normalising constant: $$\mathbb E[\xi(y,\theta)]=\alpha(y)f(y|\theta)$$ where $$\alpha(y)$$ may be unknown / intractable. This is the idea of pseudo-marginal MCMC of Andrieu & Roberts (2009).

3. Demarginalising $$y$$ into $$(y,z)$$ and $$f(y|\theta)$$ into $$\tilde f(y,z|\theta)$$ such that $$\int_{\mathbb Z} \tilde f(y,z|\theta)\,\text dz=f(y|\theta)$$and $$\tilde f(y,z|\theta)$$ tractable is a more general auxiliary variable method, where the augmented $$(\theta,z)$$ is simulated conditional on $$y$$ through an MCMC method. When using a Gibbs sampler, the ratio $$\alpha$$ may then be replaced at iteration $$t$$ by $$\tilde\alpha = \min \left( 1,\frac{\tilde f(y,z^t|\theta^{'})f(\theta^{'}) q(\theta^t|\theta^{'})}{f(y,z^t|\theta^t)f(\theta^t) q(\theta^{'}|\theta^t)} \right)$$ equivalent to $$\tilde\alpha = \min \left( 1,\frac{\tilde f(y|\theta^{'},z^t)f(\theta^{'}) q(\theta^t|\theta^{'})}{f(y|\theta^t,z^t)f(\theta^t) q(\theta^{'}|\theta^t)} \right)$$ which is a special case of 1.

If none of these (related) approaches can be used (in a sufficiently efficient manner), then a approximate approach is to resort to ABC (Approximate Bayesian computation).

1. It is technically possible, but usually unnecessary. It is usually far easier to calculate the likelihood and the prior than it is the posterior.

2. No, you do not need to know the posterior a priori. The reason we use Metropolis Hastings is because the full expression for the posterior has a normalizing constant that is difficult to calculate. BUT, you do know it is a constant, that it will make the probabilities sum to 1, and that the posterior is proportional to the likelihood times the prior. If you sample the distribution proportional to the likelihood times the prior, then you can just divide by the total number of samples to get the posterior density instead. The data's purpose is as a test: if the data fit a particular model better, that model will be more likely to be correct.

3. Look up "Bayesian Statistical Likelihood", which essentially works by simulating the possible experimental outcomes based on the current model, and constructing a likelihood function around the simulations. That said, this is usually overkill.

• Thanks, I understand the part about $f(y)$. As for the rest, please confirm whether I get it correctly: a) we use MH to sample when we have a model (in an analytical form) and it is important to have a likelihood function in the analytical form. b) Then we compare that sample to the data by another method such as convex optimization etc to check if the model w certain $\theta$ explains the data well. c) If we want to estimate $\theta$ we run MH algorithm multiple times with different values of $\theta$ and see which one fits the data the best (or utilize another optimization algorithm)?
– cc88
Nov 7, 2022 at 23:22
• a is correct. b is not quite correct: you're not trying to figure out if the model did "well" or not, only come up with a score of how well it did (which is its likelihood times its prior density). Because then you generate a new model based on the previous one, generate ITS score, and then decide if you sample the new model or add another sample of the old model. To estimate the total model $\theta$, you run this generate, compare, accept/reject algorithm until your models have converged: not to identical values, but to values with a consistent distribution. Nov 7, 2022 at 23:39