Discussion 5

Exercise 1.1 #3

In the early 1600s, Galileo was asked to explain the fact that, although the number of triples of integers from 1 to 6 with sum 9 is the same as the number of such triples with sum 10, when three dice are rolled, a 9 seemed to come up less often than a 10-supposedly in the experience of gamblers.

  1. Write a program to simulate the roll of three dice a large number of times and keep track of the proportion of times that the sum is 9 and the proportion of times it is 10.

We will first create a function that will randomly generate the roll of three dice and sum up the outcome of the dice.

# we declare our function name
sum_three_dice <- function (){
  dice_roll <- sample(x=1:6, size = 3, replace = TRUE) # roll 3 six-sided dice
  return (sum(dice_roll)) # compute the sum of the 3 dice
}

We will create yet another function to repeat our function above for as many times as we indicate and compute the proportion of the times we get a sum of 9 and 10.

# we declare our function name
proportions <- function(n){
  
  n_rolls <- replicate(n, sum_three_dice()) # replicate our function "n" times using r
  
  # counting how many times the sum is 9 or 10
  count_9 <-length(which(n_rolls == 9))
  count_10 <- length(which(n_rolls == 10))
  
  # divide the count by "n" to compute the proportions
  p_9 <- count_9/n
  p_10 <- count_10/n
  
  return(print(paste("Proportion of sum being 9:", p_9, "and the sum being 10:", p_10)))
}

Now we create 5 different simulations and observe the proportions of the times the sums were 9 or 10

# each simulation rolls the dice 10,000 times
set.seed(2)

simulation_1 <- proportions(10000)
## [1] "Proportion of sum being 9: 0.1119 and the sum being 10: 0.1276"
simulation_2 <- proportions(10000)
## [1] "Proportion of sum being 9: 0.1201 and the sum being 10: 0.1287"
simulation_3 <- proportions(10000)
## [1] "Proportion of sum being 9: 0.1134 and the sum being 10: 0.124"
simulation_4 <- proportions(10000)
## [1] "Proportion of sum being 9: 0.1142 and the sum being 10: 0.1272"
simulation_5 <- proportions(10000)
## [1] "Proportion of sum being 9: 0.1124 and the sum being 10: 0.1236"
  1. Can you conclue from your simulations that the gamblers were correct?

Yes, we can observe from our simulations that the proportions of the sum being 9 are less than the proportions of the sum being 10.