Monday, November 3, 2014

Halloween Trick-or-Treaters as a Poisson Process

Usually this time of the year I'm blogging about some Halloween-themed cookie recipe or jack-o-lanterns (and roasted pumpkin seeds yum!). This year I thought it would be fun to discuss the idea of a Poisson process and use Halloween as an example.  In this blogpost, I will simulate the number of trick-or-treaters as a Poisson process!

Generally speaking, a Poisson process is a continuous-time process ${N(t), t \geq 0}$ where $N(t)$ counts the number of events that occur in a time interval [0, $t$] and the inter-arrival time of these events in a given time interval. In our case, we can think the Poisson process counting the number of trick-or-treaters in a given time interval. Specifically a Poisson process is characterized by the following properties:
  1. The number of events at time $t$ = 0 is 0 (or $N(0) = 0$)
  2. Stationary increments: the probability distribution of $N(t+h) - N(t)$ depends only on $h$ (not $t$). This means the probability of observing a certain number of trick-or-treaters in a given time interval depends only on the length of the time interval (e.g. 1hr).  
  3. Independent increments: the number of events occurring in disjoint time intervals are independent of each other. You can think of this as the number of trick-or-treaters we see from e.g. 5:30-6:30pm doesn't influence the number of trick-or-treaters we see e.g. 7:30-8:30pm. 
  4. $N(t)$ is distributed as a Poisson distribution.  
Assuming these four properties, we immediately get a free piece of information:
  • Inter-arrival times between the events (or "waiting times") are independent and identically distributed as an exponential random variable with a given rate parameter. Therefore to simulate a Poisson process all we have to do is simulate the inter-arrival times between events using an exponential distribution.  
Now, there are several types of Poisson processes, but for our purposes I will discuss on two: (1) a homogeneous and (2) inhomogeneous Poisson process. The main difference between the two is the rate at which the events occur.  In the homogeneous Poisson process events occur at a constant rate $\lambda$.  In the inhomogenous Poisson process, events occur at a variable rate $\lambda(t)$.  
  • homogenous Poisson process: 
    • The probability of one event in a small interval $h$ is approximately $\lambda h$ where $\lambda$ is a rate parameter. The probability of two events in a small interval is approximately 0.
$$N(t) \sim Poisson(\lambda t)$$
$$P[N(t + s) - N(t) = k] = \frac{e^{-\lambda s} (\lambda s)^{k}}{k!}$$

If we define $S_k$ as the arrival time of the $k^{th}$ events and $X_k = S_k - S_{k-1}$ as the time between the $k^{th}$ and $k-1$ arrival time, then 

$$P(X_k > t | S_{k-1} = s) = e^{-\lambda t}$$
  • inhomogenous Poisson process: 
    • The difference is here the rate parameter varies over time: $\lambda(t)$.  This means we no longer have stationary increments as above because the number of events observed in a given time interval depends on the length of the interval AND the time $t$ itself.  
Let's try an example. Let's simulate the number trick-or-treaters using a homogeneous Poisson process with rate parameter $\lambda$. Using this blogpost as an estimate for the number of trick-or-treaters per minute, I estimated there are 1-2 trick-or-treaters per minute.  As stated above, to simulate the Poisson process, I will simulate the inter-arrival times of the trick-or-treaters using an exponential distribution. The cumulative distribution function of an exponential random variable $T$ is given by

$$u = F(x) = 1 -e^{-\lambda t}$$

As a little background reading, here are two sets of notes on simulating a Poisson process which are particularly useful: here and here.  If the hours for trick-or-treating are around 5:30-8:30pm, the inter-arrival times $X_k$ can be simulated $u \sim U[0,1]$, then we can solve solve for $t$:

$$t = - \frac{\log(u)}{\lambda}$$

One nice extension of this example would be to an inhomogeneous Poisson process where the rate at which the trick-or-treaters arrive varies across time.  I'll leave it to you to try.  Hope everyone had a safe and happy Halloween!

No comments:

Post a Comment