tuneRF.RdStarting with the default value of mtry, search for the optimal value (with respect to Out-of-Bag error estimate) of mtry for randomForest.
tuneRF(x, y, mtryStart, ntreeTry=50, stepFactor=2, improve=0.05,
trace=TRUE, plot=TRUE, doBest=FALSE, ...)matrix or data frame of predictor variables
response vector (factor for classification, numeric for regression)
starting value of mtry; default is the same as in
randomForest
number of trees used at the tuning step
at each iteration, mtry is inflated (or deflated) by this value
the (relative) improvement in OOB error must be by this much for the search to continue
whether to print the progress of the search
whether to plot the OOB error as function of mtry
whether to run a forest using the optimal mtry found
options to be given to randomForest
If doBest=FALSE (default), it returns a matrix whose first
column contains the mtry values searched, and the second column the
corresponding OOB error.
If doBest=TRUE, it returns the randomForest
object produced with the optimal mtry.
data(fgl, package="MASS")
fgl.res <- tuneRF(fgl[,-10], fgl[,10], stepFactor=1.5)
#> mtry = 3 OOB error = 22.43%
#> Searching left ...
#> mtry = 2 OOB error = 22.9%
#> -0.02083333 0.05
#> Searching right ...
#> mtry = 4 OOB error = 23.36%
#> -0.04166667 0.05