# Segment 41. Markov Chain Monte Carlo, Example 2

## Contents

#### Watch this segment

(Don't worry, what you see statically below is not the beginning of the segment. Press the play button to start at the beginning.)

{{#widget:Iframe |url=http://www.youtube.com/v/FnNckBLWJ24&hd=1 |width=800 |height=625 |border=0 }}

Links to the slides: PDF file or PowerPoint file

### Problems

#### To Calculate

1. Show that the waiting times (times between events) in a Poisson process are Exponentially distributed. (I think we've done this before.)

2. Plot the pdf's of the waiting times between (a) every other Poisson event, and (b) every Poisson event at half the rate.

3. Show, using characteristic functions, that the waiting times between every Nth event in a Poisson process is Gamma distributed. (I think we've also done one before, but it is newly relevant in this segment.)

1. In slide 5, showing the results of the MCMC, how can we be sure (or, how can we gather quantitative evidence) that there won't be another discrete change in $k_1$ or $k_2$ if we keep running the model longer. That is, how can we measure convergence of the model?

2. Suppose you have two hypotheses: H1 is that a set of times $t_i$ are being generated as every 26th event from a Poisson process with rate 26. H2 is that they are every 27th event from a Poisson process with rate 27. (The mean rate is thus the same in both cases.) How would you estimate the number $N$ of data points $t_i$ that you need to clearly distinguish between these hypotheses?

### Class Activity

Here's another one of these amazing Gibbs sampling examples. Suppose 2 unknown distributions over the digits 0..9, that is $p_0,p_1,\ldots,p_9$ and $q_0,q_1,\ldots,q_9$, of course with $\sum_i p_i = 1$ and $\sum_i q_i = 1$. This data file has 1000 lines, each with 10 i.i.d. draws of digits, either from the $p$'s or the $q$'s -- but, for each line, you don't know which.

1. Estimate $p_0,p_1,\ldots,p_9$ and $q_0,q_1,\ldots,q_9$ from the data. If you are ambitious, do this by two different methods: First, by Gibbs sampling. Second, by an E-M method. (Although these are conceptually different, my code for them differs by only a few lines.)

2. Estimate a probability for each line in the data file as to whether it is drawn from the $p_i$'s (as opposed to the $q_i$'s.

3. Plot histograms that show the uncertainties of your Gibbs estimate for the $p_i$'s. Do your E-M estimates appear to be at the modes of your Gibbs histograms? Should they be?