I want to show law of large numbers. I simulate a sample of size n=1000, 1000, 10000 respectively from Poisson variates with mean 5, 10, 15, and 20. Then I estimate E(sqrt(x)) and Var(sqrt(x)). My current codes are:
f <- function(n, lambda) {
E <- mean(sqrt(rpois(n, lambda)))
VAR <- var(sqrt(rpois(n, lambda)))
return(c(E, VAR))
}
f(1000, 5)
f(1000, 10)
f(1000, 15)
f(1000, 20)
f(10000, 5)
f(10000, 10)
f(10000, 15)
f(10000, 20)
f(100000, 5)
f(100000, 10)
f(100000, 15)
f(100000, 20)
The outputs are not very in a beautiful way:
[1] 2.1811702 0.2771724
[1] 3.1130539 0.2616986
[1] 3.8524663 0.2417407
[1] 4.4322371 0.2531221
[1] 2.1679419 0.2881696
[1] 3.1306374 0.2568755
[1] 3.8376813 0.2554475
[1] 4.4458512 0.2567878
[1] 2.1715152 0.2858644
[1] 3.1164014 0.2612395
[1] 3.8393476 0.2577202
[1] 4.4426835 0.2541482