# Problem_12_5_1.r

# Simulate 7 batches of ten normally distributed random numbers 
#   with mean 4 and variance .0037

nbatches=7
sampsize=10

mu=4.
sigmasq=.0037
set.seed(1) # Set seed to be able to replicate simulations
par(mfcol=c(3,2))
for (i in c(1:6)){
batches<-matrix(rnorm(nbatches*sampsize,mean=mu, sd=sqrt(sigmasq)), nrow=sampsize, ncol=nbatches)

boxplot(batches, xlab=paste("Batch for Batch Set ", i,sep=""))
}

# In this set of simulations, there are pairs of labs that appear quite different
#   in mean level: Batch Set 3, batches 1 and 4, Batch set 2, batches 2 and 5

#   in dispersion:  Batch Set 1, batches 5 and 7, Batch Set 6, batches 3 and 4.
#
# Note that with the smaple sample size (10), the variation will be moderate.
# If we change the sampsize to 250, there should be little differences in mean
# and dispersion due to the larger sample sizes.
sampsize=250
set.seed(1) # Set seed to be able to replicate simulations
par(mfcol=c(3,2))
for (i in c(1:6)){
  batches<-matrix(rnorm(nbatches*sampsize,mean=mu, sd=sqrt(sigmasq)), nrow=sampsize, ncol=nbatches)
  
  boxplot(batches, xlab=paste("Batch for Batch Set ", i,sep=""))
}

# In these plots, the mean level is quite constant as is the
# dispersion as measured by the inter-quartile range.