
i
i
“K23166” — 2015/1/28 — 9:35 — page 160 — #186
i
i
i
i
i
i
160 CHAPTER 10. SIMULATION
To begin the process, we pick an arbitrary value for X
1
. The Metropolis–Hastings algorithm
chooses X
n+1
as follows:
1. Generate y from a normal(X
n
, 1).
2. Compute α(x, y) as above.
3. With probability α(x, y), let X
n+1
= y (use proposal value). Otherwise, with proba-
bility 1 − α(x, y), let X
n+1
= X
n
= x (repeat previous value).
The code below uses the first 5,000 iterations as a burn-in period, then generates 50, 000
samples using this procedure. Only every 10th value from these 50, 000 is saved, to reduce
autocorrelation. This process is known as “thinning.” We begin by writing ...