0

I'm new to both statistics and R. I've generated 100 random samples from a Poisson distribution with lambda = 2.5 using:

 samples <- rpois(100,2.5)

I've successfully created a relative frequency histogram of the samples:

 hist(samples, prob=TRUE)

Now I need to overlay the pmf of the true Poisson distribution over the histogram but don't know how to generate the true function. I think this is probably very simple but just can't figure out what to do. Any help would be really appreciated.

Thanks!

zero323
  • 322,348
  • 103
  • 959
  • 935
user2840061
  • 11
  • 1
  • 1
  • 2
    `plot(table(samples)/length(samples)); points(0:8, dpois(0:8,lambda=2.5))` (I hope this isn't homework ...) – Ben Bolker Oct 02 '13 at 19:54
  • ... but you can be sure it's a repeat question. http://stackoverflow.com/questions/7605191/adding-a-best-fit-normal-on-top-of-a-histogram-in-r/7605889#7605889 – IRTFM Oct 02 '13 at 20:02
  • Sorry, it is for homework. Didn't know I shouldn't ask these kinds of questions here. Thanks though. I searched through R help, googled it, and looked on here (though obviously not well enough). Will try to be more thorough next time. – user2840061 Oct 02 '13 at 20:12
  • homework **is** allowed on SO: http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions, but I personally don't like answering those questions. – Ben Bolker Oct 02 '13 at 20:34
  • I would say it's not quite a dupe, because there are a few considerations that are specifically relevant to plotting discrete distributions (i.e., `hist()` and `curve()` are sub-optimal; they can be tweaked to work OK, but `plot(table(...))` and `points()` work better) – Ben Bolker Oct 02 '13 at 20:35
  • See also http://tolstoy.newcastle.edu.au/R/e12/help/10/10/1870.html – Ben Bolker Oct 02 '13 at 20:37

1 Answers1

-1

Get the distribution by plugging values from the domain into the Poisson probability mass function. The domain is 0-infinity. The pmf is [e^(-lamda)*lamda^k]/k_factorial See the wikipedia page for details: http://en.wikipedia.org/wiki/Poisson_distribution

brbaker
  • 172
  • 2
  • 9