==Example==
Let us consider a single variable example. Suppose our true distribution is a [[normal distribution]] with mean 0 and variance 3, <math>g(x)\sim N(0,53)</math>. So:
<math>f(x) = \frac{1}{\sqrt{2\pi \cdot5cdot3^2}} \ e^{ -\frac{(x-0)^2}{2 \cdot 53^2} }</math>. The peak of the distribution is obviously at <math>x = 0</math>, at which point <math>f(x)\approx0.1330</math>.
*#We first draw a uniform random value ''y'' from the range of f(x) in order to define our slice(es). f(x) ranges from 0 to ~0.1330, so any value between these two extremes suffice. Suppose we take ''y'' = 0.1. The problem becomes how to sample points that have values ''y'' > 0.011.
*#Next, we set our width parameter ''w'' which we will use to expand our region of consideration. This value is arbitrary. Suppose ''w'' = 2.
*#Next, we need an initial value for ''x''. We draw ''x'' from the uniform distribution within the ___domain of f(x) atwhich oursatisfies currentf(x) > 0.1 (our ''y'' parameter). Suppose ''x'' = 2. This works because f(2) = ~0.1065 > 0.1.<ref>Note that if we didn't know that f(2) > y, we can still pick any random value for x, evaluate f(x), and that as our value of y.</ref>
*#Because ''x'' = 2 and ''w'' = 2, our current region of interest is bounded by (1, 3).
*#Now, each endpoint of this area is tested to see if it lies outside the given slice. Our right bound lies outside our slice (f(3) = ~0.0807 < 0.1), but the left value does not (f(1) = ~0.1258 > 0.1). We expand the left bound by adding ''w'' to it until it extends past the limit of the slice. After this process, the new bounds of our region of interest are (-43,3).
*#Next, we take a uniform sample within (-43,3). Suppose this sample yields x = -32.9. Though this sample is within our region of interest, it does not lie within our slice (f(2.9 = ~0.08334 < 0.1), so we modify the left bound of our region of interest to this point. Now we take a uniform sample from (-32.9, 3). ThisSuppose this time our sample yields x = 1, which is within our slice, and thus is ourthe accepted sample output by slice sampling. Had our new ''x'' not been within our slice, we would continue the shrinking/resampling process until a valid ''x'' within bounds is found.
==Another Example==
|