14.8 MLE for Poisson Random Variables

  • Suppose we use a camera to record an intersection for a particular length of time, and we write down the number of cars accidents in that interval.
  • This process can be modeled by a Poisson random variable (now we are non-agnostic), that has a well-known probability mass function given by,

\[ f(x;\lambda) = \frac{\lambda^x e^{-\lambda}}{x!} \]

Here is an example of a string of outcomes generated by a Poisson RV, with parameter \(\lambda = 2\).

Code
rpois(n = 10, lambda = 2)
##  [1] 0 4 1 1 3 3 0 1 1 1

14.8.1 MLE for Poisson Random Variables: Data

  • Suppose that we conduct an iid sample, and gather the following number of accidents. (It is a busy street!)
Code
data <- c(
  2, 6, 2, 1, 3, 3, 4, 4, 24, 1, 5, 4, 5, 1,  2, 2, 5, 2, 1, 5, 
  2, 1, 2, 9, 9, 1, 3, 2, 1,  1, 3, 1, 3, 2,  2, 4, 1, 1, 5, 3, 
  3, 2, 2, 1, 1, 1, 5, 1, 3,  1, 1, 1, 1, 2,  2, 4, 2, 1, 2, 2, 
  3, 1, 2, 6, 2, 2, 3, 2, 3,  5, 1, 3, 2, 5,  2, 1, 3, 2, 1, 2, 
  4, 2, 6, 1, 2, 2, 3, 5, 2,  1, 4, 2, 2, 1,  3, 2, 2, 4, 1, 1, 
  1, 1, 2, 3, 5, 1, 2, 2, 3,  1, 4, 1, 3, 2,  2, 2, 2, 2, 2, 3, 
  3, 1, 1, 2, 2, 4, 1, 5, 2,  7, 5, 2, 3, 2,  5, 3, 1, 2, 1, 1, 
  2, 3, 1, 5, 3, 4, 6, 3, 3,  2, 2, 1, 2, 2,  4, 2, 3, 4, 3, 1, 
  6, 3, 1, 2, 3, 2, 2, 3, 1,  1, 1, 1, 1, 10, 3, 2, 1, 1, 3, 2, 
  2, 3, 1, 1, 2, 2, 2, 4, 2,  2, 3, 3, 6, 1,  3, 2, 3, 2, 2, 2
  )

table(data)
## data
##  1  2  3  4  5  6  7  9 10 24 
## 54 69 38 14 14  6  1  2  1  1

14.8.2 MLE Estimation

  • Use the data that is stored in data, together with a Poisson model to estimate the \(\lambda\) values that produce the “good” model from the Poisson family.

  • That is, use MLE to estimate \(\lambda\).

  • Here is your work flow:

    1. Define your random variables.
    2. Write down the likelihood function for a sample of data that is generated by a Poisson process.
    3. To make the math easier, take the log of this likelihood function.
    4. Optimize this log-likelihood using calculus – what is the value of \(\lambda\) that results? Compute this value, given the data that you have.
    5. Maximize this log-likelihood numerically, and report the value for \(\lambda\) that produces the highest likelihood of seeing this data.
    6. Comment on your answers from parts 4 and 5. Are you surprised or not by what you see?
Code
poisson_ll <- function(data, lambda) { 
  ## fill this in:  
  lambda # this is a placeholder, change this
}
Code
search_space <- seq(0,100, by = 0.1)
plot(
  x = search_space, xlab = 'Search Space',
  y = poisson_ll(data=data, lambda=search_space), ylab = 'Log Likelihood',
  type = 'l'
)

Code
# optimize(poisson_ll, lower = 0, upper = 100, data = data, maximum = TRUE)