14.10 Exercises

1. In American Roulette you can also bet on green. There are 18 reds, 18 blacks and 2 greens (0 and 00). What are the chances the green comes out?

g<-2
bl<-18
r<-18

p_green<-g/(g+bl+r)
p_green
## [1] 0.05263158

2. The payout for winning on green is $17 dollars. This means that if you bet a dollar and it lands on green, you get $17. Create a sampling model using sample to simulate the random variable \(X\) for your winnings. Hint: see the example below for how it should look like when betting on red.

set.seed(2)
g<-2
b<-18
r<-18
pg<-g/(g+b+r)
png<-1-pg
x<-sample(c(17, -1), 1, replace=TRUE, prob=c(pg, png))
x
## [1] -1
x <-sample(c(1,-1), 1, prob = c(9/19, 10/19))

3. Compute the expected value of \(X\).

B<-10^6
x<-sample(c(17, -1), B, replace=TRUE, prob=c(pg, png))
mean(x)
## [1] -0.049276
y<-(17)*pg+-1*png

4. Compute the standard error of \(X\).

y<-(17--1)*sqrt(pg*png)

5. Now create a random variable S that is the sum of your winnings after betting on green 1000 times. Hint: change the argument size and replace in your answer to question 2. Start your code by setting the seed to 1 with set.seed(1).

set.seed(1)
g<-2
b<-18
r<-18
pg<-g/(g+b+r)
png<-1-pg
bet<-10^3
x<-sample(c(17, -1), bet, replace=TRUE, prob=c(pg, png))
S<-sum(x)

6. What is the expected value of \(S\)?

bet<-10^3
n<-1000
n*(17*pg+(-1*png))
## [1] -52.63158

7. What is the standard error of \(S\)?

se<-sqrt(1000)*abs(17--1)*sqrt(pg*png)

8. What is the probability that you end up winning money? Hint: use the CLT.

#CLT calculates avg=n*(pg-png)=mu.
g<-2
b<-18
r<-18
pg<-g/(g+b+r)
png<-1-pg
n<-1000
mu<-n*(pg*17-1*(png))
#CLT calculates standard error=sqrt(n)*abs(b-a)*sqrt(p*(1-p)).
se<-sqrt(n)*abs(17--1)*sqrt(pg*png)
1-pnorm(0, mu, se)
## [1] 0.3394053

9. Create a Monte Carlo simulation that generates 1,000 outcomes of \(S\). Compute the average and standard deviation of the resulting list to confirm the results of 6 and 7. Start your code by setting the seed to 1 with set.seed(1).

set.seed(1)
g<-2
b<-18
r<-18
pg<-g/(g+b+r)
png<-1-pg
bet<-10^4
n<-10^3
roulette_winnings <- function(n){
  X <- sample(c(17, -1), n, replace=TRUE, prob=c(pg, png))
  sum(X)
}
S<-replicate(bet, roulette_winnings(n))
mean(S)
## [1] -52.3324
sd(S)
## [1] 126.9762

10. Now check your answer to 8 using the Monte Carlo result.

mean(S>0)
## [1] 0.3391

11. The Monte Carlo result and the CLT approximation are close, but not that close. What could account for this? 1,000 simulations is not enough. If we do more, they match. The CLT does not work as well when the probability of success is small. In this case, it was 1/19. If we make the number of roulette plays bigger, they will match better. The difference is within rounding error. The CLT only works for averages.

The CLT does not work as well when the probability of success is small. In this case, it was 1/19. If we make the number of roulette plays bigger, they will match better.

12. Now create a random variable \(Y\) that is your average winnings per bet after playing off your winnings after betting on green 1,000 times.

set.seed(1)
n<-1000
pg<-2/38
png<-1-pg
X<-sample(c(-1,17), replace=TRUE, n, prob=c(png, pg))
Y<-mean(X)

13. What is the expected value of \(Y\)?

Y<-pg*17+png*-1

14. What is the standard error of \(Y\)?

n<-1000
se<-abs(-1-17)*sqrt(png*pg)/(sqrt(n))

15. What is the probability that you end up with winnings per game that are positive? Hint: use the CLT.

avg<-17*pg-1*png
se<-1/(sqrt(n))*(17--1)*sqrt(png*pg)
1-pnorm(0, avg, se)
## [1] 0.3394053

16. Create a Monte Carlo simulation that generates 2,500 outcomes of \(Y\). Compute the average and standard deviation of the resulting list to confirm the results of 6 and 7. Start your code by setting the seed to 1 with set.seed(1).

set.seed(1)
g<-2
b<-18
r<-18
pg<-g/(g+b+r)
png<-1-pg
bet<-2500
n<-10^3
roulette_winnings <- function(n){
  X <- sample(c(17, -1), n, replace=TRUE, prob=c(pg, png))
  sum(X)
}
Y<-replicate(bet, roulette_winnings(n))
mean(Y)
## [1] -54.3376
sd(Y)
## [1] 125.9509

17. Now check your answer to 8 using the Monte Carlo result.

mean(Y>0)
## [1] 0.3372

18. The Monte Carlo result and the CLT approximation are now much closer. What could account for this?

The CLT works better when the sample size is larger. We increased from 1,000 to 2,500.