In: Math
Must solve in R code
Question 2
The random variable X is a payout table of a casino slot machine. The probability mass function is given:
X -5 0 2
10 20 40 60
1000
Probability 0.65 0.159
0.10 0.05 0.02 0.01
0.01 0.001
Please simulate the results for playing the slot machine 10,000,000
times. Find the mean of these 10,000,000 simulated payout outcomes
.
In R, we have first generated the samples from the distribution of X as below:
u~R(0,1)
if (u<..65)
x=-5
if( u>.65 && u<.65+.159)
x=0
if( u>.65+.159 && u<.65+.159+.10)
x=2
and so on.
Finally calculated the sample mean of generated x's and a frequency distribution of the generated x's.
We report the mean as -0.1577593.
R Program
nsim=10000000
x=numeric(nsim)
for(i in 1:nsim)
{
u=runif(1,0,1)
if(u<.65)
x[i]=-5
if(u>.65 && u<.809)
x[i]=0
if(u>.809 && u<.909)
x[i]=2
if(u>.909 && u<.959)
x[i]=10
if(u>.959 && u<.979)
x[i]=20
if(u>.979 && u<.989)
x[i]=40
if(u>.989 && u<.999)
x[i]=60
if(u>.999)
x[i]=1000
}
table(x)
cat("\n","Simulated Mean=",mean(x))
R Output
x
-5 0 2 10 20 40 60 1000
6498761 1589532 1001486 500392 199514 100199 100218 9898
Simulated Mean= -0.1577593
For any query in above, comment.