# Difference between revisions of "Eleisha's Segment 41: Markov Chain Monte Carlo, Example 2"

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.) The waiting time to the kth event in a Poisson process with rate $\displaystyle \lambda$ is distributed a $\displaystyle \text{Gamma}(k, \lambda)$ . Let $\displaystyle \tau = t_{i+k - t_i}$ with $\displaystyle \tau$ = time from event i to event k. Then the waiting time is distributed as

$\displaystyle p(\tau | k, \lambda) = \frac{\lambda^k}{(k - 1)!} \tau^{k-1}e^{-\lambda \tau}$

So in this case $\displaystyle \tau = t_{i+1 - t_i}$ where $\displaystyle \tau$ is the time from the first event to a second event. This means that k = 1. So if k = 1 then

$\displaystyle p(\tau | k, \lambda) = \frac{\lambda}{(0!)} \tau^{0}e^{-\lambda \tau}$

$\displaystyle p(\tau | k, \lambda) = \lambda e^{-\lambda \tau}$

This is an exponential distribution.

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

Below is the python code used to generate the plot


import scipy.stats as sp
from scipy.stats import gamma
from scipy.stats import expon
import numpy as np
import matplotlib.pyplot as plt

plt.figure(1)
x = np.linspace(start = 0, stop = 20, num = 50)
rv = gamma(2, scale = 2.0)
rv2 = expon(1)
p1, = plt.plot(x, rv.pdf(x))
p2, = plt.plot(x, rv2.pdf(x))
plt.ylabel("P(x)")
plt.xlabel("x")
plt.legend([p1, p2], ["Every other event with lamdba = 2", "Half-Rate, lambda = 1"])
plt.savefig("Eleisha_HW42.png")
plt.show()


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 $\displaystyle k_1$ or $\displaystyle 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 $\displaystyle 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 $\displaystyle N$ of data points $\displaystyle t_i$ that you need to clearly distinguish between these hypotheses?