| Title: | Robust Tree-Based Boosting for Functional Regression |
|---|---|
| Description: | Implements a family of robust tree-based boosting methods for functional regression, including procedures based on least absolute deviation, M-estimation, and MM-estimation. The package also includes a non-robust tree-based boosting method introduced in Ju X and Salibian-Barrera M. (2024) <doi:10.1007/s00180-023-01364-2>. Functions are provided for model fitting and prediction in regression settings with functional predictors. |
| Authors: | Xiaomeng Ju [aut, cre], Matias Salibian-Barrera [aut] |
| Maintainer: | Xiaomeng Ju <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-10-16 17:40:19 UTC |
| Source: | https://github.com/cran/RTFBoost |
This data set consist of the eggs laid from 667 female fruit flies. This is a subset of the original dataset collected in Dr. Carey's laboratory at University of California, Davis. A description of the experiment can be found in Carey et al.(1998). We processed the original data set avaiable at https://anson.ucdavis.edu/~mueller/data/medfly1000.html to include the ones that lived past 30 days. The objective is to explore the relationship of egg laying pattern and longevity of fruit flies.
fruitflyfruitfly
A list with 3 fields:
a matrix of 667 by 30 representing the number of eggs laid at each day.
an integer giving the lifetime (in days).
an integer of the total number of eggs laid past 30 days.
...
Carey, J.R., Liedo, P., Müller, H.G., Wang, J.L., Chiou, J.M. (1998). Relationship of age patterns of fecundity to mortality, longevity, and lifetime reproduction in a large cohort of Mediterranean fruit fly females. J. of Gerontology –Biological Sciences 53, 245-251.
This data set consist of electricity spot prices traded at the European Energy Exchange (EEX) in Leipzig and electricity demand reported by European Network of Transmission System Operators for Electricity from January 1st 2006 to September 30th 2008, excluding weekends and holidays. It was processed from its original version provided in the on-line supplementary materials of Liebl (2013).
GEDGED
A list with 3 fields:
hourly evaluated electricity spot prices in 638 days, represented as a matrix of dimension 638 by 24.
daily average of electricity demand in 638 days, represented as a vector.
dates represented as a Date object with each day displayed in the form of %d%b%y.
...
Liebl, Dominik. "Modeling and forecasting electricity spot prices: A functional data perspective." The Annals of Applied Statistics 7.3 (2013): 1562-1592.
This function implements tree-based boosting algorithms for functional regression, including TFBoost(LAD), TFBoost(LAD-M), and TFBoost(RR) for robust scalar-on-function regression, and TFBoost(L2) for L2 scalar-on-function regression.
RTFBoost( x.train, z.train = NULL, y.train, x.val, z.val = NULL, y.val, x.test = NULL, z.test = NULL, y.test = NULL, seed = NULL, grid, t.range, control = RTFBoost.control(), ... )RTFBoost( x.train, z.train = NULL, y.train, x.val, z.val = NULL, y.val, x.test = NULL, z.test = NULL, y.test = NULL, seed = NULL, grid, t.range, control = RTFBoost.control(), ... )
x.train |
a matrix or data.frame containing observations of the functional predictor in the training data. |
z.train |
a matrix or data.frame containing values of the scalar predictors in the training data (optional, defaults to |
y.train |
a vector containing values of the scalar response in the training data. |
x.val |
a matrix or data.frame containing observations of the functional predictor in the validation data. |
z.val |
a matrix or data.frame containing values of the scalar predictors in the validation data (optional, required when |
y.val |
a vector containing values of the scalar response in the validation data. |
x.test |
a matrix or data.frame containing observations of the functional predictor in the test data (required when |
z.test |
a matrix or data.frame containing values of the scalar predictors in the test data (required when |
y.test |
a vector containing values of the scalar response in the test data. (optional). |
seed |
a random seed for generating potential parameters for the trees (optional). |
grid |
a vector of time points at which |
t.range |
a vector provided in the form of c(a, b), where a and b are numerical values specifying the boundaries of the domain of the functional predictor. |
control |
a named list of control parameters as returned by RTFBoost.control. |
... |
optional additional arguments passed to
|
This function implements tree-based boosting algorithms for functional regression.
The algorithms use functional multi-index regression trees as the base learners, which are constructed using functions available in the rpart and lme4 packages (see https://arxiv.org/abs/2109.02989).
A list with the following components:
loss.train |
a vector of training errors from all iterations |
loss.val |
a vector of validation errors from all iterations |
f.train |
a vector of predicted values for the training data at the early stopping iteration |
f.val |
a vector of predicted values for the validation data at the early stopping iteration |
f.test |
a vector of predicted values for the test data at the early stopping iteration (returned if |
early.stop.s1 |
the early stopping iteration for the 1st stage of TFBoost(LAD-M) and TFBoost(RR) (returned if |
early.stop |
the early stopping iteration (for TFBoost(LAD-M) and TFBoost(RR), equals to |
err.train |
a vector of mean squared prediction errors for training data from all iterations |
err.val |
a vector of mean squared prediction errors for validation data from all iterations |
err.test |
a vector of mean squared prediction errors for test data before and at the early stopping iteration (returned if |
init.vals |
a constant (if |
tree.objs |
a list of trees objects (returned if |
alpha |
a vector of step sizes (one per iteration) |
save.f.train |
a matrix of predicted values for the training data from all iterations (returned if |
save.f.val |
a matrix of predicted values for the validation data from all iterations (returned if |
save.f.test |
a matrix of predicted values for the test data before and at the early stopping iteration (returned if |
control |
|
Xiaomeng Ju, [email protected]
data(fruitfly) n <- nrow(fruitfly$eggs) n0 <- floor(0.2 * n) set.seed(123) idx_test <- sample(n, n0) idx_train <- sample((1:n)[-idx_test], floor(0.6 * n)) idx_val <- (1:n)[-c(idx_test, idx_train)] xtrain <- fruitfly$eggs[idx_train, ] ytrain <- fruitfly$lifetime[idx_train] xval <- fruitfly$eggs[idx_val, ] yval <- fruitfly$lifetime[idx_val] xtest <- fruitfly$eggs[idx_test, ] ytest <- fruitfly$lifetime[idx_test] gg <- 1:30 tt <- c(0, 30) # For illustrative purposes only; in practice, more iterations (niter), # directions (num.dir) may be required for convergence. niter <- 10 tree.control <- TREE.control(tree.type = "B", max.depth = 1, num.dir = 20) # LAD loss my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "LAD") model_TFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_LAD <- RTFBoost.predict(model_TFBoost, newx = xtest, grid = gg, t.range = tt) # Robust TFBoost my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "RR") model_RTFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_RR <- RTFBoost.predict(model_RTFBoost, newx = xtest, grid = gg, t.range = tt)data(fruitfly) n <- nrow(fruitfly$eggs) n0 <- floor(0.2 * n) set.seed(123) idx_test <- sample(n, n0) idx_train <- sample((1:n)[-idx_test], floor(0.6 * n)) idx_val <- (1:n)[-c(idx_test, idx_train)] xtrain <- fruitfly$eggs[idx_train, ] ytrain <- fruitfly$lifetime[idx_train] xval <- fruitfly$eggs[idx_val, ] yval <- fruitfly$lifetime[idx_val] xtest <- fruitfly$eggs[idx_test, ] ytest <- fruitfly$lifetime[idx_test] gg <- 1:30 tt <- c(0, 30) # For illustrative purposes only; in practice, more iterations (niter), # directions (num.dir) may be required for convergence. niter <- 10 tree.control <- TREE.control(tree.type = "B", max.depth = 1, num.dir = 20) # LAD loss my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "LAD") model_TFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_LAD <- RTFBoost.predict(model_TFBoost, newx = xtest, grid = gg, t.range = tt) # Robust TFBoost my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "RR") model_RTFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_RR <- RTFBoost.predict(model_RTFBoost, newx = xtest, grid = gg, t.range = tt)
Allow users to set the tuning and control parameters for tree-based functional boosting algorithms, including TFBoost(LAD), TFBoost(LAD-M), and TFBoost(RR) for robust scalar-on-function regression, and TFBoost(L2) for L2 scalar-on-function regression.
RTFBoost.control( make.prediction = TRUE, type = "RR", eff = 0.95, bb = 0.5, init.type = "median", init.tree.params = list(tree.type = "A", tree.nindex = 1, max.depth = 1, num.dir = 20, min.leafsize = 10), loss.s2 = "tukey", tree.control = TREE.control(), shrinkage = 0.05, n.init = 100, niter = 100, nknot = 3, precision = 4, save.f = FALSE, trace = FALSE, save.tree = FALSE, error.type = "mse", trim.prop = NULL, trim.c = 3, stage.no = 0 )RTFBoost.control( make.prediction = TRUE, type = "RR", eff = 0.95, bb = 0.5, init.type = "median", init.tree.params = list(tree.type = "A", tree.nindex = 1, max.depth = 1, num.dir = 20, min.leafsize = 10), loss.s2 = "tukey", tree.control = TREE.control(), shrinkage = 0.05, n.init = 100, niter = 100, nknot = 3, precision = 4, save.f = FALSE, trace = FALSE, save.tree = FALSE, error.type = "mse", trim.prop = NULL, trim.c = 3, stage.no = 0 )
make.prediction |
a logical flag: if |
type |
a string that specifies the type of the RTFBoost algorithm. Valid options are "L2", "LAD", "LAD-M", or "RR", corresponding to the algorithms of TFBoost(L2), TFBoost(LAD), TFBoost(LAD-M), and TFBoost(RR) respectively (defaults to "RR"). |
eff |
a numeric value between 0 and 1 indicating the efficiency (measured in a linear model with Gaussian errors) of Tukey’s loss function used in the 2nd stage of TFBoost(LAD-M) and TFBoost(RR) (defaults to 0.95). |
bb |
a numeric value indicating the breakdown point of the M-scale estimator used in the 1st stage of TFBoost(RR) (defaults to 0.5). |
init.type |
a string indicating the initial estimator to be used. Valid options are: "mean", "median" or "LADTree" (defaults to 'median') |
init.tree.params |
a list of parameters for the initial LADtree with components |
loss.s2 |
a string indicating the loss function used in the M-step of TFBoost(LAD-M). Valid potions are "huber" and "tukey" (defaults to "tukey").
|
tree.control |
a list of control parameters for the tree base learner of RTFBoost (defaults to |
shrinkage |
a numeric shrinkage parameter in boosting (defaults to 0.05). |
n.init |
an integer specifying the number of iterations for the 1st stage of TFBoost(RR) (defaults to 100). |
niter |
an integer specifying the number of iterations (for TFBoost(LAD-M) and TFBoost(RR) |
nknot |
an integer denoting the number of interior knots of the cubic B-spline basis (defaults to 3) |
precision |
an integer denoting the number of significant digits to keep when using validation error to calculate early stopping time (defaults to 4) |
save.f |
a logical flag:if |
trace |
a logical flag: if |
save.tree |
a logical flag: if |
error.type |
a character string indicating the type of error metrics to be evaluated on the test set. Valid options are: "mse" (mean squared error), "aad" (average absolute deviation), and "tmse" (trimmed mean squared error) |
trim.prop |
a numeric value used as the trimming proportion if "tmse" is used as the performance metric.
"tmse" calculates the mean-square error of residuals (r) of which |r| < quantile(|r|, 1-trim_prop) (e.g. trim_prop = 0.1 ignores 10% of the data and calculates MSE of residuals whose absolute values are below 90% quantile of |r|). If both |
trim.c |
a numeric value used for trimming if "trmse" is used as the performance metric (defaults to 3). "tmse" calculates the mean squared error of the residuals(r) between median(r) + trim_c mad(r) and median(r) - trim_c mad(r). If both |
stage.no |
a numeric value indicating which stages are executed, required by RTFBoost(LAD-M) and RTFBoost(RR): 0 runs both stages, 1 runs the first stage only, and 2 runs the second stage only (defaults to 0). |
Various tuning and control parameters for tree-based functional boosting algorithms implemented in the function RTFBoost.
A list of all input parameters
Xiaomeng Ju, [email protected]
A function to make predictions and calculate test error given an object returned by TFBoost and test data
RTFBoost.predict(model, newx, newz = NULL, newy = NULL, grid, t.range)RTFBoost.predict(model, newx, newz = NULL, newy = NULL, grid, t.range)
model |
an object returned by |
newx |
a matrix or data.frame containing observations of the functional predictor in the new data |
newz |
a matrix or data.frame containing values of the scalar predictors in the new data (required if |
newy |
a vector containing values of the scalar response in the new data. (optional, defaults to |
grid |
a vector of time points at which |
t.range |
a vector provided in the form of c(a, b), where a and b are numerical values specifying the boundaries of the domain of the functional predictor. |
A function to make predictions and calculate test error given an object returned by TFBoost and test data
A list with with the following components:
f.new |
predicted values with model at the early stopping iteration using x_test (or x_test and z_test) as the predictors |
err.new |
a vector of test errors before and at the early stopping iteration (returned if newy is provided) |
save.f.new |
a matrix of test function estimates at all iterations (returned if save_f = TRUE in control) |
Xiaomeng Ju, [email protected]
data(fruitfly) n <- nrow(fruitfly$eggs) n0 <- floor(0.2 * n) set.seed(123) idx_test <- sample(n, n0) idx_train <- sample((1:n)[-idx_test], floor(0.6 * n)) idx_val <- (1:n)[-c(idx_test, idx_train)] xtrain <- fruitfly$eggs[idx_train, ] ytrain <- fruitfly$lifetime[idx_train] xval <- fruitfly$eggs[idx_val, ] yval <- fruitfly$lifetime[idx_val] xtest <- fruitfly$eggs[idx_test, ] ytest <- fruitfly$lifetime[idx_test] gg <- 1:30 tt <- c(0, 30) # For illustrative purposes only; in practice, more iterations (niter), # directions (num.dir) may be required for convergence. niter <- 10 tree.control <- TREE.control(tree.type = "B", max.depth = 1, num.dir = 20) # LAD loss my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "LAD") model_TFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_LAD <- RTFBoost.predict(model_TFBoost, newx = xtest, grid = gg, t.range = tt) # Robust TFBoost my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "RR") model_RTFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_RR <- RTFBoost.predict(model_RTFBoost, newx = xtest, grid = gg, t.range = tt)data(fruitfly) n <- nrow(fruitfly$eggs) n0 <- floor(0.2 * n) set.seed(123) idx_test <- sample(n, n0) idx_train <- sample((1:n)[-idx_test], floor(0.6 * n)) idx_val <- (1:n)[-c(idx_test, idx_train)] xtrain <- fruitfly$eggs[idx_train, ] ytrain <- fruitfly$lifetime[idx_train] xval <- fruitfly$eggs[idx_val, ] yval <- fruitfly$lifetime[idx_val] xtest <- fruitfly$eggs[idx_test, ] ytest <- fruitfly$lifetime[idx_test] gg <- 1:30 tt <- c(0, 30) # For illustrative purposes only; in practice, more iterations (niter), # directions (num.dir) may be required for convergence. niter <- 10 tree.control <- TREE.control(tree.type = "B", max.depth = 1, num.dir = 20) # LAD loss my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "LAD") model_TFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_LAD <- RTFBoost.predict(model_TFBoost, newx = xtest, grid = gg, t.range = tt) # Robust TFBoost my.control <- RTFBoost.control(make.prediction = TRUE, save.tree = TRUE, tree.control = tree.control, shrinkage = 0.05, nknot = 3, type = "RR") model_RTFBoost <- RTFBoost(x.train = xtrain, y.train = ytrain, x.val = xval, y.val = yval, grid = gg, t.range = tt, niter = niter, control = my.control) predictions_RR <- RTFBoost.predict(model_RTFBoost, newx = xtest, grid = gg, t.range = tt)
A function to fit TFBoost(RR) (see also RTFBoost) where the initialization parameters are chosen
based on the performance on the validation set.
RTFBoost.validation( x.train, z.train = NULL, y.train, x.val, z.val = NULL, y.val, x.test, z.test = NULL, y.test, seed = NULL, grid, t.range, max.depth.init.set = c(1, 2, 3, 4), min.leafsize.init.set = c(10, 20, 30), control = RTFBoost.control(), save.all = TRUE )RTFBoost.validation( x.train, z.train = NULL, y.train, x.val, z.val = NULL, y.val, x.test, z.test = NULL, y.test, seed = NULL, grid, t.range, max.depth.init.set = c(1, 2, 3, 4), min.leafsize.init.set = c(10, 20, 30), control = RTFBoost.control(), save.all = TRUE )
x.train |
a matrix or data.frame containing observations of the functional predictor in the training data. |
z.train |
a matrix or data.frame containing values of the scalar predictors in the training data (optional, defaults to |
y.train |
a vector containing values of the scalar response in the training data. |
x.val |
a matrix or data.frame containing observations of the functional predictor in the validation data. |
z.val |
a matrix or data.frame containing values of the scalar predictors in the validation data (optional, required when |
y.val |
a vector containing values of the scalar response in the validation data. |
x.test |
a matrix or data.frame containing observations of the functional predictor in the test data (required when |
z.test |
a matrix or data.frame containing values of the scalar predictors in the test data (required when |
y.test |
a vector containing values of the scalar response in the test data. (optional). |
seed |
a random seed for generating potential parameters for the trees (optional). |
grid |
a vector of time points at which |
t.range |
a vector provided in the form of c(a, b), where a and b are numerical values specifying the boundaries of the domain of the functional predictor. |
max.depth.init.set |
a vector of possible values of the maximum depth of the initial LADTree that the algorithm choses from (defaults to c(1,2,3,4)). |
min.leafsize.init.set |
a vector of possible values of the minimum observations per node of the initial LADTree that the algorithm choses from (defaults to c(10,20,30)). |
control |
a named list of control parameters as returned by RTFBoost.control. |
save.all |
a logical flag: if |
This function runs the TFBoost(RR) algorithm (see RTFBoost) on different combinations of the
parameters for the initial fit, and chooses the optimal set based on the performance on the validation set.
A list with the following components:
model.best |
an object returned by RTFBoost that is trained with selected initialization parameters |
param |
a vector of selected initialization parameters (return (0,0) if selected initialization is the median of the training responses) |
errs.val |
a vector of robust prediction errors for validation data from all iterations |
errs.test |
a vector of robust prediction errors for test data from all iterations before and at the early stopping iteration (returned if |
pred.list.train |
a list of predicted values for the training data at the early stopping time (returned if |
pred.list.val |
a list of predicted values for the validation data at the early stopping time (returned if |
pred.list.test |
a list of predicted values for the test data at the early stopping time (returned if |
This function implements a algorithm for functional multi-index tree.
TREE(x, y, z, random.seed, control = TREE.control())TREE(x, y, z, random.seed, control = TREE.control())
x |
a matrix or data.frame containing basis projections of the functional predictor in the training data. |
y |
a vector containing values of the scalar response in the training data (optional, defaults to |
z |
a matrix or data.frame containing values of the scalar predictors in the training data (optional, defaults to |
random.seed |
an integer as the seed to generate random directions for the Type B tree. |
control |
a named list of control parameters, as returned by |
This function implements a functional multi-index tree algorithm developed based on functions available in the rpart package.
A list with the following components:
beta.opt |
a matrix of index coefficients estimated by the Type A tree, returned if |
betas.selected |
a matrix of index coefficients selected by the Type B tree, returned if |
pred |
a vector of predicted values for the training data |
tree.model |
an rpart object of the fitted tree |
control |
|
Xiaomeng Ju, [email protected]
Tuning and control parameters for the functional multi-index tree.
TREE.control( tree.type = "A", tree.nindex = 1, max.depth = 1, num.dir = 20, min.leafsize = 2, nmulti = 3, nscreen = 30 )TREE.control( tree.type = "A", tree.nindex = 1, max.depth = 1, num.dir = 20, min.leafsize = 2, nmulti = 3, nscreen = 30 )
tree.type |
a character ("A" or "B") denoting Type A or Type B tree (defaults to "A"). |
tree.nindex |
an integer specifying the number of indices required by a Type A tree (defaults to 1). |
max.depth |
an integer specifying the maximum depth for a Type A or Type B tree (defaults to 1). |
num.dir |
an integer specifying the number of random directions required by the initial Type B tree (defaults to 20). |
min.leafsize |
an integer specifying the minimum number of observations per leaf node for a Type A or Type B tree (defaults to 2). |
nmulti |
an integer specifying the number of random initialization points to fit a Type A tree (defaults to 3). |
nscreen |
an integer specifying the number of random points from which to select the initial points to fit a Type A tree (defaults to 30). |
Various tuning and control parameters for the functional multi-index tree algorithm implemented in the
function TREE
A list of all input parameters
Xiaomeng Ju, [email protected]
A function to make predictions given an object returned by TREE and test data
TREE.predict(model, newx, newz)TREE.predict(model, newx, newz)
model |
an object returned by |
newx |
a matrix or data.frame containing basis projections of the functional predictor in the new data. |
newz |
a matrix or data.frame containing values of the scalar predictors in the new data (optional, defaults to |
A function to make predictions given an object returned by TREE and test data
pred |
a vector of predicted values using |
Xiaomeng Ju, [email protected]