Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #simulate population sizes, true means, and observed means
  2. library(tidyverse)
  3. library(truncnorm)
  4.  
  5. #sim data
  6. d = tibble(
  7. n = runif(1e4, min = 2, max = 100) %>% round(),
  8. true_mean = rnorm(1e4, mean = 100, sd = 15),
  9. observed_mean = NA
  10. )
  11.  
  12. #sample the means
  13. d$observed_mean = map2_dbl(d$n, d$true_mean, ~mean(rnorm(.x, mean = .y, sd = 15)))
  14.  
  15. #plot
  16. ggplot(d, aes(true_mean, observed_mean, color = n)) +
  17. geom_point(alpha = .5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement