Solution (source code)

= Solution

The <Metropolis–Hastings algorithm> is useful when a target <posterior> can be evaluated up to a <normalizing constant> but direct <independent> sampling or simple conditional sampling is unavailable. It constructs a <Markov chain> with that <posterior> as invariant law. After adequate convergence, averages of functions of the chain estimate <posterior> <expectations>, and the retained draws approximate marginal distributions, <quantiles> and credible intervals.

For the <Random-walk Metropolis algorithm>, at current $\theta$ propose $\theta'=\theta+Z$, where $Z$ has a symmetric distribution, often $N(0,\Sigma)$. With a symmetric proposal the acceptance <probability> is
$$
\boxed{a(\theta,\theta')=\min\{1,\pi(\theta'\mid X)/\pi(\theta\mid X)\}.}
$$
Accept the proposal when an <independent> uniform is below this <probability>; otherwise retain the current value. For a nonsymmetric proposal $q(\theta'\mid\theta)$, include $q(\theta\mid\theta')/q(\theta'\mid\theta)$ in the ratio. <Detailed balance> follows because the accepted flow is the minimum of the two proposed directional flows; rejection supplies the remaining self-transition <probability>. Irreducibility, appropriate recurrence and aperiodicity are also needed for convergence.

In the displayed <trace plots>, the first parameter moves in small increments with pronounced long-term wandering and a shift from its early region to a later region. This is consistent with an undersized proposal or a strongly correlated slow direction. Measure its acceptance rate: if it is very high, increase that coordinate's proposal <variance>. The second parameter moves rapidly within regions but changes its level around iteration 4500; that is evidence against treating the full run as a settled stationary sample, and it suggests investigating dependence with the first parameter or separated <posterior> regions. Its local scale may already be reasonable, so a blanket reduction of all proposal <variances> would be unwarranted. The third parameter has conspicuous long plateaus, indicating many repeated states: if the recorded acceptance is low, reduce its proposal <variance>; also check constraints and dependence before deciding that scale alone is the cause.

\b[Rerun with coordinate-specific scale changes, inspect joint dependence, consider a covariance-based block proposal, and run longer chains from dispersed starting points.] The <MCMC trace diagnosis and proposal tuning> should include actual acceptance rates and effective sample sizes; the three marginal <trace plots> do not by themselves identify <correlations> or prove convergence. Further practical details are in the three subparts.