Skip to contents

Bayesian additive regression trees (BART) sampled with MCMC, optionally warm-started with the grow-from-root algorithm of accelerated BART (XBART). Calls stochtree::bart() from stochtree.

The "se" predict type returns the posterior standard deviation of the conditional mean. Leaf regression bases and random effects are not supported.

Custom mlr3 parameters

  • stochtree::bart() takes most of its parameters in the lists general_params, mean_forest_params, and variance_forest_params. The entries of these lists are exposed as individual hyperparameters. The entries of general_params and mean_forest_params keep their names. The entries of variance_forest_params whose names clash with those of the mean forest are prefixed with variance_, i.e., variance_num_trees, variance_alpha, variance_beta, variance_min_samples_leaf, variance_max_depth, variance_keep_vars, variance_drop_vars, and variance_num_features_subsample.

  • random_seed: If not set, the seed of the C++ random number generator is drawn from R's random number generator, so that results are reproducible with set.seed(). Upstream seeds from std::random_device in this case.

  • observation_weights is not exposed as a hyperparameter. Observation weights are taken from the task instead, see the weights property.

Saving a Learner

The fitted model holds pointers to C++ objects. In order to save a trained learner, or to use it with encapsulation or parallelization, the model is marshaled to a JSON string with stochtree::saveBARTModelToJsonString(). Call $marshal() before saving the learner with saveRDS() and $unmarshal() after reading it.

Dictionary

This Learner can be instantiated via lrn():

lrn("regr.stochtree")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”, “se”

  • Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”

  • Required Packages: mlr3, mlr3extralearners, stochtree

Parameters

IdTypeDefaultLevelsRange
num_gfrinteger5\([0, \infty)\)
num_burnininteger0\([0, \infty)\)
num_mcmcinteger100\([0, \infty)\)
cutpoint_grid_sizeinteger100\([1, \infty)\)
standardizelogicalTRUETRUE, FALSE-
sample_sigma2_globallogicalTRUETRUE, FALSE-
sigma2_global_initnumeric-\([0, \infty)\)
sigma2_global_shapenumeric0\([0, \infty)\)
sigma2_global_scalenumeric0\([0, \infty)\)
variable_weightsuntypedNULL-
random_seedinteger-\([0, \infty)\)
keep_burninlogicalFALSETRUE, FALSE-
keep_gfrlogicalFALSETRUE, FALSE-
keep_everyinteger1\([1, \infty)\)
num_chainsinteger1\([1, \infty)\)
verboselogicalFALSETRUE, FALSE-
num_threadsinteger1\([1, \infty)\)
num_treesinteger200\([0, \infty)\)
alphanumeric0.95\([0, 1]\)
betanumeric2\([0, \infty)\)
min_samples_leafinteger5\([1, \infty)\)
max_depthinteger10\([-1, \infty)\)
sample_sigma2_leaflogicalTRUETRUE, FALSE-
sigma2_leaf_initnumeric-\([0, \infty)\)
sigma2_leaf_shapenumeric3\([0, \infty)\)
sigma2_leaf_scalenumeric-\([0, \infty)\)
keep_varsuntypedNULL-
drop_varsuntypedNULL-
num_features_subsampleinteger-\([1, \infty)\)
variance_num_treesinteger0\([0, \infty)\)
variance_alphanumeric0.95\([0, 1]\)
variance_betanumeric2\([0, \infty)\)
variance_min_samples_leafinteger5\([1, \infty)\)
variance_max_depthinteger10\([-1, \infty)\)
leaf_prior_calibration_paramnumeric1.5\([0, \infty)\)
var_forest_leaf_initnumeric-\((-\infty, \infty)\)
var_forest_prior_shapenumeric-\([0, \infty)\)
var_forest_prior_scalenumeric-\([0, \infty)\)
variance_keep_varsuntypedNULL-
variance_drop_varsuntypedNULL-
variance_num_features_subsampleinteger-\([1, \infty)\)

References

Chipman, A H, George, I E, McCulloch, E R (2010). “BART: Bayesian additive regression trees.” The Annals of Applied Statistics, 4(1), 266–298.

He, Jingyu, Hahn, Richard P (2023). “Stochastic Tree Ensembles for Regularized Nonlinear Regression.” Journal of the American Statistical Association, 118(541), 551–570. doi:10.1080/01621459.2021.1942012 .

Herren, Drew, Hahn, Richard, Murray, Jared, Carvalho, Carlos, He, Jingyu (2026). stochtree: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference. doi:10.32614/CRAN.package.stochtree . R package version 0.4.5.

See also

Author

be-marc

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrStochtree

Active bindings

marshaled

(logical(1))
Whether the learner has been marshaled.

Methods

Inherited methods


LearnerRegrStochtree$new()

Creates a new instance of this R6 class.

Usage


LearnerRegrStochtree$marshal()

Marshal the learner's model.

Usage

LearnerRegrStochtree$marshal(...)

Arguments

...

(any)
Additional arguments passed to mlr3::marshal_model().


LearnerRegrStochtree$unmarshal()

Unmarshal the learner's model.

Usage

LearnerRegrStochtree$unmarshal(...)

Arguments

...

(any)
Additional arguments passed to mlr3::unmarshal_model().


LearnerRegrStochtree$clone()

The objects of this class are cloneable with this method.

Usage

LearnerRegrStochtree$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Define the Learner
learner = lrn("regr.stochtree")
print(learner)
#> 
#> ── <LearnerRegrStochtree> (regr.stochtree): Stochastic Tree Ensemble BART ──────
#> • Model: -
#> • Parameters: list()
#> • Packages: mlr3, mlr3extralearners, and stochtree
#> • Predict Types: [response] and se
#> • Feature Types: logical, integer, numeric, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: marshal and weights
#> • Other settings: use_weights = 'use', predict_raw = 'FALSE'

# Define a Task
task = tsk("mtcars")

# Create train and test set
ids = partition(task)

# Train the learner on the training ids
learner$train(task, row_ids = ids$train)

print(learner$model)
#> stochtree::bart() run with mean forest, global error variance model, and mean forest leaf scale model
#> Continuous outcome was modeled as Gaussian with a constant leaf prior for the mean forest
#> Outcome was standardized
#> The sampler was run for 5 GFR iterations, with 1 chain of 0 burn-in iterations and 100 MCMC iterations, retaining every iteration (i.e. no thinning) 


# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)

# Score the predictions
predictions$score()
#> regr.mse 
#> 10.15014