From rksh1 at cam.ac.uk  Tue Dec 15 10:20:56 2009
From: rksh1 at cam.ac.uk (Robin Hankin)
Date: Tue, 15 Dec 2009 09:20:56 +0000
Subject: [Rd] RFC: lchoose() vs lfactorial() etc
In-Reply-To: <19239.19864.396771.484772@lynne.math.ethz.ch>
References: <19239.19864.396771.484772@lynne.math.ethz.ch>
Message-ID: <4B2754F8.9010701@cam.ac.uk>

Hi Martin

I think you're absolutely right about this;
One thing I need again and again is
a multinomial function, and usually define:

 > lmultinomial
function (x)
{
    lfactorial(sum(x)) - sum(lfactorial(x))
}

 > multinomial
function (x)
{
    exp(lmultinomial(x))
}


It would be nice to have this in base R.

Is this the place to discuss having complex
arguments for gamma()?


best wishes

rksh






Martin Maechler wrote:
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>   


-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877



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