10.7 C
London
Sunday, July 7, 2024
HomeRProbability Distributions in RHow to Plot a Poisson Distribution in R

How to Plot a Poisson Distribution in R

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

To plot the probability mass function for a Poisson distribution in R, we can use the following functions:

  • dpois(x, lambda) to create the probability mass function
  • plot(x, y, type = ‘h’) to plot the probability mass function, specifying the plot to be a histogram (type=’h’)

To plot the probability mass function, we simply need to specify lambda (e.g. the rate of occurrence of events) in the dpois() function.

For example, the following code illustrates how to plot a probability mass function for a Poisson distribution with lambda = 5:

#define range of "successes"
success #create plot of probability mass function
plot(success, dpois(success, lambda=5), type='h')

Poisson probability mass function

The x-axis shows the number of “successes” – e.g. the number of events that occurred – and the y-axis shows the probability of obtaining that number of successes in 20 trials.

We can add a title, change the axes labels, and increase the line width to make the plot more aesthetically pleasing:

success 

Poisson distribution probability mass function in R

We can use the following code to obtain the actual probabilities for each number of successes shown in the plot:

#prevent R from displaying numbers in scientific notation 
options(scipen=999) 

#define range of successes
success #display probability of success for each number of trials
dpois(success, lambda=5)

[1] 0.0067379469991 0.0336897349954 0.0842243374886 0.1403738958143
[5] 0.1754673697679 0.1754673697679 0.1462228081399 0.1044448629571
[9] 0.0652780393482 0.0362655774156 0.0181327887078 0.0082421766854
[13] 0.0034342402856 0.0013208616483 0.0004717363030 0.0001572454343
[17] 0.0000491391982 0.0000144527054 0.0000040146404 0.0000010564843
[21] 0.0000002641211

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories