#slice sampler # assuming we do not know the edges: target=function(x){ dnorm(x,0,1) } B=1000 x=rep(0,B) u=rep(0,B) x[1]=0 u[1]=runif(1,0,target(x[1])) for( i in 2:B){ xProp=x[i-1]+rnorm(1,0,1) if(target(xProp)