Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: large numbers in comb(n,k) function: no success


From   Inna Becher <[email protected]>
To   [email protected]
Subject   Re: st: large numbers in comb(n,k) function: no success
Date   Thu, 05 Feb 2009 17:40:40 +0100

Thank you, Bill. I've just spoken with a mathematician, he showed me a similar way you did.
the formula I need is actually:

probability=1- [comb(n-m,k)/comb(n, k)]
so I have useful numbers after the computation. (n=180000, m=2, k=2000)

Inna

William Gould, StataCorp LP schrieb:
Inna Becher <[email protected]> wrote,
I would like to implement a comb(n,k) function. But my Stata does not allow it because of large n, k-numbers. N=180000 and k=2000. Is there any other way to do it? I wasn't successful by using exp(lnfactorial(n)) in mata as well.

Maarten buis <[email protected]> replied,
The outcome of comb(180000,2000) is going to be,
ridiculously large (> 8e+307) and it hits the limit of what can be stored in double precision [...]

Yes, that's right.  In fact, the answer is between 1e+4770 and 1e+4771.

comb(n, k) is defined

                             n!
           comb(n, k)  =  ---------   =  (n!)/( k! (n-k)! )
                          k! (n-k)!


Thus,
       ln(comb(n,k)    =  ln( (n!)/( k! (n-k)! ) )
                       =  ln(n!) - ln(k!) - ln(n-k)!

Stata has a lnfactorial() function, so we can plug in and get
           . scalar n = 180000

           . scalar k = 2000

           . display lnfactorial(n) - lnfactorial(k) - lnfactorial(n-k)
           10983.753

In log base 10, that 10983.753/ln(10) = 4770.1833. Hence my statement, the answer is between 1e+4770 and 1e+4771.

1e+4770 is unimagineably big. The number of particles in the observable universe is estimated to be between 1e+72 and 1e+87, so it would not be possible to tally 1e+4770.

-- Bill
   [email protected]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index