Optimising Random Forest Stability by Determining the Optimal Number of Trees

Calculating the stability of random forest with certain numbers of trees. The non-linear relationship between stability and numbers of trees is described using a logistic regression model and used to estimate the optimal number of trees.


optRF: Optimising random forest stability by determining the optimal number of trees

CRAN status CRAN Downloads month CRAN Downloads overall

The optRF package provides tools for optimizing the number of trees in a random forest to improve model stability and reproducibility. Since random forest is a non-deterministic method, variable importance and prediction results can vary between runs. The optRF package estimates the stability of random forest based on the number of trees and helps users determine the optimal number of trees required for reliable predictions and variable selection.

Installation

To install the optRF R package from CRAN, just run

install.packages("optRF")

R version >= 3.6 is required.
You can install the development version of optRF from GitHub using devtools with:

devtools::install_github("tmlange/optRF")

Usage

The optRF package includes the SNPdata data set for demonstration purposes. The two main functions are:

  • opt_prediction – Finds the optimal number of trees for stable predictions.
  • opt_importance – Finds the optimal number of trees for stable variable importance estimates.
library(optRF)

# Load example data set
data(SNPdata)

# Optimise random forest for predicting the first column in SNPdata
result_optpred = opt_prediction(y = SNPdata[,1], X=SNPdata[,-1])
summary(result_optpred)

# Optimise random forest for calculating variable importance
result_optimp = opt_importance(y = SNPdata[,1], X=SNPdata[,-1]) 
summary(result_optimp)

For detailed examples and explanations, refer to the package vignettes:

  • optRF – General package overview
  • opt_prediction – Optimizing random forest predictions
  • opt_importance – Optimizing random forest variable importance estimation

Citing optRF

If you use optRF in your research, please cite:
Lange, T.M., Gültas, M., Schmitt, A.O. & Heinrich, F. optRF: Optimising random forest stability by determining the optimal number of trees. BMC Bioinformatics 26, 95 (2025).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("optRF")

1.2.1 by Thomas Martin Lange, a year ago


https://github.com/tmlange/optRF


Report a bug at https://github.com/tmlange/optRF/issues


Browse source code at https://github.com/cran/optRF


Authors: Thomas Martin Lange [cre, aut] (ORCID: , Felix Heinrich [ctb]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports minpack.lm, ranger, irr, graphics, methods, stats

Suggests covr, knitr, rmarkdown, spelling, testthat


See at CRAN