TRexSelector R package guide

Getting started with TRexSelector

What the package does

The Terminating-Random Experiments (T-Rex) selector selects variables while controlling the false discovery rate (FDR) at a target level chosen by the user, and it does so with a high true positive rate (TPR) [1]. It applies to low- and high-dimensional designs and is tailored to the high-dimensional problem. It takes a design matrix \(\boldsymbol{X}\) with \(n\) observations of \(p\) variables, a response vector \(\boldsymbol{y}\) and the target FDR, and runs \(K\) random experiments in which the real variables compete with computer-generated dummy variables, random columns with finite mean and variance that act as flagged null variables. In every experiment the dummies are appended to the design, a forward selection solver walks its path and stops as soon as \(T\) dummies have entered, and the share of experiments in which a variable was selected is its vote. Because a dummy enters as easily as a null variable, the included dummies give an estimate of the false discoveries, and a calibration over the number of dummies, the stopping time and the voting level selects as many variables as the FDR target allows, with a finite-sample guarantee that holds for a broad class of forward selection solvers. The scheme is not tied to the linear model and scales to millions of variables. The library currently covers the supervised linear model with a response vector and a design matrix.

The R package is the R interface to the TRexSelector C++ library. The same library drives the Python package and the C++ software development kit, so the three surfaces select the same variables on the same data. Since version 2.0.0 it replaces the pure-R implementation of the 1.x releases under the same package name [version 1.0.0].

The package currently has five groups of tools.

Installation

The released package is on the Comprehensive R Archive Network (CRAN) [package page]. Install it from an R session.

install.packages("TRexSelector")

CRAN provides binaries for Windows and macOS. On Linux, and for every install from source, the package compiles its C++ backend, so a C++20 compiler is required (GCC 10, Clang 12, Apple Clang 14, Rtools on Windows, or newer) together with R (>= 4.3).

The main branch of the repository carries the released sources, the version that is on CRAN, in the R/TRexSelector/ subdirectory, and the development happens on the dev_beyond branch. Install the R-side prerequisites once, then the package from GitHub.

install.packages(c("Rcpp", "RcppEigen", "BH", "Rcereal", "R6", "remotes"))
remotes::install_github("trexselector/TRexSelector", subdir = "R/TRexSelector")

OpenMP is optional. The CRAN binary for Windows is built with it, and on Linux the package compiles with the OpenMP flags of R. CRAN’s R for macOS has none, so the macOS binary runs on one thread, while a build from source (install.packages("TRexSelector", type = "source")) uses the omp.h header of Homebrew’s libomp (brew install libomp) together with the OpenMP runtime that R itself ships. Without a header the package compiles single-threaded and trex_get_max_threads() returns 1. The parallelism page explains what the threads are used for.

The package builds on Rcpp [2] and RcppEigen [3] for the bindings, on the Boost headers of BH [4] for the memory mapping, on the cereal headers of Rcereal [5] for the serialization, and on R6 [6] for its classes.

A first run

The package ships a small Gaussian data set with \(n = 50\) observations, \(p = 100\) variables and three active variables.

data(Gauss_data)
X <- Gauss_data$X
y <- Gauss_data$y
true_support <- which(Gauss_data$support)
true_support
#> [1] 1 2 3

The selectors are R6 classes. Construct one with $new(), run it with $select() and read the results from its fields. A fixed seed makes the dummy draws reproducible. The default seed = -1 draws them from the hardware entropy source, which is the right choice for Monte Carlo studies, see the T-Rex selector page.

sel <- TRexSelector$new(X, y, tFDR = 0.1, seed = 1234, verbose = FALSE)
sel$select()
sel$selected_indices
#> [1] 1 2 3

The two metrics of variable selection compare the selection with the true support. The false discovery proportion (FDP) is the share of false positives among the selected variables and the true positive proportion (TPP) is the share of the true support that was found. Their expectations are the FDR and the TPR.

trex_fdp(sel$selected_indices, true_support)
#> [1] 0
trex_tpp(sel$selected_indices, true_support)
#> [1] 1

The result fields

Every selector exposes the calibration it arrived at.

sel$num_selected   # number of selected variables
#> [1] 3
sel$T_stop         # stopping time: dummies included when the T-loop stopped
#> [1] 6
sel$L              # calibrated dummy multiplier, the selector used L * p dummies
#> [1] 4
sel$v_thresh       # voting level the selection was read at
#> [1] 1
sel$K              # random experiments
#> [1] 20

fdp_hat_mat holds the FDP estimate per stopping time (rows) and voting level (columns), phi_mat the relative occurrence of every variable over the \(K\) experiments after each stopping time, and voting_grid the voting levels. The T-Rex selector page walks through them.

dim(sel$fdp_hat_mat)
#> [1]  6 11
head(sel$voting_grid)
#> [1] 0.50 0.55 0.60 0.65 0.70 0.75
round(sel$fdp_hat_mat[sel$T_stop, ], 3)
#>  [1] 0.38 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20

T-Rex variants of the library

Situation Selector Page
Independent or modestly dependent variables TRexSelector T-Rex selector
Strongly dependent variables (autoregressive, equi-correlated, clustered) TRexDASelector T-Rex+DA
Groups of correlated variables that should enter together TRexGVSSelector T-Rex GVS
Very large \(p\), a fast first pass before the full selector TRexScreeningSelector Screen-T-Rex
Many phenotypes against one genotype matrix TRexBiobankScreeningSelector Screen-T-Rex
Sparse principal components TRexSPCASelector T-Rex SPCA
A structured penalty (smoothness, graph Laplacian, groups) TRexTikhonovSelector T-Rex Tikhonov

The solver inside the random experiments is set in trex_control(solver = ). T-LARS (terminating least angle regression) is the default and the solver of the T-Rex paper. T-LASSO adds the lasso modification, T-ENET the elastic net, the orthogonal matching pursuit (OMP) family and the adaptive forward stepwise family are greedy and faster per step, and the coordinate descent (CD) family computes exact penalized minimizers at every dummy crossing. The T-solvers page describes the families, and every solver can be run on its own.

ctrl <- trex_control(solver = "TLASSO", K = 10)
sel2 <- TRexSelector$new(X, y, tFDR = 0.1, seed = 1234, verbose = FALSE, control = ctrl)
sel2$select()
sel2$selected_indices
#> [1] 1 2 3

Citing the package

citation("TRexSelector")

The methods are published in [1] (T-Rex), [7] (T-Rex+DA), [8], [9] (T-Rex GVS), [10] (Screen-T-Rex), [11] (T-Rex SPCA), [12] (memory mapping) and [13] (the terminating greedy pursuits).

Bibliography

[1]
J. Machkour, M. Muma, and D. P. Palomar, “The terminating-random experiments selector: Fast high-dimensional variable selection with false discovery rate control,” Signal Process., vol. 231, 2025, doi: 10.1016/j.sigpro.2025.109894.
[2]
D. Eddelbuettel and R. François, “Rcpp: Seamless R and C++ integration,” J. Stat. Softw., vol. 40, no. 8, pp. 1–18, 2011, doi: 10.18637/jss.v040.i08.
[3]
D. Bates and D. Eddelbuettel, “Fast and elegant numerical linear algebra using the RcppEigen package,” J. Stat. Softw., vol. 52, no. 5, pp. 1–24, 2013, doi: 10.18637/jss.v052.i05.
[4]
D. Eddelbuettel, J. W. Emerson, and M. J. Kane, BH: Boost C++ header files. 2025. doi: 10.32614/CRAN.package.BH.
[5]
W. Wu, Rcereal: Cereal headers for R and C++ serialization. 2024. doi: 10.32614/CRAN.package.Rcereal.
[6]
W. Chang, R6: Encapsulated classes with reference semantics. 2025. doi: 10.32614/CRAN.package.R6.
[7]
J. Machkour, M. Muma, and D. P. Palomar, “High-dimensional false discovery rate control for dependent variables,” Signal Process., vol. 234, 2025, doi: 10.1016/j.sigpro.2025.109990.
[8]
J. Machkour, M. Muma, and D. P. Palomar, “False discovery rate control for grouped variable selection in high-dimensional linear models using the T-Knock filter,” in Proc. 30th eur. Signal process. Conf. (EUSIPCO), 2022, pp. 892–896. doi: 10.23919/EUSIPCO55093.2022.9909883.
[9]
J. Machkour, M. Muma, and D. P. Palomar, “The informed elastic net for fast grouped variable selection and FDR control in genomics research,” in Proc. IEEE 9th int. Workshop comput. Adv. Multi-sensor adapt. Process. (CAMSAP), 2023, pp. 466–470. doi: 10.1109/CAMSAP58249.2023.10403489.
[10]
J. Machkour, M. Muma, and D. P. Palomar, “False discovery rate control for fast screening of large-scale genomics biobanks,” in Proc. 22nd IEEE statist. Signal process. Workshop (SSP), 2023, pp. 666–670. doi: 10.1109/SSP53291.2023.10207957.
[11]
J. Machkour, A. Breloy, M. Muma, D. P. Palomar, and F. Pascal, “Sparse PCA with false discovery rate controlled variable selection,” in Proc. IEEE 49th int. Conf. Acoust., speech, signal process. (ICASSP), 2024, pp. 9716–9720. doi: 10.1109/ICASSP48485.2024.10448237.
[12]
F. Scheidt, J. Machkour, and M. Muma, “Solving FDR-controlled sparse regression problems with five million variables on a laptop,” in Proc. IEEE 9th int. Workshop comput. Adv. Multi-sensor adapt. Process. (CAMSAP), 2023, pp. 116–120. doi: 10.1109/CAMSAP58249.2023.10403478.
[13]
F. Scheidt and M. Muma, “Terminating greedy pursuits for high-dimensional false discovery rate control,” in Proc. Eur. Signal process. Conf. (EUSIPCO), 2026, pp. 2511–2515.