guido111
guido111
  • Threads: 10
  • Posts: 707
Joined: Sep 16, 2010
November 3rd, 2010 at 9:45:30 PM permalink
Looking for a formula that can be used in a spread sheet to calculate the probabilities of unique/repeat #s for an American Roulette Wheel. 38 numbers.
I have always run simulations but a friend said to use factorials as in "next 5 numbers" example below.( He is on vacation for 2 weeks or I would sit him down and show me how to use factorials)
It is beyond me.

I can get this far using a sledge hammer approach.

next 2 numbers
unique/repeats
2/0 (38/38)*(37/38) = 0.973684211
1/1 (38/38)*(1/38) = 0.026315789

next 3 numbers
unique/repeats
3/0 (38/38)*(37/38)*(36/38) = 0.922437673
2/1 [(38/38)*(37/38)*(2/38)]+[(38/38)*(1/38)*(37/38)] = 0.076869806
1/2 (38/38)*(1/38)*(1/38) = 0.000692521

next 4 numbers
unique/repeats
4/0 (38/38)*(37/38)*(36/38)*(35/38) = 0.849613646
3/1 [(38/38)*(37/38)*(36/38)*(3/38)]+[(38/38)*(37/38)*(2/38)*(36/38)]+[((38/38)*(1/38)*(37/38)*(36/38))] = 0.145648054
2/2 1-(D21(4/0)+D22(3/1)+D24(1/3)) = 0.004720076
1/3 (38/38)*(1/38)*(1/38)*(1/38) = 0.000018224

Using the sledge hammer approach becomes time consuming if you want to go up to 38 spins.
There must be a recursive formula.

next 5 numbers
5/0 =(FACT(38)/FACT(33))/(38^5) = 0.760180631
4/1 =((FACT(38)/FACT(34))/(38^4))*(10/38) = 0.223582539
3/2 =((FACT(38)/FACT(35))/(38^3))*((25/38)^1/38)... I do not understand ((25/38)^1/38) = 0.015970181
I'm lost at this point!!!
2/3
1/4

Any good ideas on how to create a recursive formula?
For now I stick with simulations.
weaselman
weaselman
  • Threads: 20
  • Posts: 2349
Joined: Jul 11, 2010
November 4th, 2010 at 5:47:50 AM permalink
I am not sure I understand what you are trying to do ... Are you looking for the probability of m unique numbers out of n trials?

If so,

P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);
P(0,0) = 1;
P(0,m) = P(n,0) = 0;
"When two people always agree one of them is unnecessary"
guido111
guido111
  • Threads: 10
  • Posts: 707
Joined: Sep 16, 2010
November 4th, 2010 at 10:35:00 PM permalink
Quote: weaselman

I am not sure I understand what you are trying to do ... Are you looking for the probability of m unique numbers out of n trials?

If so,

P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);
P(0,0) = 1;
P(0,m) = P(n,0) = 0;


yes
Take my example of the next 4 spins.
I want to know the probability of ALL the possible outcomes of exactly 4 spins.

unique/repeats
4/0 (38/38)*(37/38)*(36/38)*(35/38) = 0.849613646
In 4 spins NO repeat numbers

3/1 [(38/38)*(37/38)*(36/38)*(3/38)]+[(38/38)*(37/38)*(2/38)*(36/38)]+[((38/38)*(1/38)*(37/38)*(36/38))] = 0.145648054
In 3 spins 1 repeat number... and it could happen on the 2nd, 3rd or 4th spin

2/2 1-(D21(4/0)+D22(3/1)+D24(1/3)) = 0.004720076
1/3 (38/38)*(1/38)*(1/38)*(1/38) = 0.000018224
In 4 spins all numbers are the same. 3 repeats

Let me see if your formula will work.
P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);
There must be a power in there somewhere
weaselman
weaselman
  • Threads: 20
  • Posts: 2349
Joined: Jul 11, 2010
November 5th, 2010 at 7:54:41 AM permalink
It is easier to approach the problem in terms of counting unique numbers instead of repeats. "Number of repeats" is ambigous. For example 1,1,2,2,3,3,3,4 is how many repeats - 3 or 7 or 4? Depending on the answer, there are other problems too. For example, if you say, this is 3 repeats (1, 2 and 3 repeated), then something like 1,1,1,2,2,3,3,3 has to count as the same outcome (but it has a very different probability).
If you just look at the number of uniques, you avoid all those problems - it's clearly 4 in one case, and 3 in the other.


Quote: guido111


Let me see if your formula will work.
P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);
There must be a power in there somewhere



The power (and the factorial) is hidden in the recursion.
"When two people always agree one of them is unnecessary"
7winner
7winner
  • Threads: 9
  • Posts: 198
Joined: May 31, 2010
November 5th, 2010 at 11:53:07 AM permalink
Quote: weaselman


If you just look at the number of uniques, you avoid all those problems - it's clearly 4 in one case, and 3 in the other.



So I understand guido's question.

In 4 consecutive spins on an American Roulette wheel (38 numbers)
There could be 4 unique numbers (1,2,3,4)
3 unique numbers (1,2,3,3,)or(1,2,2,3)or(1,1,2,3)
2 unique numbers (1,1,2,2)or(1,2,1,2)
1 unique number(7,7,7,7)

To use this formula:
P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);

m=unique numbers=3
n=spins=4
= (39-3)/38*P(4-1,3-1) + (4-1)/38*P(4-1,3);
question:what is P(4-1,3-1) or what is the (,)
is it 4-1^3-1
can this be done in Excel or a spreadsheet?
7 winner chicken dinner!
weaselman
weaselman
  • Threads: 20
  • Posts: 2349
Joined: Jul 11, 2010
November 5th, 2010 at 12:01:53 PM permalink
Quote: 7winner


P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);



Sure. Number 39 consequentive columns 0 through 38. The column number is will correspond to N.
Now number 39 rows 0 through 39, the row number will be M.
Fill the column #0 and the row #0 with zeroes, except put 1 into the corner cell (0 column, 0 row);
Now, pick the next empty cell (1,1), and put the formula into it, replacing P(n-1,m-1) with the reference to the cell one to the left and one up, and P(n-1,m) wiht the one to the left in the same row.
Fill in the rest of the matrix (excel should take care of updating the cell references for you), and enjoy :)
"When two people always agree one of them is unnecessary"
7winner
7winner
  • Threads: 9
  • Posts: 198
Joined: May 31, 2010
November 5th, 2010 at 1:38:17 PM permalink
Quote: weaselman

Sure. Number 39 consequentive columns 0 through 38. The column number is will correspond to N.
Now number 39 rows 0 through 39, the row number will be M.
Fill the column #0 and the row #0 with zeroes, except put 1 into the corner cell (0 column, 0 row);
Now, pick the next empty cell (1,1), and put the formula into it, replacing P(n-1,m-1) with the reference to the cell one to the left and one up, and P(n-1,m) wiht the one to the left in the same row.
Fill in the rest of the matrix (excel should take care of updating the cell references for you), and enjoy :)



Thank you.
Nice work. Now I see the light.
7 winner chicken dinner!
guido111
guido111
  • Threads: 10
  • Posts: 707
Joined: Sep 16, 2010
November 5th, 2010 at 1:42:32 PM permalink
Quote: weaselman


Fill in the rest of the matrix (excel should take care of updating the cell references for you), and enjoy :)


Thank you weaselman.
and I do enjoy.

That was easy to do and to understand!
I better stop using sledge hammers to do precision math work!
MichaelBluejay
MichaelBluejay
  • Threads: 86
  • Posts: 1680
Joined: Sep 17, 2010
August 18th, 2019 at 9:10:52 PM permalink
Quote: weaselman

Are you looking for the probability of m unique numbers out of n trials? If so,

P(n,m) = (39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);

weaselman, I have this exact question too, but I'm afraid I don't understand your answer.

(1) Where did the 39 come from? Is it just the number of possible outcomes of one trial plus one?

(2) Are the 38's the number of possible outcomes from one trial?

(3) The recursion looks like it will happen forever. Indeed, when I call the function with Javascript, I get the error "Maximum call stack size exceeded."

<input id=output onclick=this.value=P(37,37)>

<script>
function P(n,m) { return P(39-m)/38*P(n-1,m-1) + (n-1)/38*P(n-1,m);}
</script>

How can this be programmed (or written without recursion, so I can program it)?
I run Easy Vegas ( https://easy.vegas )
7craps
7craps
  • Threads: 18
  • Posts: 1977
Joined: Jan 23, 2010
August 18th, 2019 at 10:41:47 PM permalink
Quote: MichaelBluejay

weaselman, I have this exact question too, but I'm afraid I don't understand your answer.

How can this be programmed (or written without recursion, so I can program it)?

for Excel, it is slow and messy just for a 39x39 matrix for each cell probability

R is way easier using a transition matrix (even Excel vba) and can easily be converted to javascript.
This is actually a variation of the coupon collecting problem, number of coupons collected and the probabilities after N draws.
My R code can be found here for any interested: https://sites.google.com/view/krapstuff/roulette
section 1r.
results for 37 numbers and 37 spins
u=24 means 24 unique numbers
> cc.draws(37,37)#0 Roulette, 37 numbers and spins
[1] "Number of numbers:37, spins:37, mean numbers show:23.5745, mean numbers NOT shown:13.4255"
not drawn Probability cumulative
u=1 36 3.505402835209287e-57 3.505402835209287e-57
u=2 35 8.672020148914835e-45 8.672020148918339e-45
u=3 34 3.314692573547716e-37 3.314692660267917e-37
u=4 33 1.181828396058428e-31 1.181831710751088e-31
u=5 32 3.000862968528566e-27 3.000981151699641e-27
u=6 31 1.353451338520529e-23 1.353751436635699e-23
u=7 30 1.768441721182332e-20 1.769795472618967e-20
u=8 29 8.959214842349408e-18 8.976912797075598e-18
u=9 28 2.122121911879776e-15 2.131098824676851e-15
u=10 27 2.668810406674974e-13 2.690121394921743e-13
u=11 26 1.950286896969477e-11 1.977188110918694e-11
u=12 25 8.848652985269136e-10 9.046371796361005e-10
u=13 24 2.620176869821741e-08 2.710640587785351e-08
u=14 23 5.261661586746048e-07 5.532725645524582e-07
u=15 22 7.383252426941282e-06 7.93652499149374e-06
u=16 21 7.411821128636426e-05 8.2054736277858e-05
u=17 20 0.0005422692213502838 0.0006243239576281418
u=18 19 0.00293391179997579 0.003558235757603932
u=19 18 0.01187191625199462 0.01543015200959855
u=20 17 0.03623411297966621 0.05166426498926475
u=21 16 0.08391608620844208 0.1355803511977068
u=22 15 0.1480232196433522 0.2836035708410591
u=23 14 0.1991885036499151 0.4827920744909742
u=24 13 0.2043690022411817 0.6871610767321559
u=25 12 0.1594366767704862 0.8465977535026421
u=26 11 0.0940910790104586 0.9406888325131006
u=27 10 0.04167532060124458 0.9823641531143452
u=28 9 0.01370132987004642 0.9960654829843917
u=29 8 0.003293428397655762 0.9993589113820475
u=30 7 0.0005672008922863491 0.9999261122743338
u=31 6 6.81047323781154e-05 0.9999942170067119
u=32 5 5.492144751551008e-06 0.9999997091514634
u=33 4 2.821730077624601e-07 0.9999999913244711
u=34 3 8.540410436050481e-09 0.9999999998648816
u=35 2 1.342486662710851e-10 0.9999999999991303
u=36 1 8.684549839638909e-13 0.9999999999999988
u=37 0 1.303986462408241e-15 1
[1] "Number of numbers:37, spins:37, mean numbers show:23.5745, mean numbers NOT shown:13.4255"

R can suffer from decimal rounding errors (well known) as well as javascript
there are ways to get around that

added: 8/19
for a non Markov chain solution
using inclusion/exclusion
pari/gp code (online here: https://pari.math.u-bordeaux.fr/gp.html)
pari/gp is arbitrary precision
(less code than R Markov chain)
gp > \\ exact X uniques V2
gp > s=37;\\spins
gp > u=24;\\uniques
gp > n=37;\\number of numbers
gp > a=binomial(s,u)*sum(k=0,u,((-1)^k*\
binomial(u,k)*(u-k)^n)/n^s);
gp > aDec=1.*a;
gp > print(a)
%6 = 1575706646773794798146077150283100638656856064000000000/7710105884424969623139759010953858981831553019262380893
gp > print(aDec)
%7 = 0.20436900224118169584948252577079534716
Last edited by: 7craps on Aug 19, 2019
winsome johnny (not Win some johnny)
  • Jump to: