[R] OSX-specific Bug in randomForest
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Wed Oct 23 12:28:45 CEST 2024
>>>>> Duncan Murdoch
>>>>> on Wed, 23 Oct 2024 05:33:57 -0400 writes:
> I've cc'd this to the package maintainer, Andy Liaw
> <andy_liaw using merck.com>. I'm not sure he reads this list.
> Duncan Murdoch
Also, note that you should check for absolute difference, i.e.,
if (abs(sum(cutoff) - 1) > .Machine$double.eps || ...
and I'd really recommend
if (isTRUE(all.equal(1, sum(cutoff))) || ....
Martin Maechler
> On 2024-10-23 1:26 a.m., Stevie Pederson wrote:
>> Hi,
>>
>> It appears there is an OSX-specific bug in the function
>> `randomForest.default()` Going by the source code at
>> https://github.com/cran/randomForest/blob/master/R/randomForest.default.R
>> the bug is on line 103
>>
>> If the vector `cutoff` is formed using `cutoff <-
>> rep(1/9, 9)` (line #101) the test on line 103 will fail
>> on OSX as the sum is greater than 1 due to machine
>> precision errors.
>>
>> sum(rep(1 / 9, 9)) - 1 # [1] 2.220446e-16
>>
>> This will actually occur for a scenario when the number
>> of factor levels (nclass) is 9, 11, 18, 20 etc.The
>> problem does not occur on Linux, and I haven't tested on
>> WIndows.
>>
>> A suggestion may be to change the opening test
>>
>> if (sum(cutoff) > 1 || ...)
>>
>> to
>>
>> if (sum(cutoff) - 1 > .Machine$double.eps || ...
>>
>> however, I'm sure there's a more elegant way to do this
>>
>> Thanks in advance
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and
>> more, see https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> https://www.R-project.org/posting-guide.html and provide
>> commented, minimal, self-contained, reproducible code.
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and
> more, see https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html and provide
> commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list