2
votes

I am using the randomForest package in R to model imbalanced data. The outcome is a binary variable with the outcome (no, yes) having relative frequencies of (2249(88%), 318 (12%) ).

Due to the imbalance, RF initially predicted no with an OOB error rate of 0% and yes with an OOB error rate of 100%. I changed the sampling design in RF by forcing use of all 318 yes outcomes and 318 no outcomes randomly sampled from a possible 2249 with the following code. The OOB error rates changed to a reasonable 44% for no and 12% for yes.

rf1 <- randomForest(binary.outcome ~ ., data = data, 
                   strata = data$binary.outcome,
                   sampsize = c(318,318), replace = TRUE, importance = TRUE,
                   proximity = TRUE, mtry = 8, ntree = 2000)

Does anyone know how to repeat this sampling design but in randomForestSRC?

I am having trouble working it out from the CRAN pdf specifications

rfsrc.1 <- rfsrc(binary.outcome ~ ., data = data, 
                bootstrap = "by.user", samptype = "swor",
                samp = c(318,318), replace = TRUE, importance = "permute",
                proximity = TRUE, mtry = 8, ntree = 2000)

I get the error message " in apply(samp,2, sum): dim(x) must have positive length"

I can't work out how to manipulate samp and bootstrap to get what I want.

Thank you,

Don

1

1 Answers

2
votes

Our documentation could perhaps be clearer. You should use the case.wt option in the rfsrc() call. Leave bootstrap, samptype and samp at their default values. case.wt must be a vector of dimension n, where n equals the number of cases in the processed data set. In your situation n= 2567 assuming no missing data. Every minority class case should have a weight of 1/318, and every majority class case should have a weight of 1/2249. The vector will be normalized internally, and every bootstrap will have equal amounts of each class, if this is the intention.

Note that we are working on a new performance measure called the g-mean that is relevant to the minority two-class problem. It will be released in an upcoming beta build on

https://github.com/kogalur/randomForestSRC

In addition, we will be implementing thresholding, an option that allows the minority class to win if the proportion of that class in a node is greater than its overall proportion in the data set, rather than the default threshold of 50% that currently determines a win. We will be happy to notify you of this functionality when it becomes available, as it may be relevant to your situation.