#=============================== # Law of Large Numbers simulator # (run event simulator function first) #=============================== end=1000 p=.4 n=1:end p.est=numeric(end) # Vector of zeros with length of end. for (i in n) { p.est[i]=sum(success(n[i],p))/n[i] # Proportion of successes out # of n[i] trials. } plot(n,p.est,type="l") abline(h=.4,lty=2)