Question
Carefully read the R code for the simulation of Craps game; the code is bellow . Modify the code to include the stopping times (i.e.,
- Carefully read the R code for the simulation of Craps game; the code is bellow . Modify the code to include the stopping times (i.e., the total numbers of trials) to stop (win or lose) the game. Run a simulation for at least 10,000 runs. Report the results of your simulation: (a) what is the estimate of the probability of winning? (b) Obtain a "LLN type" of plot to visualize how the sequence of partial fractions converge to the theoretical probability of winning? (c) Obtain a histogram of the stopping times and what is the estimated average number of trials to stop the game?
The code:
##### Two pairs - Poker Game
## Consider poker games, the player is dealt five cards, a two-pairs is two cards showing the same numbers and## another two cardsshowing the same numbers (but not all four numbers the same) plus one extra card (not the ## same as any of the other numbers).
# Exact probability = 123552/2598960 = 0.047539
choose(13,2)*(choose(4,2)^2)*choose(11,1)*choose(4,1)/choose(52,5)
# = 123552/2598960 = 0.04753902
# Simulation
set.seed(7628)
n <- 100000
simlist <- numeric(n)
deck <- rep(1:13, times = 4)
for (i in 1:n) {
cards.hands <- sample(deck,5,replace=FALSE)
# use table() to get frequencies of each card
t.hands <- table(cards.hands)
success <- if (sum(t.hands==2)==2) 1 else 0
simlist[i] <- success }
mean(simlist)
# [1] 0.04783
## LLN plot
p.2pairs <- cumsum(simlist)/(1:n)
plot(p.2pairs, type = 'l', ylim= c(0.03, 0.06),
xlab= expression(italic(n)), ylab= expression(italic(p.2pairs)))
abline(h = 0.047539, col="blue")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started