# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- # Simulate a series of 200 fair coin flips: # flips = rbinom( 200, 1, 0.5 ) # Consider all 200 flips taken together as one experiment: hist( flips, breaks=c(-0.5,+0.5,1.5), probability=TRUE, main="long run frequency distribution of head/tail" ) # Generate 20 experiments of size 10 flips each to make a plot like Fig. 2.a: # all_empirical_freq = c() for( n in seq(1,20) ){ n_flips = 10 flips = rbinom( n_flips, 1, 0.5 ) all_empirical_freq = c( all_empirical_freq, sum(flips)/n_flips ) } plot( seq(1,20), all_empirical_freq, xlab='number of sequence', ylab='f(even)', ylim=c(0,1), main="n=10" ) abline(h=0.5)