Package: stochtree 0.1.1

Drew Herren

stochtree: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference

Flexible stochastic tree ensemble software. Robust implementations of Bayesian Additive Regression Trees (BART) Chipman, George, McCulloch (2010) <doi:10.1214/09-AOAS285> for supervised learning and Bayesian Causal Forests (BCF) Hahn, Murray, Carvalho (2020) <doi:10.1214/19-BA1195> for causal inference. Enables model serialization and parallel sampling and provides a low-level interface for custom stochastic forest samplers.

Authors:Drew Herren [aut, cre], Richard Hahn [aut], Jared Murray [aut], Carlos Carvalho [aut], Jingyu He [aut], Pedro Lima [ctb], stochtree contributors [cph], Eigen contributors [cph], xgboost contributors [cph], treelite contributors [cph], Microsoft Corporation [cph], Niels Lohmann [cph], Daniel Lemire [cph], Victor Zverovich [cph]

stochtree_0.1.1.tar.gz
stochtree_0.1.1.zip(r-4.5)stochtree_0.1.1.zip(r-4.4)stochtree_0.1.1.zip(r-4.3)
stochtree_0.1.1.tgz(r-4.5-x86_64)stochtree_0.1.1.tgz(r-4.5-arm64)stochtree_0.1.1.tgz(r-4.4-x86_64)stochtree_0.1.1.tgz(r-4.4-arm64)stochtree_0.1.1.tgz(r-4.3-x86_64)stochtree_0.1.1.tgz(r-4.3-arm64)
stochtree_0.1.1.tar.gz(r-4.5-noble)stochtree_0.1.1.tar.gz(r-4.4-noble)
stochtree_0.1.1.tgz(r-4.4-emscripten)stochtree_0.1.1.tgz(r-4.3-emscripten)
stochtree.pdf |stochtree.html
stochtree/json (API)
NEWS

# Install 'stochtree' in R:
install.packages('stochtree', repos = c('https://stochastictree.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/stochastictree/stochtree/issues

Uses libs:
  • c++– GNU Standard C++ Library v3

On CRAN:

bartbayesian-machine-learningbayesian-methodsdecision-treesgradient-boosted-treesmachine-learningprobabilistic-modelstree-ensemblescpp

8.31 score 19 stars 40 scripts 132 downloads 60 exports 3 dependencies

Last updated 7 days agofrom:59d7786dce. Checks:1 OK, 10 WARNING. Indexed: yes.

TargetResultLatest binary
Doc / VignettesOKFeb 13 2025
R-4.5-win-x86_64WARNINGFeb 13 2025
R-4.5-mac-x86_64WARNINGFeb 13 2025
R-4.5-mac-aarch64WARNINGFeb 13 2025
R-4.5-linux-x86_64WARNINGFeb 13 2025
R-4.4-win-x86_64WARNINGFeb 13 2025
R-4.4-mac-x86_64WARNINGFeb 13 2025
R-4.4-mac-aarch64WARNINGFeb 13 2025
R-4.3-win-x86_64WARNINGFeb 13 2025
R-4.3-mac-x86_64WARNINGFeb 13 2025
R-4.3-mac-aarch64WARNINGFeb 13 2025

Exports:bartbcfcalibrateInverseGammaErrorVariancecomputeForestLeafIndicescomputeForestLeafVariancescomputeForestMaxLeafIndexconvertPreprocessorToJsoncreateBARTModelFromCombinedJsoncreateBARTModelFromCombinedJsonStringcreateBARTModelFromJsoncreateBARTModelFromJsonFilecreateBARTModelFromJsonStringcreateBCFModelFromCombinedJsoncreateBCFModelFromCombinedJsonStringcreateBCFModelFromJsoncreateBCFModelFromJsonFilecreateBCFModelFromJsonStringcreateCppJsoncreateCppJsonFilecreateCppJsonStringcreateCppRNGcreateForestcreateForestDatasetcreateForestModelcreateForestModelConfigcreateForestSamplescreateGlobalModelConfigcreateOutcomecreatePreprocessorFromJsoncreatePreprocessorFromJsonStringcreateRandomEffectSamplescreateRandomEffectsDatasetcreateRandomEffectsModelcreateRandomEffectsTrackergetRandomEffectSamplesloadForestContainerCombinedJsonloadForestContainerCombinedJsonStringloadForestContainerJsonloadRandomEffectSamplesCombinedJsonloadRandomEffectSamplesCombinedJsonStringloadRandomEffectSamplesJsonloadScalarJsonloadVectorJsonpreprocessPredictionDatapreprocessTrainDataresetActiveForestresetForestModelresetRandomEffectsModelresetRandomEffectsTrackerrootResetRandomEffectsModelrootResetRandomEffectsTrackersampleGlobalErrorVarianceOneIterationsampleLeafVarianceOneIterationsaveBARTModelToJsonsaveBARTModelToJsonFilesaveBARTModelToJsonStringsaveBCFModelToJsonsaveBCFModelToJsonFilesaveBCFModelToJsonStringsavePreprocessorToJsonString

Dependencies:BHcpp11R6

Bayesian Supervised Learning in StochTree

Rendered fromBayesianSupervisedLearning.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-30
Started: 2024-06-18

Causal Machine Learning in StochTree

Rendered fromCausalInference.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-02-07
Started: 2024-06-18

Custom Sampling Routines in StochTree

Rendered fromCustomSamplingRoutine.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-02-05
Started: 2024-06-18

Kernel Methods from Tree Ensembles in StochTree

Rendered fromEnsembleKernel.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-31
Started: 2024-06-18

Bayesian Supervised Learning with Heteroskedasticity in StochTree

Rendered fromHeteroskedasticity.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-30
Started: 2024-10-07

Model Serialization in StochTree

Rendered fromModelSerialization.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-02-07
Started: 2024-06-18

Running Multiple Chains (Sequentially or in Parallel) in StochTree

Rendered fromMultiChain.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-30
Started: 2024-10-07

Prior Calibration Approaches for Parametric Components of Stochastic Tree Ensembles

Rendered fromPriorCalibration.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-30
Started: 2024-08-30

Deeper Dive on Sampled Forests in StochTree

Rendered fromTreeInspection.Rmdusingknitr::rmarkdownon Feb 13 2025.

Last update: 2025-01-30
Started: 2024-11-15

Readme and manuals

Help Manual

Help pageTopics
stochtree: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inferencestochtree-package stochtree
Run the BART algorithm for supervised learning.bart
Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation.bcf
Calibrate the scale parameter on an inverse gamma prior for the global error variance as in Chipman et al (2022)calibrateInverseGammaErrorVariance
Compute vector of forest leaf indicescomputeForestLeafIndices
Compute vector of forest leaf scale parameterscomputeForestLeafVariances
Compute and return the largest possible leaf index computable by 'computeForestLeafIndices' for the forests in a designated forest sample container.computeForestMaxLeafIndex
Convert the persistent aspects of a covariate preprocessor to (in-memory) C++ JSON objectconvertPreprocessorToJson
Class that stores draws from an random ensemble of decision treesCppJson
Class that wraps a C++ random number generator (for reproducibility)CppRNG
Convert a list of (in-memory) JSON representations of a BART model to a single combined BART model object which can be used for prediction, etc...createBARTModelFromCombinedJson
Convert a list of (in-memory) JSON strings that represent BART models to a single combined BART model object which can be used for prediction, etc...createBARTModelFromCombinedJsonString
Convert an (in-memory) JSON representation of a BART model to a BART model object which can be used for prediction, etc...createBARTModelFromJson
Convert a JSON file containing sample information on a trained BART model to a BART model object which can be used for prediction, etc...createBARTModelFromJsonFile
Convert a JSON string containing sample information on a trained BART model to a BART model object which can be used for prediction, etc...createBARTModelFromJsonString
Convert a list of (in-memory) JSON strings that represent BCF models to a single combined BCF model object which can be used for prediction, etc...createBCFModelFromCombinedJson
Convert a list of (in-memory) JSON strings that represent BCF models to a single combined BCF model object which can be used for prediction, etc...createBCFModelFromCombinedJsonString
Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc...createBCFModelFromJson
Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc...createBCFModelFromJsonFile
Convert a JSON string containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc...createBCFModelFromJsonString
Create a new (empty) C++ Json objectcreateCppJson
Create a C++ Json object from a Json filecreateCppJsonFile
Create a C++ Json object from a Json stringcreateCppJsonString
Create an R class that wraps a C++ random number generatorcreateCppRNG
Create a forestcreateForest
Create a forest dataset objectcreateForestDataset
Create a forest model objectcreateForestModel
Create a forest model config objectcreateForestModelConfig
Create a container of forest samplescreateForestSamples
Create a global model config objectcreateGlobalModelConfig
Create an outcome objectcreateOutcome
Reload a covariate preprocessor object from a JSON string containing a serialized preprocessorcreatePreprocessorFromJson
Reload a covariate preprocessor object from a JSON string containing a serialized preprocessorcreatePreprocessorFromJsonString
Create a 'RandomEffectSamples' objectcreateRandomEffectSamples
Create a random effects dataset objectcreateRandomEffectsDataset
Create a 'RandomEffectsModel' objectcreateRandomEffectsModel
Create a 'RandomEffectsTracker' objectcreateRandomEffectsTracker
Class that stores a single ensemble of decision trees (often treated as the "active forest")Forest
Dataset used to sample a forestForestDataset
Class that defines and samples a forest modelForestModel
Object used to get / set parameters and other model configuration options for a forest model in the "low-level" stochtree interfaceForestModelConfig
Class that stores draws from an random ensemble of decision treesForestSamples
Generic function for extracting random effect samples from a model object (BCF, BART, etc...)getRandomEffectSamples
Extract raw sample values for each of the random effect parameter terms.getRandomEffectSamples.bartmodel
Extract raw sample values for each of the random effect parameter terms.getRandomEffectSamples.bcfmodel
Object used to get / set global parameters and other global model configuration options in the "low-level" stochtree interfaceGlobalModelConfig
Combine multiple JSON model objects containing forests (with the same hierarchy / schema) into a single forest_containerloadForestContainerCombinedJson
Combine multiple JSON strings representing model objects containing forests (with the same hierarchy / schema) into a single forest_containerloadForestContainerCombinedJsonString
Load a container of forest samples from jsonloadForestContainerJson
Combine multiple JSON model objects containing random effects (with the same hierarchy / schema) into a single containerloadRandomEffectSamplesCombinedJson
Combine multiple JSON strings representing model objects containing random effects (with the same hierarchy / schema) into a single containerloadRandomEffectSamplesCombinedJsonString
Load a container of random effect samples from jsonloadRandomEffectSamplesJson
Load a scalar from jsonloadScalarJson
Load a vector from jsonloadVectorJson
Outcome / partial residual used to sample an additive model.Outcome
Predict from a sampled BART model on new datapredict.bartmodel
Predict from a sampled BCF model on new datapredict.bcfmodel
Preprocess covariates. DataFrames will be preprocessed based on their column types. Matrices will be passed through assuming all columns are numeric.preprocessPredictionData
Preprocess covariates. DataFrames will be preprocessed based on their column types. Matrices will be passed through assuming all columns are numeric.preprocessTrainData
Class that wraps the "persistent" aspects of a C++ random effects model (draws of the parameters and a map from the original label indices to the 0-indexed label numbers used to place group samples in memory (i.e. the first label is stored in column 0 of the sample matrix, the second label is store in column 1 of the sample matrix, etc...))RandomEffectSamples
Dataset used to sample a random effects modelRandomEffectsDataset
The core "model" class for sampling random effects.RandomEffectsModel
Class that defines a "tracker" for random effects models, most notably storing the data indices available in each group for quicker posterior computation and sampling of random effects terms.RandomEffectsTracker
Reset an active forest, either from a specific forest in a 'ForestContainer' or to an ensemble of single-node (i.e. root) treesresetActiveForest
Re-initialize a forest model (tracking data structures) from a specific forest in a 'ForestContainer'resetForestModel
Reset a 'RandomEffectsModel' object based on the parameters indexed by 'sample_num' in a 'RandomEffectsSamples' objectresetRandomEffectsModel
Reset a 'RandomEffectsTracker' object based on the parameters indexed by 'sample_num' in a 'RandomEffectsSamples' objectresetRandomEffectsTracker
Reset a 'RandomEffectsModel' object to its "default" staterootResetRandomEffectsModel
Reset a 'RandomEffectsTracker' object to its "default" staterootResetRandomEffectsTracker
Sample one iteration of the (inverse gamma) global variance modelsampleGlobalErrorVarianceOneIteration
Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!)sampleLeafVarianceOneIteration
Convert the persistent aspects of a BART model to (in-memory) JSONsaveBARTModelToJson
Convert the persistent aspects of a BART model to (in-memory) JSON and save to a filesaveBARTModelToJsonFile
Convert the persistent aspects of a BART model to (in-memory) JSON stringsaveBARTModelToJsonString
Convert the persistent aspects of a BCF model to (in-memory) JSONsaveBCFModelToJson
Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a filesaveBCFModelToJsonFile
Convert the persistent aspects of a BCF model to (in-memory) JSON stringsaveBCFModelToJsonString
Convert the persistent aspects of a covariate preprocessor to (in-memory) JSON stringsavePreprocessorToJsonString