Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. library(tidyverse)
  2. share <- .7
  3. population_size <- 10000
  4. sample_size <- 30
  5.  
  6. binary_var <- c(rep(T, population_size * share),
  7. rep(F, population_size * (1-share)))
  8.  
  9. many_sample_means <- function(x, sample_size, n_samples = 10000) {
  10. map(1:n_samples, ~sample(x, sample_size)) %>%
  11. map(mean) %>%
  12. unlist %>%
  13. table
  14. }
  15.  
  16.  
  17. sample_sizes <- c(10, 30, 50, 100)
  18. xlabs <- str_c("sample size: ", sample_sizes)
  19.  
  20. l <- c("n = 10" = 10, n_30 = 30, n_50 = 50, n_100 = 100) %>%
  21. map(~many_sample_means(binary_var, .))
  22.  
  23. par(mfrow = c(2,2))
  24.  
  25. for(i in seq_along(l)) {
  26. plot(l[[i]], main = xlabs[i], ylab = "count of realizations", xlab = "mean", xlim = c(0,1))
  27. }
  28.  
  29. par(mfrow = c(1,1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement