Get Started with RLT
Ruoqing Zhu
Last Updated: October 27, 2026
Source:vignettes/articles/get-started.Rmd
get-started.RmdInstall the RLT Package
These guides describe RLT source version 6.1.1. The CRAN release is a separate, older version whose interfaces and features may differ. Installing from GitHub requires a C++ toolchain compatible with your R installation. Set it up using the platform requirements below, then install the source into your normal shared R library:
# install.packages("remotes")
remotes::install_github("teazrq/RLT")
packageVersion("RLT")These examples target version 6.1.1. GitHub installation uses the
repository’s current default branch, which can change.
packageVersion() checks the version number; different
source revisions can share that number. See matching the documentation
revision for an exact source match, or the
CRAN release for the separate CRAN installation route.
Fit and evaluate a regression forest
We will predict a continuous response from six numeric predictors. The response depends on the first two predictors plus independent noise. We reserve 40 observations for evaluation and fit the model on the other 160.
library(RLT)
set.seed(1)
x <- matrix(rnorm(200 * 6), nrow = 200, ncol = 6)
y <- x[, 1] - x[, 2] + rnorm(200)
trainX <- x[1:160, ]
trainY <- y[1:160]
testX <- x[161:200, ]
testY <- y[161:200]The default forest uses one variable at each split. Here
mtry = 3 samples three candidate variables at a node, and
nsplit = 0 searches all available cutpoints for those
candidates. We use 100 trees for this short example and set
seed to control fitting randomness.
fit <- RLT(
trainX, trainY, model = "regression",
ntrees = 100, mtry = 3, nsplit = 0,
resample.replace = TRUE, resample.prob = 0.80,
seed = 1, ncores = 1, verbose = FALSE
)Each tree makes 128 draws, with replacement, from the training set.
An observation’s out-of-bag (OOB) prediction uses only trees whose
resample omitted that observation. The fitted object’s
Prediction component contains these OOB predictions. For
held-out observations, predict() averages predictions from
the fitted trees.
pred <- predict(fit, testX)
list(
OOB_MSE = mean((fit$Prediction - trainY)^2),
Test_MSE = mean((pred$Prediction - testY)^2)
)
## $OOB_MSE
## [1] 1.374119
##
## $Test_MSE
## [1] 1.186798
head(data.frame(Observed = testY, Predicted = pred$Prediction))
## Observed Predicted
## 1 2.0239825 2.0611649
## 2 -2.8588177 -0.6790041
## 3 0.2598043 1.5173868
## 4 0.4535536 0.8997102
## 5 1.2538745 -0.1908594
## 6 0.9382517 0.7102354Both results are mean squared errors (MSEs), so smaller values indicate more accurate predictions. OOB MSE evaluates predictions within the training sample using omitted observations; test MSE evaluates the 40 observations reserved before fitting. These are two estimates of prediction error for this example, and they can differ in a small sample.
Try reinforcement or linear combination splits
Setting reinforcement = TRUE fits embedded models within
nodes to guide single-variable splits. The following fit uses the same
training data and outer forest settings as the first fit. We set
ntrees = 100 explicitly in both calls because its default
is 500 without reinforcement and 100 with reinforcement.
reinforced_fit <- RLT(
trainX, trainY, model = "regression",
reinforcement = TRUE,
ntrees = 100, mtry = 3, nsplit = 0,
resample.replace = TRUE, resample.prob = 0.80,
seed = 1, ncores = 1, verbose = FALSE
)
reinforced_pred <- predict(reinforced_fit, testX)
head(reinforced_pred$Prediction)
## [,1]
## [1,] 2.3363702
## [2,] -0.6634972
## [3,] 1.7565052
## [4,] 0.8463552
## [5,] -0.1653644
## [6,] 0.6967331This shows how to request reinforcement. It does not establish an
accuracy advantage for either fit. Linear combination splits make a
different choice: they split along a combined predictor direction, with
linear.comb setting the maximum number of variables in that
direction. They do not require reinforcement = TRUE. See
the linear combination guide for
a worked example.
Next steps
The Regression and Classification tutorials show numeric and factor predictors, OOB evaluation, and held-out predictions. The Survival tutorial covers censored event times. To repeat an analysis, see Random Seed and Reproducibility.
Match the Documentation Revision
For reproducible use, check out the same repository revision used to
build the documentation and install that checkout. Replace
DOCUMENTATION_REVISION below with the revision linked as
Source revision in the published site’s footer. Use
your normal shared R library.
CRAN Release
Install the separate CRAN release with:
install.packages("RLT")CRAN may offer a binary package for your platform, which avoids local compilation. Installing from GitHub requires source compilation and the tools described below.
Platform Requirements
For Windows Users
Source installation on Windows requires Rtools. Install the matching version from the Rtools page, then install RLT from GitHub.
For macOS Users
Use Apple’s Xcode Command Line Tools for C++ compilation. Follow the R macOS tools instructions, and consult the download page for your R version and architecture to identify its compiler requirements. Any GNU Fortran compiler and runtime libraries used for package compilation must match those used to build your R. The gfortran 12.2 installer applies to CRAN R 4.3.0 through 4.4.3; it is not a general choice for newer R versions.
For Linux Users
Install your distribution’s R development tools and a compatible C++ compiler, including the development libraries required by your R installation for BLAS/LAPACK and Fortran linking. See R’s package installation instructions.
Optional OpenMP Parallel Support
OpenMP enables RLT to use multiple CPU cores. A build without OpenMP
runs serially; increasing ncores cannot enable parallelism
in that build.
On macOS, follow the R macOS OpenMP guide and choose the runtime from its Xcode/Apple clang compatibility table. For example, that table pairs Xcode 14.0 through 14.2 with OpenMP 14.0.6, whereas Xcode 16.3 through 26.3 uses OpenMP 19.1.5. Apple clang 1700 and later cannot use the older runtimes listed there. Check the current table for your installed compiler before configuring OpenMP, then reinstall RLT from source.
Changes to ~/.R/Makevars affect source builds of other R
packages too. Review any compiler paths or OpenMP flags there whenever
R, macOS, or Xcode changes; avoid copying flags intended for a different
toolchain.
The current validation covers Windows builds with and without OpenMP. Source installation on Ubuntu Linux is checked by the documentation workflow. macOS source installation has not been verified.