library(openintro)
data(COL)
Distributions of a single six sided die
#Generate a uniform random distribution from min to max
numcases <- 10000 #how many cases to generate
min <- 1 #set parameters
max <- 6
x<-sample(min:max,numcases,replace=TRUE) #generate random uniform numcases numbers from min to max
par(mfrow=c(2,1)) #stack two figures above each other
hist(x,main=paste( numcases," roles of a single die"),breaks=seq(min-.5,max+.5,1)) #show the histogram
boxplot(x, horizontal=TRUE,range=1) # and the boxplot
title("boxplot of a uniform random distribution")
Simulation of two six-sided dice
#generate a uniform random distribution from min to max for numcases samples of size 2
numcases <- 10000 #how many cases to generate
min <- 1 #set parameters
max <- 6
x <- sample(min:max,numcases,replace=TRUE)+sample(min:max,numcases,replace=TRUE)
par(mfrow=c(2,1)) #stack two figures above each other
hist(x,breaks=seq(1.5,12.5),main=paste( numcases," roles of a pair of dice")) #show the histogram
boxplot(x, horizontal=TRUE,range=1) # and the boxplot
title("boxplot of samples of size two taken from a uniform random distribution")
Simulation of 32 six-sided dice
#generate a uniform random distribution from min to max for numcases samples of size 2
numcases <- 10000 #how many cases to generate
min <- 1 #set parameters
max <- 6
x<-rep(1,numcases)
for(i in 1:32){
x <- x+sample(min:max,numcases,replace=TRUE)
}
par(mfrow=c(2,1)) #stack two figures above each other
hist(x,breaks=seq(32*min-.5,32*max+.5,1),main=paste( numcases," roles of thirty two dice"),col=COL[1,4]) #show the histogram
abline(v=32*3.5,col=COL[4,1])
boxplot(x, horizontal=TRUE,range=1) # and the boxplot
title("boxplot of samples of size thirty two taken from a uniform random distribution")