The key is that you are pulling WITHOUT REPLACEMENT, so the conditional probabilities change as you pull. The expected ratio is only 4:4:4 is you pull with replacement. You can do a simpler analysis of 6 balls (3R, 3B, 3Y) and pulling 3 balls to see that the ratios are not even. If I did the analysis correctly, in that situation there is a 70% chance that the ratio is 2:1:0 and only a 30% chance that the ratio is 1:1:1.
I think you can perform the simulation more concisely if you use the SAMPLE function to pull the samples and use the TABULATE subroutine to analyze the ratio:
proc iml;
call randseed(123);
/* simulate 1000000 times */
n=1000000;
/* create binary variable equal to 1 if the ratio is 3:4:5 */
is_345 = j(n,1,0);
set = repeat('R',8) // repeat('G',8) // repeat('Y',8);
draws = sample(set, 12 //n, "NoReplace"); /* draw n samples of size 12 */
do i = 1 to n;
call tabulate(labels, freq, draws[i,]);
if ncol(freq)=3 then
is_345[i] = all(freq={3 4 5}) | all(freq={3 5 4}) |
all(freq={4 3 5}) | all(freq={5 3 4}) |
all(freq={4 5 3}) | all(freq={5 4 3}) ;
end;
/* estimate proportion of draws that result in 3:4:5 */
prop_345 = mean(is_345);
print prop_345;
In this simulation, the result is 0.4867 of the draws have ratio 3:4:5. Since this is less than 50%, the magician must have been using "magic" (that is, cheating) to win money.
... View more