Message-ID: <418F71DF.4080304@statistik.uni-dortmund.de>
Date: 2004-11-08T13:17:19Z
From: Uwe Ligges
Subject: About 'choose' function
In-Reply-To: <20041108115804.49535.qmail@web26304.mail.ukl.yahoo.com>
John wrote:
> Hello R-users,
>
> When I didn't know about the internal 'choose'
> function, I made such function, 'my.choose' below. But
> when I used them instead of choose(6000,20), they
> didn't give me any answer.
>
> What is the difference between 'choose', 'my.choose1',
> and 'my.choose2' below? That is, what is behind
> 'choose' function and what's the problem using 'prod'
> or 'gamma' function?
prod() calculates the whole product while choose() can do it the clever
way avoiding overflows. On my machine, .Machine$double.xmax is
1.797693e+308, hence prod(1:170) works while prod(1:171) is too much to
be represented correctly ...
Uwe Ligges
> Thanks a lot.
>
> John
>
> ##########
>
>
>>choose(6000,20)
>
> [1] 1.455904e+57
>
>>my.choose1 <- function(x,y) {
>
> prod(1:x)/(prod(1:y)*prod(1:(x-y))) }
>
>>my.choose1(6000,20)
>
> [1] NaN
>
>>my.choose2 <- function(x,y) {
>
> gamma(x+1)/(gamma(y+1)*gamma(x-y+1)) }
>
>>my.choose2(6000,20)
>
> [1] NaN
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html