From bolker at ufl.edu  Wed Mar 19 23:15:27 2008
From: bolker at ufl.edu (Ben Bolker)
Date: Wed, 19 Mar 2008 22:15:27 +0000 (UTC)
Subject: [Rd]
	=?utf-8?q?choose_incorrect_for_fractional_and_some_negative_?=
	=?utf-8?q?integer=09values_=28PR=2310766=29?=
References: <20080319132533.E961D282EFF6@mail.pubhealth.ku.dk>
Message-ID: <loom.20080319T220841-857@post.gmane.org>

 <jerry.lewis <at> biogenidec.com> writes:

> 
> choose(-5,-7) uses integer arguments (as specified in Help)  and returns a 
> numeric value that is incorrect.  Either the function or the documentation 
> should be fixed.  If the function is not fixed, a warning or an error 
> would be helpful.
> 
> The fact that choose(n,k) usually returns choose(n,round(k,0)) is not 
> obvious from either the output or the documentation.  I suggest issuing a 
> warning when k is not an integer; a user might easily expect that choose 
> would coerce both arguments to integers, but only coercing k to an integer 
> is unusual and potentially misleading.

  Although perhaps (?) expected from a close reading of the documentation, which
says that n is real and k must be integer ...

> 
> The fact that choose(n,k) always rounds .5 up in k (contrary to the round 
> function documentation) is nowhere documented.
> 
> Help for coerce would lead a reader to expect k to be truncated toward 
> zero (as.integer), instead of rounding it.
> 

   Not being an R-core member I can't say it would be accepted, but since your
arguments seem to make sense it would be helpful if you could provide patches to
implement your suggested changes -- and perhaps a set of test code to
demonstrate the range of behaviors you are proposing.  

   The rounding behavior (   return R_IS_INT(n) ? floor(r + 0.5) : r; in C code)
is commented as "/* might have got rounding errors */", so I think it's intended
as a way to get the desired answer when a little bit of numeric fuzz is present
-- but I agree it seems like overkill.  I don't know whether R-core members have
on the top of their heads the standard ways of dealing with this situation ...

  Ben Bolker



[Rd] =?utf-8?q?choose_incorrect_for_fractional_and_some_negative_?= =?utf-8?q?integer=09values_=28PR=2310766=29?=
Ben Bolker