Solution (source code)

= Solution
{c}

Assume $a,b,\mu>0$ and a current state with $0<p<1$, $\beta>0$. The unnormalized <posterior density> is
$$
\pi(p,\beta\mid x)\ \propto\
\exp\{\ell(p,\beta;x)\}\,p^{a-1}(1-p)^{b-1}\,\mu^{-1}e^{-\beta/\mu}.
$$
Thus the <log-posterior>, up to an additive constant, is the <log-likelihood> plus the <beta distribution> and <exponential distribution> log <prior densities>. The <exponential distribution> rate is $1/\mu$, since $\mu$ is its mean. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Beta.html[Official R documentation: dbeta arguments and logarithmic density output]{ref} https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Exponential.html[Official R documentation: dexp rate parameter and mean equal to inverse rate]{ref}

Choose a symmetric joint <random-walk Metropolis algorithm> proposal: $p'=p+0.1G_1$ and $\beta'=\beta+(\mu/2)G_2$, for <independent> <standard normal distribution> draws. Its scale depends only on fixed hyperparameters, so forward and reverse proposal <probability density functions> agree. Reject immediately outside $(0,1)\times(0,\infty)$; otherwise accept with <Metropolis–Hastings acceptance probability>
$$
\boxed{\alpha=\min\{1,\exp[\log\pi(p',\beta'\mid x)-\log\pi(p,\beta\mid x)]\}.}
$$
The following function makes exactly one proposal, with rejection retaining both old parameters:

``
MHstep <- function(x, p, beta, a, b, mu) {
  p_new <- rnorm(1, mean = p, sd = 0.1)
  beta_new <- rnorm(1, mean = beta, sd = mu / 2)
  if (p_new <= 0 || p_new >= 1 || beta_new <= 0)
    return(list(p = p, theta = beta))
  logpost <- function(pp, bb) {
    ll_f(pp, bb, x) + dbeta(pp, a, b, log = TRUE) +
      dexp(bb, rate = 1 / mu, log = TRUE)
  }
  logA <- logpost(p_new, beta_new) - logpost(p, beta)
  if (log(runif(1)) <= min(0, logA)) {
    p <- p_new
    beta <- beta_new
  }
  list(p = p, theta = beta)
}
``

\b[The returned field `theta` contains the updated value of `beta`.] The original PDF really asks for `p` and `theta`, although no parameter $\theta$ is defined in this question. This choice preserves its literal interface while making the intended second parameter explicit. A caller therefore advances with `state <- MHstep(x, p, beta, a, b, mu)`, `p <- state$p`, and `beta <- state$theta`.

The proposal is an unrestricted symmetric <normal distribution> followed by rejection outside the <support>. Repeatedly drawing until a valid proposal appears would instead truncate and renormalize the proposal, requiring a proposal-density correction. The code uses immediate rejection and needs no such correction. The displayed scales are valid fixed choices; practical efficiency can be improved using a separate tuning phase.