Search code examples
rstatisticsprobabilitymeanpoisson

Finding the expectation of n Poisson values in R


enter image description here

I have written the following code:

n <- 5
lambda <- 2
randomNumbers <- rpois(n, lambda)
prob <- dpois(randomNumbers, lambda)

Is my code correct thus far?

How can I find the expected values of 5 Poisson values?

eX <- mean(randomNumbers)

or,

weighted.mean(randomNumbers, prob)

Solution

  • n <- 5
    lambda <- 2
    randomNumbers <- rpois(n, lambda)
    # estimate of P(X = 0), for example
    mean(randomNumbers == 0)
    # estimate of E[X]
    mean(randomNumbers)