This assignment is based on the illustration of the Central Limit Theorem (CLT) presented in our textbook (Crawley, M. J. “Statistics: An introduction using R”, 2014).
You must read pages 70 to 73 of the book in order to produce a similar result.
Consider the ancient game of “craps” described on page 70. It involves the use of two 6-sided dice, and in its simplest form the two dice are thrown and the two scores added together.
In the book, the example simulates 10,000 plays of the game. You are required to use a number of simulations equal to 10 times the last 5 digits of your student ID number.
Follow the discussion presented in our textbook and produce plots as the ones in page 71 and page 72.
Make sure to report mean(mean.score)
and sd(mean.score)
for your experiment (see page 71). Comment on your results.
Can you think of another game/situation that can be simulated in a similar fashion?
If so, please give a brief description of the game/situation and explain/show how it would confirm the CLT.
# id number
id <- 04381*10
score <- 2:12
ways <- c(1,2,3,4,5,6,5,4,3,2,1)
game <- rep(score,ways)
game
## [1] 2 3 3 4 4 4 5 5 5 5 6 6 6 6 6 7 7 7 7 7 7 8 8
## [24] 8 8 8 9 9 9 9 10 10 10 11 11 12
sample(game,1)
## [1] 9
outcome <- numeric(id)
for (i in 1:id)
{
outcome[i] <- sample(game,1)
}
hist(outcome,breaks=(1.5:12.5))
mean.score <- numeric(id)
for (i in 1:id) mean.score[i] <- mean(sample(game,3))
hist(mean.score,breaks=(1.5:12.5))
mean(mean.score)
## [1] 6.998805
sd(mean.score)
## [1] 1.359584
The mean and standard deviation are almost the same numbers comparing to books results. It demostrate the central limit theorem
xv <- seq(2,12,0.1)
yv <- id*dnorm(xv,mean(mean.score),sd(mean.score))
hist(mean.score,breaks=(1.5:12.5),ylim=c(0,15000),col="yellow",main="")
lines(xv,yv,col="red")
*The coin example was created in conjunction with Gabriella B.
# 0 : tails
# 1 : heads
# 10000 people throwing the coin 10 times
# sum tails
outcome <- numeric(10000)
for(i in 1:10000) outcome[i] <- sum(sample(0:1,10,rep=T))
hist(outcome, breaks=(-0.5:10.5))
mean(outcome)
## [1] 4.9815
sd(outcome)
## [1] 1.560577