[R] OSX-specific Bug in randomForest

Stevie Pederson @tephen@peder@on@@u @end|ng |rom gm@||@com
Wed Oct 23 07:26:00 CEST 2024


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]]



More information about the R-help mailing list