I am trying to apply MCMC on a problem, but my priors(in my case they are $\alpha\in[0,1],\beta\in[0,1]$)) are restricted to an area? Can I use normal MCMC and ignore the samples that fall outside of the restricted zone(which in my case is [0,1]^2), i.e. reuse transition function when the new transition falls out of restricted(constrained) area?

  • 3
    $\begingroup$ Take a look: xianblog.wordpress.com/tag/constrained-parameter-spaces $\endgroup$
    – Zen
    Commented Oct 27, 2013 at 21:30
  • $\begingroup$ @Zen, I am not quite sure but the answer suggested by Xian is that to subsample, but instead of using MH, to use Gibbs sampler and reiterate if one of the values of a dimension exceeds the boundary, am I right? $\endgroup$
    – Cupitor
    Commented Oct 27, 2013 at 22:00
  • 1
    $\begingroup$ If MH proposes something outside of the parameter space, the acceptance probability is just set to $0$ and everything works fine. I think MH just interprets $0/0$ as $0$ (a manifestation of $0 \cdot \infty = 0$ in measure theory). $\endgroup$
    – guy
    Commented Oct 27, 2013 at 23:30
  • $\begingroup$ @guy, but according to the discussion on xian's page(above link by Zen), it looks like that Gibbs has a superiority without mentioning any reason though! $\endgroup$
    – Cupitor
    Commented Oct 28, 2013 at 16:01
  • 1
    $\begingroup$ @Cupitor I don't see him saying that. I think the implication is that Gabriel was doing Metropolis-within-Gibbs. $\endgroup$
    – guy
    Commented Oct 28, 2013 at 19:29

1 Answer 1


You have several nice, more-or-less simple, options. Your uniform prior helps make them simpler.

Option 1: Independence sampler. You can just set your proposal distribution equal to a uniform distribution over the unit square, which ensures that samples won't fall outside the restricted zone, as you call it. Potential downside: if the posterior is concentrated in a very small region of the unit square, you may have a very low acceptance rate. OTOH, it's hard to generate random numbers faster than from a U(0,1) distribution. Potential upside: less work for you.

Option 2: Transform your parameters to something that isn't bounded, make proposals for the transformed parameters, then transform the parameters back for use in the likelihood functions. Note that in this case the prior is going to be on the transformed parameters, because that's what you're making proposals for, so you'll have to mess with the Jacobian of the transform to get the new prior. For your analysis, of course, you'll transform the MCMC-generated parameter random numbers back to the original parameters. Potential downside: more initial work for you. Potential upside: better acceptance rate for your proposals.

Option 3: Construct a proposal distribution other than an independence sampler that is on the unit square. This allows you to keep your uniform prior, but at the cost of greater complexity when calculating the proposal probabilities. An example of this, letting $x$ be the current value of one of your parameters, would be a Beta distribution with parameters $(nx, n(1-x))$. The larger $n$ is, the more concentrated your proposal will be around the current value. Potential downside: more initial work for you. Potential upside: better acceptance rate for your proposals - but if you make $n$ too large, and move near to a corner, you might wind up making lots of small moves in the corner before getting out.

Option 4: Just reject any proposals that fall outside the unit square (Xian's half-hearted suggestion). Note that this is not the same as just generating another proposal; in this case you are rejecting the proposal, which means your next value for the parameter is the same as the current value for the parameter. This works because it's what would happen if you had a zero prior probability for some region of your parameter space and generated a random number that fell in that region. Potential downside: if you get near a corner, you may have a low acceptance probability and get stuck for a while. Potential upside: less work for you.

Option 5: Create an extended problem on the plane which, on the unit square, is the same as the actual problem you face, do everything right, then, when post-processing the results of the MCMC sampling, throw out all the samples outside of the unit square. Potential upside: If it's very easy to create that extended problem, it may be less work for you. Potential downside: if the Markov chain wanders off somewhere outside the unit square for a while, you may have, in effect, horrible acceptance probabilities, as you will throw out most of your samples.

No doubt there are other options, I'd be interested to see what other people suggest!

The difference between 2 and 3 is to some extent conceptual, although with real implications for what you actually do. I'd probably go with 3, as I'd just let R tell me what the proposal probabilities are (if I'm programming in R) and the amount of extra effort, aside from some tuning of the proposal distribution parameter $n$, looks small to me. If I was using JAGS or BUGS, of course, that would be a whole different matter, since those tools handle their own proposals.

  • $\begingroup$ Vote up! Thanks a lot for such a thorough answer, but there are a few points that I am struggling to follow: 1)Actually the parameter space is coming from a line-segment in square and therefor it is really hard to get by uniform sampling I guess 2)This actually doesnt' seem to be a quite good idea. To give a simple illustration imagine to extend the bounded sample just by setting the probability of outer area to zero! This would make the converging process very slow I guess and that would be probably similar to subsampling $\endgroup$
    – Cupitor
    Commented Oct 28, 2013 at 16:06
  • $\begingroup$ 3)The problem with this idea is that your proposal is not invertible and therefore it might be the case that the resulting sampling scheme might not be an ergodic one anymore! $\endgroup$
    – Cupitor
    Commented Oct 28, 2013 at 16:06
  • $\begingroup$ 4) is the way that I tried and looks reasonable(IMH!) 5) This ones seem to suffer from the example I mentioned in 2 and as you said yourself might give terrible acceptance rates! $\endgroup$
    – Cupitor
    Commented Oct 28, 2013 at 16:08
  • 2
    $\begingroup$ 1) Not sure what you mean; do you mean that your two parameters are on a line in the unit square (and are therefore really only one parameter?) 2) What 2 refers to is transforming the parameters to other parameters, e.g., y = x/(1-x) has range $(0,\inf)$ when $x \in (0,1)$ and sampling from y instead of x. 3) The $\beta$ proposal works; you just have to incorporate the proposal probabilities in the calculation of the acceptance ratio (standard MCMC.) You don't need to have a symmetric proposal (which is what I think you mean by "invertible") for ergodicity to hold. $\endgroup$
    – jbowman
    Commented Oct 28, 2013 at 16:59
  • $\begingroup$ 1)Ok, what I am doing is that I pick up a uniform random number from [0.0,4.0] and depending on its integer part and floating part assign it to a point on the periphery of the square I mentioned. For example $\alpha=2.5$ will go to $(0.5,1)$ and $\alpha=3.2$ goes to $(0,0.8)$ while $\alpha=0.2$ goes to $(0.2,0)$ $\endgroup$
    – Cupitor
    Commented Oct 28, 2013 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.