Skip to content

Instantly share code, notes, and snippets.

@3inar
Created October 18, 2017 13:23
Show Gist options
  • Save 3inar/d777ec009af625085700dde48030e018 to your computer and use it in GitHub Desktop.
Save 3inar/d777ec009af625085700dde48030e018 to your computer and use it in GitHub Desktop.
2017-10-18 untitled from rstudio
library(plyr)
set.seed(2017-06-08)
l=0.5
# this distribution has mean and variance both = l above
# importantly it never produces values < 0
plot(table(rpois(100, lambda=l)))
asymptotic_v_actual <- function(sample_size) {
means <- raply(100000, mean(rpois(sample_size, lambda=l)))
hist(means, prob=T, col="grey", border = NA,
main=paste0("sample size=", as.character(sample_size)))
curve(dnorm(x, mean=l, sd=sqrt(l/sample_size)), add=T, lwd=2, col="red")
}
asymptotic_v_actual(sample_size=5)
asymptotic_v_actual(sample_size=10)
asymptotic_v_actual(sample_size=100)
asymptotic_v_actual(sample_size=1000)
# probability of x < 0 for different sample sizes:
sizes <- 1:20
plot(sizes, pnorm(0, mean=l, sd=sqrt(l/sizes)), type="o",
main="p(x < 0) for different sample size")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment