Simulate MLE for Poisson distribution

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












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










share|cite|improve this question



























    up vote
    1
    down vote

    favorite












    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










    share|cite|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      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










      share|cite|improve this question













      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







      python maximum-likelihood poisson-distribution simulation






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked 1 hour ago









      Sargis Iskandaryan

      1104




      1104




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          That's what I get from your code



          I got this plot, which looks pretty good, $lambda _mle approx5 approx lambda$






          share|cite|improve this answer




















          • Did you use the same code?
            – Sargis Iskandaryan
            21 mins ago










          • 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
            – Cherny
            19 mins ago











          • Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
            – Sargis Iskandaryan
            9 mins ago











          • BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
            – Sargis Iskandaryan
            5 mins ago










          • 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
            – Cherny
            2 mins ago











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "65"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f370705%2fsimulate-mle-for-poisson-distribution%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          That's what I get from your code



          I got this plot, which looks pretty good, $lambda _mle approx5 approx lambda$






          share|cite|improve this answer




















          • Did you use the same code?
            – Sargis Iskandaryan
            21 mins ago










          • 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
            – Cherny
            19 mins ago











          • Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
            – Sargis Iskandaryan
            9 mins ago











          • BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
            – Sargis Iskandaryan
            5 mins ago










          • 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
            – Cherny
            2 mins ago















          up vote
          2
          down vote



          accepted










          That's what I get from your code



          I got this plot, which looks pretty good, $lambda _mle approx5 approx lambda$






          share|cite|improve this answer




















          • Did you use the same code?
            – Sargis Iskandaryan
            21 mins ago










          • 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
            – Cherny
            19 mins ago











          • Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
            – Sargis Iskandaryan
            9 mins ago











          • BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
            – Sargis Iskandaryan
            5 mins ago










          • 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
            – Cherny
            2 mins ago













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          That's what I get from your code



          I got this plot, which looks pretty good, $lambda _mle approx5 approx lambda$






          share|cite|improve this answer












          That's what I get from your code



          I got this plot, which looks pretty good, $lambda _mle approx5 approx lambda$







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered 25 mins ago









          Cherny

          38416




          38416











          • Did you use the same code?
            – Sargis Iskandaryan
            21 mins ago










          • 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
            – Cherny
            19 mins ago











          • Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
            – Sargis Iskandaryan
            9 mins ago











          • BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
            – Sargis Iskandaryan
            5 mins ago










          • 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
            – Cherny
            2 mins ago

















          • Did you use the same code?
            – Sargis Iskandaryan
            21 mins ago










          • 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
            – Cherny
            19 mins ago











          • Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
            – Sargis Iskandaryan
            9 mins ago











          • BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
            – Sargis Iskandaryan
            5 mins ago










          • 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
            – Cherny
            2 mins ago
















          Did you use the same code?
          – Sargis Iskandaryan
          21 mins ago




          Did you use the same code?
          – Sargis Iskandaryan
          21 mins ago












          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
          – Cherny
          19 mins ago





          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
          – Cherny
          19 mins ago













          Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
          – Sargis Iskandaryan
          9 mins ago





          Ok, thank you. It is strange because I have been struggling with this two days. The plot I get looks like an exponential decay.
          – Sargis Iskandaryan
          9 mins ago













          BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
          – Sargis Iskandaryan
          5 mins ago




          BTW datascience package is from berkeley course data8. Here is a link if you are interested data8.org/fa16
          – Sargis Iskandaryan
          5 mins ago












          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
          – Cherny
          2 mins ago





          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
          – Cherny
          2 mins ago


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f370705%2fsimulate-mle-for-poisson-distribution%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery