[Rd] RFC: lchoose() vs lfactorial() etc

Martin Maechler maechler at stat.math.ethz.ch
Tue Dec 15 09:49:28 CET 2009


lgamma(x) and lfactorial(x) are defined to return

 ln|Gamma(x)| {= log(abs(gamma(x)))} or  ln|Gamma(x+1)| respectively.

Unfortunately,  we haven't chosen the analogous definition for 
lchoose().

So, currently 

  > lchoose(1/2, 1:10)
   [1] -0.6931472 -2.0794415        NaN -3.2425924        NaN -3.8869494
   [7]        NaN -4.3357508        NaN -4.6805913
  Warning message:
  In lchoose(n, k) : NaNs produced
  > 

which (the NaN's) is not particularly useful.
(I have use case where I really have to workaround those NaNs.)

I herebey propose to *amend* the definition of lchoose() such
that it behaves analogously to  lgamma() and lfactorial(),
i.e., to return

   log(abs(choose(.,.))

Your comments are welcome.
Martin Maechler, ETH Zurich



More information about the R-devel mailing list