Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(123)
- n_m = n_f = p1 = p2 = list()
- n_m$total = sample(5:20)
- n_m$success = sapply(n_m$total, function(x) rbinom(1, x, .5))
- n_f$total = sample(5:20)
- n_f$success = sapply(n_f$total, function(x) rbinom(1, x, .5))
- p1$m = n_m$success/n_m$total
- p1$f = n_f$success/n_f$total
- p2$m = sum(n_m$success)/sum(n_m$total)
- p2$f = sum(n_f$success)/sum(n_f$total)
- > n_m
- $total
- [1] 9 16 10 19 17 5 18 13 20 8 14 7 12 6 15 11
- $success
- [1] 3 5 4 13 11 3 10 11 11 5 7 4 5 2 11 8
- > n_f
- $total
- [1] 16 20 5 11 14 7 8 15 6 13 17 12 18 19 10 9
- $success
- [1] 7 12 1 5 9 2 4 6 2 8 11 5 10 7 5 4
- > mean(p1$m/p1$f)
- [1] 1.293038
- > p2$m/p2$f
- [1] 1.153061
- >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement