Displaying 11 results from an estimated 11 matches for "r_is_int".
2020 Jan 14
4
[R] choose(n, k) as n approaches k
...ctly zero and we should return 1, that we either return 0 (negative case) or n (positive case; because the n(n-1)(n-2)... product has at least one factor). In the other cases, we get 1 or n(n-1)(n-2)...(n-k+1) which if n is near-integer gets rounded to produce an integer, due to the
return R_IS_INT(n) ? R_forceint(r) : r;
part.
-pd
> On 14 Jan 2020, at 17:02 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
> On 14/01/2020 10:50 a.m., peter dalgaard wrote:
>>> On 14 Jan 2020, at 16:21 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>>...
2020 Jan 14
2
[R] choose(n, k) as n approaches k
...m., peter dalgaard wrote:
>> Yep, that looks wrong (probably want to continue discussion over on R-devel)
>> I think the culprit is here (in src/nmath/choose.c)
>> if (k < k_small_max) {
>> int j;
>> if(n-k < k && n >= 0 && R_IS_INT(n)) k = n-k; /* <- Symmetry */
>> if (k < 0) return 0.;
>> if (k == 0) return 1.;
>> /* else: k >= 1 */
>> if n is a near-integer, then k can become non-integer and negative. In your case,
>> n == 4 - 1e-7
>> k == 4
>> n -...
2020 Jan 14
1
[R] choose(n, k) as n approaches k
Yep, that looks wrong (probably want to continue discussion over on R-devel)
I think the culprit is here (in src/nmath/choose.c)
if (k < k_small_max) {
int j;
if(n-k < k && n >= 0 && R_IS_INT(n)) k = n-k; /* <- Symmetry */
if (k < 0) return 0.;
if (k == 0) return 1.;
/* else: k >= 1 */
if n is a near-integer, then k can become non-integer and negative. In your case,
n == 4 - 1e-7
k == 4
n - k == -1e-7 < 4
n >= 0
R_IS_INT(n) = TRUE (relative di...
2020 Jan 15
1
[R] choose(n, k) as n approaches k
...should return 1, that we either return 0 (negative case) or n (positive case; because the n(n-1)(n-2)... product has at least one factor). In the other cases, we get 1 or n(n-1)(n-2)...(n-k+1) which if n is near-integer gets rounded to produce an integer, due to the
>>
>> return R_IS_INT(n) ? R_forceint(r) : r;
>>
>> part.
>>
>> -pd
>>
>>
>>
>>> On 14 Jan 2020, at 17:02 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>>
>>> On 14/01/2020 10:50 a.m., peter dalgaard wrote:
>>>>> On...
2020 Jan 13
3
choose(n, k) as n approaches k
This struck me as incorrect:
> choose(3.999999, 4)
[1] 0.9999979
> choose(3.9999999, 4)
[1] 0
> choose(4, 4)
[1] 1
> choose(4.0000001, 4)
[1] 4
> choose(4.000001, 4)
[1] 1.000002
Should base::choose(n, k) check whether n is within machine precision of k and return 1?
Thanks,
Erik
***
sessionInfo()
R version 3.6.0 beta (2019-04-15 r76395)
Platform: x86_64-apple-darwin15.6.0
2020 Jan 13
3
choose(n, k) as n approaches k
This struck me as incorrect:
> choose(3.999999, 4)
[1] 0.9999979
> choose(3.9999999, 4)
[1] 0
> choose(4, 4)
[1] 1
> choose(4.0000001, 4)
[1] 4
> choose(4.000001, 4)
[1] 1.000002
Should base::choose(n, k) check whether n is within machine precision of k and return 1?
Thanks,
Erik
***
sessionInfo()
R version 3.6.0 beta (2019-04-15 r76395)
Platform: x86_64-apple-darwin15.6.0
2020 Jan 14
0
[R] choose(n, k) as n approaches k
...and we should return 1, that we either return 0 (negative case) or n (positive case; because the n(n-1)(n-2)... product has at least one factor). In the other cases, we get 1 or n(n-1)(n-2)...(n-k+1) which if n is near-integer gets rounded to produce an integer, due to the
>
> return R_IS_INT(n) ? R_forceint(r) : r;
>
> part.
>
> -pd
>
>
>
>> On 14 Jan 2020, at 17:02 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>
>> On 14/01/2020 10:50 a.m., peter dalgaard wrote:
>>>> On 14 Jan 2020, at 16:21 , Duncan Murdoch <m...
2020 Jan 14
0
[R] choose(n, k) as n approaches k
...07 a.m., peter dalgaard wrote:
> Yep, that looks wrong (probably want to continue discussion over on R-devel)
>
> I think the culprit is here (in src/nmath/choose.c)
>
> if (k < k_small_max) {
> int j;
> if(n-k < k && n >= 0 && R_IS_INT(n)) k = n-k; /* <- Symmetry */
> if (k < 0) return 0.;
> if (k == 0) return 1.;
> /* else: k >= 1 */
>
> if n is a near-integer, then k can become non-integer and negative. In your case,
>
> n == 4 - 1e-7
> k == 4
> n - k == -1e-7 &l...
2020 Jan 14
0
[R] choose(n, k) as n approaches k
...e:
>>> Yep, that looks wrong (probably want to continue discussion over on R-devel)
>>> I think the culprit is here (in src/nmath/choose.c)
>>> if (k < k_small_max) {
>>> int j;
>>> if(n-k < k && n >= 0 && R_IS_INT(n)) k = n-k; /* <- Symmetry */
>>> if (k < 0) return 0.;
>>> if (k == 0) return 1.;
>>> /* else: k >= 1 */
>>> if n is a near-integer, then k can become non-integer and negative. In your case,
>>> n == 4 - 1e-7
>&g...
2008 Mar 19
1
choose incorrect for fractional and some negative integer values (PR#10766)
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
2009 Dec 15
3
RFC: lchoose() vs lfactorial() etc
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