library(mosaic)
library(tidyverse)
#####################
### Amy and Betty ###
#####################
# Define gender: female = 1, male = 0
gender <- c(0, 1)
# Give birth to two kids
sample(gender, 2, replace=TRUE)
# Simulate birth of two kids 25,000 times
amy <- Do(25000) * sample(gender, 2, replace=TRUE)
betty <- Do(25000) * sample(gender, 2, replace=TRUE)
# Take a look at Amy's data
head(amy)
# Filter only the simulations with youngest female child
# Summarize proportion of those cases where both children are female
amy %>%
filter(V1 == 1) %>%
summarize(proportion = sum(V2) / n())
# Betty: Filter only cases with at least one female child
betty_female <- betty %>%
mutate(sum = V1+V2) %>%
filter(sum !=0)
# Betty: Keep only cases with two female children
betty_two_girls <- betty_female %>%
filter(sum == 2)
# Calculate proportion
count(betty_two_girls) / count(betty_female)
#####################
####### Chris #######
#####################
# Define days
days <- c("S", "M", "T", "W", "R", "F", "X")
# Simulate children
chris <- Do(25000) * sample(gender, 2, replace=TRUE)
# Simulate days of birth
chris_days <- Do(25000) * sample(days, 2, replace=TRUE)
# Merge data
chris$day1 <- chris_days$V1
chris$day2 <- chris_days$V2
# Look at data
head(chris)
# Find "sum" of kids (2 = 2 females; 0 = 2 males)
chris$kids <- chris$V1 + chris$V2
# Filter only boys on Tuesday
chris_Tboy <- chris %>%
filter(V1 == 0 & day1 == "T" | V2 == 0 & day2 == "T")
# Calculate proportion of these that have two boys (sum==0)
chris_twoboys <- chris_Tboy %>%
filter(kids == 0)
# Final proportion
count(chris_twoboys) / count(chris_Tboy)