3
$\begingroup$

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.

$\endgroup$
6
  • 2
    $\begingroup$ 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. $\endgroup$
    – Elin
    Mar 21, 2019 at 1:54
  • $\begingroup$ 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). $\endgroup$ Mar 21, 2019 at 2:04
  • $\begingroup$ "how to correct the formula to get the mean from the variance." ? Maybe I'm reading it wrong? $\endgroup$
    – Elin
    Mar 21, 2019 at 2:05
  • 1
    $\begingroup$ 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. $\endgroup$ Mar 21, 2019 at 2:06
  • 1
    $\begingroup$ 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. $\endgroup$
    – Matt Black
    Mar 21, 2019 at 2:23

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ 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! $\endgroup$
    – Matt Black
    Mar 21, 2019 at 2:14
  • 1
    $\begingroup$ @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. $\endgroup$
    – Elin
    Mar 21, 2019 at 2:27
  • 1
    $\begingroup$ @Elin Will ensure my questions are more succinct and reduce noise. Appreciate the feedback. $\endgroup$
    – Matt Black
    Mar 21, 2019 at 2:47
  • 1
    $\begingroup$ 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. $\endgroup$ Mar 21, 2019 at 3:15
  • 1
    $\begingroup$ Done and done @MauritsEvers! Really appreciate your time and tutelage. $\endgroup$
    – Matt Black
    Mar 21, 2019 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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