# TO BE USED WITH S.MCMC
# On a simple proposal mechanism for xs given unequally spaced markers in (0,1)
# started 12/18/98
# Propose either the current interval, or a neighboring one, and a uniformly distributed
# point within that.
nn <- length(pos) # there are nn-1 gaps
mgaps <- pos[2:nn] - pos[1:(nn-1)]
mgaps <- c( mgaps, 0 )
qprobs <- matrix(0,nn-1,3)
qprobs[1,2:3] <- mgaps[1:2]/sum(mgaps[1:2])
triplet.len <- pos[3]
ind <- c(1,2,3)
ok <- T
gap.id <- 2
while(ok)
{
triplet.len <- c( triplet.len, sum( mgaps[ind] ) )
qprobs[gap.id,] <- mgaps[ind]/sum( mgaps[ind] )
gap.id <- gap.id+1
ind <- ind + 1
ok <- ifelse( max(ind) > nn , F, T )
}
mgaps <- mgaps[-nn] # remove trailing 0
# Cumulative probabilities
cumqprob <- cbind( qprobs[,1], qprobs[,1]+qprobs[,2], 1 )
# In summary, suppose we are at a value xs=x which happens to be in (pos[i],pos[i+1])
# (i.e. in a gap of length mgap[i]).
# We propose one of (i-1,i,i+1) with probabilities
#
# i to i-1 w.p. gap[i-1]/triplet.len[i] (noting gap[0]=0)
# i w.p gap[i]/triplet.len[i]
# i+1 w.p gap[i+1]/triplet.len[i] (noting gap[nn]= 0)
#
# Next we sample a position uniformly from within the selected gap.
#
# So if going from x in gap_i to y in gap_i+1, MH=triplet.len[i]/triplet.len[i+1].
# Note that the numerators ``gap[..]'' cancel in the MH ratio by uniform sampling.
# This rule accounts for the edges which are really doublets.