Skip to content

Instantly share code, notes, and snippets.

@dmarcelinobr
Created February 25, 2013 00:30
Show Gist options
  • Save dmarcelinobr/5026475 to your computer and use it in GitHub Desktop.
Save dmarcelinobr/5026475 to your computer and use it in GitHub Desktop.
N < - 8619170 # population size of voters
ss <- c(1000, 1200, 3000) # samples size
p <- .27 # .27 Serra .25 Haddad .19 Russomano true population proportion
nsim <- 100 # number of simulations
pop.prob <- list()
for (i in 1:length(ss)) {
n <- ss[i]
x <- rhyper(nsim, N * p, N * (1 - p), n)
pop.prob[[i]] <- x / n
}
names(pop.prob) <- paste("n =", ss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment