# Simulate MLE for Poisson distribution [closed]

According to the theory given $$X_i$$ ~ $$Pois(\lambda)$$ iid, the maximum likelihood must be equal to $$\sum_{i=1}^{n} X_i/n$$ in this case $$5.01$$

from scipy.stats import poisson
from datascience import *
import numpy as np

%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')

# Poisson r.v.
Pois = Table().with_column('PDF',np.random.poisson(lam=5,size=10000))
Pois.hist()

#log-likelihood
def l(lam):
logs = make_array()
for k in Pois.column(0):
logs = np.log(poisson.pmf(k=k,mu = lam))
return np.sum(logs)

# lambdas
lams = np.arange(3,7,0.1)

# likelihood
ls = make_array()
for lam in lams:
print(lam)
ls = np.append(ls, np.exp(l(lam)))

plots.plot(lams,ls)


However, according to the plot the MLE is approximately when lambda = 3

## 1 Answer

I got this plot, which looks pretty good, $$\lambda _{mle} \approx5 \approx \lambda$$

• Did you use the same code? Oct 8 '18 at 7:31
• yap! on python 3.7... though I needed to install the datascience package, never heard of it before. Oh and I remove the Pois.hist(), since it resulted in an error Oct 8 '18 at 7:33
• Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay. Oct 8 '18 at 7:43
• BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16 Oct 8 '18 at 7:47
• Not sure about the exponential decay, but maybe you looked at the distribution of the inverse? I don't want to confuse you too much but you can look at the time between events and you'll get exponential distribution, and Thanks! I'll check it out Oct 8 '18 at 7:50