1
\$\begingroup\$

I am plotting a distribution of 10,000 samples of sum of 100 poisson variables, and overlaying that distribution of the approximate normal distribution. However, the normal distribution line does not show up. I also plotted with sum of 4 variables, in which case it worked. So what is the difference here that makes normal distribution disappear?

Here is my code in the sum of 4 variables case

final = c()
for (i in 1:10000){

sum = sum(rpois(4,2))
final = c(final,sum)
}



dens_final = density(final)
aprox_norm <- dnorm(min(final):max(final), 8,sqrt(8))
plot(dens_final)
lines(aprox_norm, col='red')

and here is my code of sum of 100 variables

final = c()
for (i in 1:10000){

sum = sum(rpois(100,2))
final = c(final,sum)
}

dens_final = density(final)
aprox_norm <- dnorm(min(final):max(final), 200,sqrt(200))
plot(dens_final)
lines(aprox_norm, col='red')

I have also attached images of the 2 plots as reference

plot of distribution of sum of 4 variables

plot of distribution of sum of 100 variables

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Your normal distribution is just outside of the plotting window. Use for instance plot(dens_final, xlim = c(0, 300)) and you'll see it. But that's not really a Code Review question (use Cross Validated for help on statistics, or Stack Overflow for questions about R programming). \$\endgroup\$ – Scarabee Oct 5 '20 at 0:44

Browse other questions tagged or ask your own question.