MHB Where Did the Monte Carlo Simulation Go Wrong?

AI Thread Summary
The Monte Carlo simulation and analytical solution for a game involving random number selection from the set {1,2,3,4,5} yielded differing expected values and variances. The analytical approach calculated a winning probability of 0.6, leading to an expected profit of -$340 after 17 games. In contrast, the simulation produced an expected profit of -$480.38, raising questions about the accuracy of the simulation setup. Clarification was sought on whether the selection of numbers was with or without replacement, as this significantly impacts the probability calculations and expected outcomes. Understanding the sampling method is crucial for reconciling the discrepancies between the two methods.
Lancelot1
Messages
26
Reaction score
0
Two numbers are bring chosen by random from the set {1,2,3,4,5}. If the sum of the two numbers is even, you win 100 dollars, otherwise you win nothing. In order to participate in the game, you pay $80. What is the expected value and variance of the profit after 17 games ?

I solved this one analytically and with Monte Carlo simulation and got different results, I wonder where my mistake it.

The Solution:

The probability of success in a single game is:

\[p=\frac{\binom{2}{2}\binom{3}{0}+\binom{2}{0}\binom{3}{2}}{\binom{5}{2}}=0.6\]

If we define X to be the number of successes, then

\[X:Bin(17,0.6)\]

Therefore:

\[E(X)=10.2, V(X)=4.08\]

The profit is a linear transformation of X:

\[Y=100X-1360\]

And thus:

\[E(Y)=100\cdot 10.2-1360=-340\]

\[V(Y)=10000\cdot 4.08=40800\]My R code is below, and it yields different results , e.g.:

\[E(Y)=-480.38 ... V(Y)=10000\cdot 4.08=42751.21\]

where is the mistake ?

n = 5000
successes = rep(0,n)
for (j in 1:n)
{
result = rep(0,17)
for (i in 1:17)
{
game.result = sample(1:5,2,replace = T)
if (sum(game.result)%%2==0)
{
result = 1
}
}
successes[j] = sum(result)
}
successes
mean(successes)
var(successes)

profit = 100*successes-1360
mean(profit)
var(profit)
 
Physics news on Phys.org
Please clarify- when you "choose two numbers from the set", can you choose the same number twice? That is, is this "sampling with replacement" or "sampling without replacement?

If it is the first, then there are 25 possible outcomes. The probability of odd on each pick is 3/5, the probability of even is 2/5. In order that the sum of the two numbers be even, both choices must be even, which has probability 4/25, or both choice odd which has probability 9/25. The probability of winning in anyone game is 4/25+ 9/25= 13/25. The expected winning in anyone game is (13/25)(100)= $52. You had to pay $80 to pay so you can expect to lose $28 on each game.

The other, sampling without replacement, is slightly harder. The probability you draw an even number the first time is still 2/5 but now there are 4 numbers to pick from with only one even. The probability you also draw an even number the second time is 1/4 so the probability you draw two even numbers, and win, is (2/5)(1/4)= 1/10. The probability you draw an odd number the first time is 3/5. Now there are 4 numbers to pick from, 2 odd. The probability you draw an odd number the second time is 2/4= 1/2 so the probability you draw two odd numbers, and win, is (3/5)(1/2)= 3/10. The expected value now is (3/10)(100)= $30. You had to pay $80 to play so your expected loss is $50.the second, 20 possible outcomes. In the f
 
Back
Top