# Why is MCMC needed when estimating a parameter using MAP

Given the formula for MAP estimation of a parameter Why is a MCMC (or similar) approach needed, couldn't I just take the derivative, set it to zero and then solve for the parameter?

• Great question! – user46925 Mar 12 '16 at 15:19

If you know which family your posterior is from and if finding the derivative of that distribution is analytically feasible, that is correct.

However, when you use MCMC, you are likely not going to be in that type of situation. MCMC is made for situations in which you have no clear analytical notion of how your posterior looks like.

• I think this is slightly misleading: MCMC is typically not used for finding the MAP estimator (outside special cases like an MCEM algorithm). – Cliff AB Aug 26 '15 at 17:02
• I do not disagree with you in principle. But, MCMC can be and is used to simulate the posterior distribution. And once you have done that, you can sure find the mode of that distribution, aka the MAP. Which is, I believe, what the OP had in mind, so I am not quite sure why my answer would be misleading. – Christoph Hanck Aug 27 '15 at 5:04
• Yes, however, is MCMC the method of choice when dealing with MAP if there is no analytical way to optimize the parameter? – Dänu Aug 27 '15 at 13:39
• I've never heard of using simple MCMC to find the mode of the posterior distribution (technically, it could be done, but this is extremely inefficient). Since we typically can evaluate a function that is proportional to the posterior distribution, maximizing this will be equivalent to maximizing the posterior distribution. Out of the box optimizers will work just as well on this as any frequentist likelihood problem (which is to say, sometimes you will need to specialize them). – Cliff AB Aug 27 '15 at 18:11
• @Dänu You probably don't want to use MCMC (to be pedantic, a Markov chain) to find maxima. An optimization algorithm should work better. – jtobin Aug 27 '15 at 19:10

Most posteriors prove to be difficult to optimize analytically (i.e. by taking a gradient and setting it equal to zero), and you'll need to resort to some numerical optimization algorithm to do MAP.

As an aside: MCMC is unrelated to MAP.

MAP - for maximum a posteriori - refers to finding a local maximum of something proportional to a posterior density and using the corresponding parameter values as estimates. It is defined as

$$\hat{\theta}_{MAP} = \text{argmax}_{\theta} \, p(\theta \, | \, D)$$

MCMC is typically used to approximate expectations over something proportional to a probability density. In the case of a posterior, that's

$$\hat{\theta}_{MCMC} = n^{-1} \sum_{i=1}^{n} \theta^{0}_{i} \approx \int_{\Theta}\theta \, p(\theta \, | \, D)d\theta$$

where $\{\theta^{0}_{i}\}^{n}_{i=1}$ is a collection of parameter space positions visited by a suitable Markov chain. In general, $\hat{\theta}_{MAP} \neq \hat{\theta}_{MCMC}$ in any meaningful sense.

The crux is that MAP involves optimization, while MCMC is based around sampling.

• You state that posteriors prove to be difficult to optimize analytically, which is the case in MAP. So is MAP only possible if the posterior can be optimized analytically and if this is not the case one has to resort (for example) to an MCMC approach? – Dänu Aug 27 '15 at 13:04
• No, instead of coming with the analytical solution, one can use an iterative algorithm to come up with the solution (i.e. if the log posterior is concave, you can use Newton's Method, for example). – Cliff AB Aug 27 '15 at 18:13
• MAP refers to finding parameter values that (locally) maximize a posterior. It doesn't matter how one gets those parameter values: solving for maxima analytically, using a numerical routine, automatic differentiation, etc. – jtobin Aug 27 '15 at 19:00

MCMC is not needed (or suggested) in order to compute a MAP estimate. In general, you won't be able to solve for the root of the MAP objective's derivative. However, you can use numerical optimization to approximately maximize the objective. As noted, MCMC is a sampling method, whereas MAP estimation is an optimization problem. MAP estimation only requires us to be able to evaluate the (unnormalized) posterior distribution at a given $$\theta$$, and only gives us one piece of information about that posterior. By approximately sampling an intractable posterior, MCMC methods allow us to learn all information about the posterior distribution.