[R] inconsistency between gamma and choose functions
Cowpertwait, Paul
P.S.Cowpertwait at massey.ac.nz
Thu Dec 13 23:38:11 CET 2001
Please can someone explain why I seem to get these contradictory results?
choose(5,2)
[1] 10
gamma(6)/(gamma(3)*gamma(4))
[1] 10
gamma(6)/(gamma(3)*gamma(4)) == choose(5,2)
[1] TRUE
# all's well so far.
# now look what happens:
gamma(21)/(gamma(6)*gamma(16)) == choose(20,5)
[1] FALSE
# check individual terms:
gamma(21)/(gamma(6)*gamma(16))
[1] 15504
choose(20,5)
[1] 15504
# so they are the same, BUT we get FALSE when comparing - a contradiction!
gamma(21)/(gamma(6)*gamma(16)) == choose(20,5)
[1] FALSE
# the problem seems to have root in the gamma function, because:
choose(20,5)
[1] 15504
choose(20,5) == 15504
[1] TRUE
# but,
gamma(21)/(gamma(6)*gamma(16)) == 15504
[1] FALSE
# and yet ..
gamma(21)/(gamma(6)*gamma(16))
[1] 15504
# a function to 'compare' shows FALSE starts to appear when n >= 10. Why the
inconsistency?
compare <- function (n, k) choose(n,k) ==
gamma(n+1)/(gamma(k+1)*gamma(n-k+1))
compare(5,2)
[1] TRUE
compare(10,2)
[1] FALSE
compare(9,2)
[1] TRUE
compare(9,3)
[1] TRUE
#etc.
_____________________________________
Paul S.P. Cowpertwait
IIMS, Massey University, Albany,
Private Bag 102 904
North Shore Mail Centre
Auckland, NZ
Tel (+64) (9) 443 9799 ext 9488
http://www.massey.ac.nz/~pscowper
_____________________________________
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list