Question 3

The following function prints the results of 10 batches of 1,000 rolls each (cumulative results)

toss10k <- function(){
  batch = list()
  for (i in 1:30){
    n <- i * 1000
    trial <- rbinom(n=1000, size = 1, prob = 0.5)
    batch[[i]] <- sum(trial)
    diff <- Reduce("+", batch) - (n/2)
    cat("In batch",i,"we have Sn = ",Reduce("+", batch), "and Sn - n/2 =", diff, "and heads rate of", round(Reduce("+", batch)/n,3), ".\n")
  }
}

toss10k()
## In batch 1 we have Sn =  529 and Sn - n/2 = 29 and heads rate of 0.529 .
## In batch 2 we have Sn =  1035 and Sn - n/2 = 35 and heads rate of 0.518 .
## In batch 3 we have Sn =  1539 and Sn - n/2 = 39 and heads rate of 0.513 .
## In batch 4 we have Sn =  2031 and Sn - n/2 = 31 and heads rate of 0.508 .
## In batch 5 we have Sn =  2539 and Sn - n/2 = 39 and heads rate of 0.508 .
## In batch 6 we have Sn =  3051 and Sn - n/2 = 51 and heads rate of 0.508 .
## In batch 7 we have Sn =  3547 and Sn - n/2 = 47 and heads rate of 0.507 .
## In batch 8 we have Sn =  4026 and Sn - n/2 = 26 and heads rate of 0.503 .
## In batch 9 we have Sn =  4498 and Sn - n/2 = -2 and heads rate of 0.5 .
## In batch 10 we have Sn =  4994 and Sn - n/2 = -6 and heads rate of 0.499 .
## In batch 11 we have Sn =  5464 and Sn - n/2 = -36 and heads rate of 0.497 .
## In batch 12 we have Sn =  5937 and Sn - n/2 = -63 and heads rate of 0.495 .
## In batch 13 we have Sn =  6440 and Sn - n/2 = -60 and heads rate of 0.495 .
## In batch 14 we have Sn =  6892 and Sn - n/2 = -108 and heads rate of 0.492 .
## In batch 15 we have Sn =  7400 and Sn - n/2 = -100 and heads rate of 0.493 .
## In batch 16 we have Sn =  7905 and Sn - n/2 = -95 and heads rate of 0.494 .
## In batch 17 we have Sn =  8409 and Sn - n/2 = -91 and heads rate of 0.495 .
## In batch 18 we have Sn =  8908 and Sn - n/2 = -92 and heads rate of 0.495 .
## In batch 19 we have Sn =  9409 and Sn - n/2 = -91 and heads rate of 0.495 .
## In batch 20 we have Sn =  9939 and Sn - n/2 = -61 and heads rate of 0.497 .
## In batch 21 we have Sn =  10466 and Sn - n/2 = -34 and heads rate of 0.498 .
## In batch 22 we have Sn =  10955 and Sn - n/2 = -45 and heads rate of 0.498 .
## In batch 23 we have Sn =  11472 and Sn - n/2 = -28 and heads rate of 0.499 .
## In batch 24 we have Sn =  11994 and Sn - n/2 = -6 and heads rate of 0.5 .
## In batch 25 we have Sn =  12500 and Sn - n/2 = 0 and heads rate of 0.5 .
## In batch 26 we have Sn =  12966 and Sn - n/2 = -34 and heads rate of 0.499 .
## In batch 27 we have Sn =  13465 and Sn - n/2 = -35 and heads rate of 0.499 .
## In batch 28 we have Sn =  13985 and Sn - n/2 = -15 and heads rate of 0.499 .
## In batch 29 we have Sn =  14498 and Sn - n/2 = -2 and heads rate of 0.5 .
## In batch 30 we have Sn =  14987 and Sn - n/2 = -13 and heads rate of 0.5 .