population.data.set <- c( rep( 0, 20 ), rep( 1, 18 ) ) print( population.data.set ) # [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 n.repetitions <- 5000 set.seed( 2717282 ) sample.data.set <- sample( population.data.set, n.repetitions, replace = T ) cumulative.proportion <- cumsum( sample.data.set ) / ( 1:n.repetitions ) print( cbind( 1:10, sample.data.set[ 1:10 ], cumulative.proportion[ 1:10 ] ) ) # [,1] [,2] [,3] # [1,] 1 0 0.0000000 # [2,] 2 0 0.0000000 # [3,] 3 0 0.0000000 # [4,] 4 0 0.0000000 # [5,] 5 0 0.0000000 # [6,] 6 1 0.1666667 # [7,] 7 1 0.2857143 # [8,] 8 1 0.3750000 # [9,] 9 0 0.3333333 # [10,] 10 0 0.3000000 plot( 1:n.repetitions, cumulative.proportion, type = 'l', lwd = 1, col = 'blue', xlab = 'repetition number', lty = 2, ylab = 'cumulative proportion of red roulette numbers', ylim = c( 0, 1 ) ) abline( h = 18 / 38, lwd = 3, col = 'black' ) n.simulations <- 100 for ( i in 2:n.simulations ) { sample.data.set <- sample( population.data.set, n.repetitions, replace = T ) cumulative.proportion <- cumsum( sample.data.set ) / ( 1:n.repetitions ) lines( 1:n.repetitions, cumulative.proportion, lwd = 1, lty = 2, col = 'blue' ) Sys.sleep( 0.5 ) } abline( h = 18 / 38, lwd = 3, col = 'black' )