Using ppois in r to calculate probabilities of random variable with variance

I'm working on a homework assignment on little sleep and hoping for some help. Here is the question I'm trying to write a script for:

Write a script in R to compute the following probabilities of a random variable that has Poisson Distribution with variance 16.

a) is less than 9

What I have is:

ppois(9, 16)


I know this is incorrect, however cannot think on how to correct the formula to get the mean from the variance.

• Hi, this is not a great SO question because it's not about code but about knowing the relationship between the mean and the variance in a poisson distribution which is very specific but I'm not going to say because I'm a professor and you are doing homework. Still you could Google it or look in any stats book.
– Elin
Mar 21, 2019 at 1:54
• I'm not sure I agree with your comment @Elin; OP clearly includes a code attempt, which makes this a coding question. From his code attempt I infer that he also seems to be clear on the variance-mean relationship of the Poisson distribution (he sets lambda = 16 in ppois). Mar 21, 2019 at 2:04
• "how to correct the formula to get the mean from the variance." ? Maybe I'm reading it wrong?
– Elin
Mar 21, 2019 at 2:05
• I think OP is confused about the definition of the distribution function: F(x <= x) vs. F(X < x). He was just looking in the wrong place. But I admit, perhaps I'm wrong. In any case, I think the downvotes are a bit harsh here. OP is a first time SO poster, he includes a clear problem statement, openly and clearly flags his question as homework, and includes a code attempt. That's more than I see with 90% of first-time posters. Mar 21, 2019 at 2:06
• Thank you all for being gentle. I'm struggling to grasp a few of these concepts regarding probability while also learning r. Appreciate the guidance. Will move to stats for any additional questions not code related.
– Matt Black
Mar 21, 2019 at 2:23

You are very close, barring a small but important detail involving discrete distributions.

For discrete distributions the cumulative distribution function is defined as

F(x) = Pr(X ≤ x)


(note the "less than or equal" sign).

So, in order to get the probability of observing values less than 9 we need to calculate

F(8) = Pr(X ≤ 8)


which is

ppois(8, lambda = 16)
#[1] 0.02198725


It's instructive to compare this number with a simulation-type experiment, where we draw N random numbers from a Poisson distribution with lambda = 16.

set.seed(2019)
N <- 10^7
x <- rpois(N, lambda = 16)


The probability of observing a number less than 9 is then

sum(x < 9) / length(x)
#[1] 0.0219958


which is very close to the theoretical value.

• Thank you @Maurits for your help! It's difficult to find help on writing r code AND understanding the math when my confidence in both is minuscule...and I'm on 3 hours sleep!
– Matt Black
Mar 21, 2019 at 2:14
• @MattBlack I think you could rewrite the question a bit to make it more clearly lead to this answer if this was what you were looking for.
– Elin
Mar 21, 2019 at 2:27
• @Elin Will ensure my questions are more succinct and reduce noise. Appreciate the feedback.
– Matt Black
Mar 21, 2019 at 2:47
• Glad it was helpful @MattBlack and good luck with your studies. If this answers your question please remember to close the question by setting the green check mark next to the answer. That way you keep SO tidy and help future SO users to identify relevant questions. It also grants a small reputation bonus to both the original poster and answerer. Mar 21, 2019 at 3:15
• Done and done @MauritsEvers! Really appreciate your time and tutelage. Mar 21, 2019 at 3:42