### Simulate flipping a fair coin. # There are two possible outcomes. Let x be the number of heads in n flips of a # fair coin. n <- 500 x <- sample(0:1,n,replace=T) p.hat <- cumsum(x) index <- 1:n p.hat <- p.hat/index plot(p.hat,main="relative frequency of heads",type="l",ylim=c(0,1)) p.obs <- p.hat[n] p.exp <- 1/2 cbind(p.obs,p.exp)