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

(8 intermediate revisions by the same user not shown) | |||

Line 2: | Line 2: | ||

1. Show that the waiting times (times between events) in a Poisson process are Exponentially distributed. (I think we've done this before.) | 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 <math>\lambda </math> is distributed a <math>\text{Gamma}(k, \lambda) </math>. | ||

+ | Let <math>\tau = t_{i+k - t_i}</math> with <math>\tau </math> = time from event i to event k. | ||

+ | Then the waiting time is distributed as | ||

+ | |||

+ | <math> p(\tau | k, \lambda) = \frac{\lambda^k}{(k - 1)!} \tau^{k-1}e^{-\lambda \tau} </math> | ||

+ | |||

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

+ | |||

+ | <math> p(\tau | k, \lambda) = \frac{\lambda}{(0!)} \tau^{0}e^{-\lambda \tau} </math> | ||

+ | |||

+ | <math> p(\tau | k, \lambda) = \lambda e^{-\lambda \tau} </math> | ||

+ | |||

+ | 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. | 2. Plot the pdf's of the waiting times between (a) every other Poisson event, and (b) every Poisson event at half the rate. | ||

+ | |||

+ | [[File:Eleisha_HW42.png]] | ||

+ | |||

+ | Below is the python code used to generate the plot | ||

+ | |||

+ | <pre> | ||

+ | |||

+ | 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() | ||

+ | </pre> | ||

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.) | 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.) |

## Latest revision as of 17:04, 9 May 2014

**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 **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \lambda }**
is distributed a **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \text{Gamma}(k, \lambda) }**
.
Let **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \tau = t_{i+k - t_i}}**
with **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \tau }**
= time from event i to event k.
Then the waiting time is distributed as

**Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p(\tau | k, \lambda) = \frac{\lambda^k}{(k - 1)!} \tau^{k-1}e^{-\lambda \tau} }**

So in this case **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \tau = t_{i+1 - t_i}}**
where **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \tau }**
is the time from the first event to a second event. This means that k = 1. So if k = 1 then

**Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p(\tau | k, \lambda) = \frac{\lambda}{(0!)} \tau^{0}e^{-\lambda \tau} }**

**Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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.)

**To Think About: **

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 **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle k_1}**
or **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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 **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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 **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle N }**
of data points **Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle t_i}**
that you need to clearly distinguish between these hypotheses?

**Back To: ** Eleisha Jackson