# Hit and run MCMC

I'm trying to implement the hit and run MCMC algorithm, but I'm having a bit of trouble understanding how to go about it. The general idea, is as follows:

To generate a proposal jump in MH, we:

• Generate a direction $d$ from a distribution on the surface of the unit sphere $\mathcal{O}$
• Generate a signed distance $\lambda$ along the constrained space.

However, I have no idea of how I should go about implementing this in R (or any other language).

Does anyone have a snippet of code that would point me in the right direction?

BTW, I not that interested in a library that does this method, I want to try and code it up myself.

Many thanks.

• Never heard of this algorithm before, but it sounds pretty interesting. Could you provide a link to a explanatory source ? Thank you ! Dec 2, 2010 at 10:35
• @steffen Here's a link to the original paper - well actually the technical report. I've never used this procedure either. Dec 2, 2010 at 11:20
• What is the advantage of the hit and run MCMC over other methods? Speed of convergence? Dec 6, 2010 at 5:14
• @fRed: That's why I offered the bounty. I've read about Hit and run, but don't know under what circumstances it would be useful. Dec 6, 2010 at 18:46
• Link is now broken. Feb 1, 2017 at 23:54

I didn't look at the paper you supplied, but let me have a go anyway:

If you have a $p$-dimensional parameter space you can generate a random direction $d$ uniformly distributed on the surface of the unit sphere with

x <- rnorm(p)
d <- x/sqrt(sum(x^2))


(c.f. Wiki).

Then, use this to generate proposals for $d$ for rejection sampling (assuming you can actually evaluate the distribution for $d$).

Assuming you start in position $x$ and have accepted a $d$, generate a proposal $y$ with

 lambda <- r<SOMEDISTRIBUTION>(foo, bar)
y <- x + lambda * d


and do a Metropolis-Hastings-Step to decide whether to move to $y$ or not.

Of course, how well this can work will depend on the distribution of $d$ and how expensive it is to (repeatedly) evaluate its density in the rejection sampling step, but since generating proposals for $d$ is cheap you may get away with it.