我写了以下代码:
n <- 5
lambda <- 2
randomNumbers <- rpois(n, lambda)
prob <- dpois(randomNumbers, lambda)
到目前为止,我的代码是否正确?
如何找到5个泊松值的期望值?
eX <- mean(randomNumbers)
或
weighted.mean(randomNumbers, prob)
答案 0 :(得分:2)
n <- 5
lambda <- 2
randomNumbers <- rpois(n, lambda)
# estimate of P(X = 0), for example
mean(randomNumbers == 0)
# estimate of E[X]
mean(randomNumbers)