A grandma is a heterozygous carrier of Huntington’s disease. What is the probability that her daughter has 5 healthy children?

Probability that the mother is a carrier

proba_mother_carrier <- 1/2

Function to compute the probability that she gets 5 healthy children

state_of_the_mother takes value 0 if she is not a carrier, 1 if she is.

generates5Children <- function (state_of_the_mother) {
  we_have_5_healthy_children = FALSE
  if (state_of_the_mother == 0 ) {
    we_have_5_healthy_children = TRUE
  }
  else if (state_of_the_mother == 1) {
    number_of_sick_children <- rbinom(n=1, size=5, prob=1/2)
    if (number_of_sick_children ==0) {
      we_have_5_healthy_children = TRUE
    }
  }
  return (we_have_5_healthy_children)
}

Function to simulate the whole family

simulateFamily <- function (proba_mother_carrier) {
  state_of_the_mother <- rbinom(n=1, size=1, prob=proba_mother_carrier)
  we_have_5_healthy_children = generates5Children(state_of_the_mother)
  if (we_have_5_healthy_children == TRUE) {
    return (1)
  }
  else {
    return (0)
  }
}

Computing the probability of getting 5 healthy children by repeating the experiment 1000 times

counter = 0
for(i in 1:10000) {
  counter = counter + simulateFamily(proba_mother_carrier)
}
print("Number of times we got 5 healthy children: ")
## [1] "Number of times we got 5 healthy children: "
print(counter)
## [1] 5122

Investigating the variation

counters = c()
for (j in 1:1000) {
  counter = 0
  for(i in 1:10000) {
    counter = counter + simulateFamily(proba_mother_carrier)
  }
  counters <- c(counters, counter)
}
hist (counters/100, n=20, main="Distribution of the proportion of\n families with 5 healthy children")