Metropolis Sampling and invalid states I have a short question about Monte Carlo integration with Metropolis sampling. I have a continuous state space, but only certain parts of this state space are valid. It is possible that the transition function can suggest a move to an invalid part of the state space, and the jump should be obviously rejected. However, I'm not sure whether this invalid sample should be counted; i.e. if N samples are taken and one is rejected from an invalid part of state space, should I divide by N-1 in the estimate.
Thanks
 A: From your question:

It is possible that the transition function can suggest a move to an invalid part of the state space, and the jump should be obviously rejected. 

The jump should not be rejected
This is a great article on the problem with immediately rejecting an errant jump. As a consequence, your problem vanishes. 
A: [Reproducing a blog entry I wrote a while ago:]
It is indeed a popular belief that something needs to be done to counteract restricted supports. However, there is no mathematical reason for doing so! If we look at the Metropolis-Hastings acceptance probability
$$\rho(x_t,y_{t+1})= \text{min} (1, \pi(y_{t+1})q(x_t|y_{t+1})\big/
\pi(x_t)q(y_{t+1}|x_{t}) )$$
(duplicated from the mcmc tag wiki), with $y_t\sim q(y_{t+1}|x_{t})$, if $y_t$ is outside the support of $\pi$, we can extend the support by defining $\pi(y)=0$ outside the original support. Hence, if $\pi(y_{t+1})=0$, $\rho(x_t,y_{t+1})=0$, which means the proposed value is rejected and $x_{t+1}=x_t$.
Consider the following illustration.
target=function(x) (x>0)*(x<1)*dnorm(x,mean=4)
mcmc=rep(0.5,10^5)
for (t in 2:10^5){
prop=mcmc[t-1]+rnorm(1,.1)
if (runif(1)<target(prop)/target(mcmc[t-1]))
mcmc[t]=prop
else
mcmc[t]=mcmc[t-1]
}
hist(mcmc,prob=TRUE,col="wheat",border=FALSE,main="",xlab="")
curve(dnorm(x-4)/(pnorm(-3)-pnorm(-4)),add=TRUE)

that is targeting a truncated normal distribution using a Gaussian random walk proposal with support the entire real line. Then the algorithm is properly converging as shown by the fit below:

