myran <- function(num_males, prob_attend_male,
num_fem, prob_attend_fem) {
mframe <- data.frame(
M_or_F = rep("M", num_males),
attend = sample(c(0, 1),
size = num_males,
prob = c(1 - prob_attend_male, prob_attend_male), replace = TRUE)
)
fframe <- data.frame(
M_or_F = rep("F", num_fem),
attend = sample(c(0, 1),
size = num_fem,
prob = c(1 - prob_attend_fem, prob_attend_fem), replace = TRUE)
)
together <- rbind(mframe, fframe)
table(
together$M_or_F,
together$attend
)
}
# once
myran(20,.2,20,.2)
# 100 times (library(purrr))
purrr::map(1:100,~myran(20,.2,20,.2))