Metropolis Hastings with estimated posterior I am interested in samples of $\theta$ from the posterior distribution
$$
P(\theta|x) = \int d\phi P(\theta|\phi)P(\phi|x)
$$
where $x$ are data and $\phi$ are nuisance parameters. In principle, I can use a Metropolis Hastings sampler to sample from $\theta$ and $\phi$ and discard the samples of the nuisance parameter.
In this case, I can sample from $P(\phi|x)$ directly such that I can approximate the marginal posterior by Monte Carlo integration
$$
P(\theta|x)\approx\frac{1}{n}\sum_{i=1}^n P(\theta|\phi_i)\equiv \hat P,
$$
where $\phi_i$ are samples from $P(\phi|x)$. Of course, the approximation $\hat P$ is not deterministic because of the sampling error. I seem to remember that running the following algorithm samples from the posterior in this case but I can no longer find the reference. Is this correct? If so, do you have a reference?
# Sampler in pseudo-python
theta = initial_value

for step in range(num_steps):
    # Sample phi
    phi = sample_phi_given_x(x)
    # Evaluate current posterior
    posterior_estimate = mean(posterior(theta, phi))
    # Sampled from proposal and evaluate posterior at proposal
    candidate = sample_from_proposal(theta)
    posterior_candidate_estimate = mean(posterior(candidate, phi))

    # Accept or reject the proposal
    if random_uniform() < posterior_candidate_estimate / posterior_estimate:
         theta = candidate

 A: I do not understand the need for this construction if you can


*

*simulate from $P(\phi|x)$

*simulate from $P(\theta|\phi)$


since neither an approximation nor an MCMC implementation is then required. 
If you cannot analytically sample from P(θ|ϕ), a regular Gibbs sampler will work as well:


*

*simulate from $P(\phi|x,\theta)\propto P(\phi|x)\times P(\theta|\phi)$ [which may require one [& only one] Metropolis-within-Gibbs step]

*simulate from $P(\theta|\phi)$ [which may require one [& only one] Metropolis-within-Gibbs step]

*simulate from $P(\phi|x,\theta)\propto P(\phi|x)\times P(\theta|\phi)$ &tc...


This is less costly than the pseudo-marginal version, which requires $n$ $\phi_i$'s for one proposal of $\theta$.
Note: The link to pseudo-marginal MCMC made by lacerbi is however correct in that if one manages to get an unbiased estimator of the
posterior density (up to a constant) there are valid MCMC implementations
based on such estimates. Which means your proposal is not correct because you use the same $\phi_i$'s for numerator and denominator in the Metropolis ratio. The random variables used to approximate the posterior density should be considered as auxiliary or latent variables and hence be only simulated for the proposal, while being preserved from the earlier stage for the current value: to quote from Darren Wilkinson's blog,

"The key to understanding the pseudo-marginal approach is to realise
  that at each iteration of the MCMC algorithm a new value of w is being
  proposed in addition to a new value for x."

Meaning that the acceptance ratio

keeps the previous value of w for the previous value of x. In other words, the $\phi_i$'s are not to be re-simulated for computing the unbiased estimator at the previous value of $\theta$.
