[R] OSX-specific Bug in randomForest
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Wed Oct 23 11:33:57 CEST 2024
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
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.
More information about the R-help
mailing list