1
$\begingroup$

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

$\endgroup$

closed as off-topic by Hong Ooi, Peter Flom Oct 8 '18 at 11:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Hong Ooi, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

2
$\begingroup$

That's what I get from your code

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

$\endgroup$
  • $\begingroup$ Did you use the same code? $\endgroup$ – Sargis Iskandaryan Oct 8 '18 at 7:31
  • $\begingroup$ 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 $\endgroup$ – Cherny Oct 8 '18 at 7:33
  • $\begingroup$ Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay. $\endgroup$ – Sargis Iskandaryan Oct 8 '18 at 7:43
  • $\begingroup$ BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16 $\endgroup$ – Sargis Iskandaryan Oct 8 '18 at 7:47
  • $\begingroup$ 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 $\endgroup$ – Cherny Oct 8 '18 at 7:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.