### Simulate rolling a pair of fair dice. # There are 12 possible outcomes. Let x be the sum of pips you see on each roll # of the pair of fair dice. n <- 10000 x <- matrix(sample(1:6,2*n,replace=T),2,n) s <- apply(x,2,sum) br <- (1:13)-0.5 par(mfcol=c(4,1)) hist(s[1:100],breaks=br,probability=T,main="relative frequency plot - roll a pair of dice") hist(s[1:500],,breaks=br,probability=T,main="relative frequency plot - roll a pair of dice") hist(s[1:1000],breaks=br,probability=T,main="relative frequency plot - roll a pair of dice") hist(s[1:10000],breaks=br,probability=T,main="relative frequency plot - roll a pair of dice") p.obs <- table(s)/n p.exp <- c(1,2,3,4,5,6,5,4,3,2,1)/36 cbind(p.obs,p.exp)