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

## Documentation for package ‘stochtree’ version 0.2.0

- DESCRIPTION file.
- Package NEWS.

## Help Pages

stochtree-package | stochtree: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference
bart | Run the BART algorithm for supervised learning.
bcf | Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation.
calibrateInverseGammaErrorVariance | Calibrate the scale parameter on an inverse gamma prior for the global error variance as in Chipman et al (2022)
computeForestLeafIndices | Compute vector of forest leaf indices
computeForestLeafVariances | Compute vector of forest leaf scale parameters
computeForestMaxLeafIndex | Compute and return the largest possible leaf index computable by 'computeForestLeafIndices' for the forests in a designated forest sample container.
compute_bart_posterior_interval | Compute posterior credible intervals for specified terms from a fitted BART model.
compute_bcf_posterior_interval | Compute posterior credible intervals for BCF model terms
compute_contrast_bart_model | Compute a contrast between two outcome prediction specifications for a BART model
compute_contrast_bcf_model | Compute a contrast between two outcome prediction specifications for a BCF model
convertPreprocessorToJson | Convert the persistent aspects of a covariate preprocessor to (in-memory) C++ JSON object
CppJson | Class that stores draws from an random ensemble of decision trees
CppRNG | Class that wraps a C++ random number generator (for reproducibility)
createBARTModelFromCombinedJson | 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...
createBARTModelFromCombinedJsonString | 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...
createBARTModelFromJson | Convert an (in-memory) JSON representation of a BART model to a BART model object which can be used for prediction, etc...
createBARTModelFromJsonFile | Convert a JSON file containing sample information on a trained BART model to a BART model object which can be used for prediction, etc...
createBARTModelFromJsonString | Convert a JSON string containing sample information on a trained BART model to a BART 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 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...
createBCFModelFromJson | Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc...
createBCFModelFromJsonFile | Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc...
createBCFModelFromJsonString | Convert a JSON string containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc...
createCppJson | Create a new (empty) C++ Json object
createCppJsonFile | Create a C++ Json object from a Json file
createCppJsonString | Create a C++ Json object from a Json string
createCppRNG | Create an R class that wraps a C++ random number generator
createForest | Create a forest
createForestDataset | Create a forest dataset object
createForestModel | Create a forest model object
createForestModelConfig | Create a forest model config object
createForestSamples | Create a container of forest samples
createGlobalModelConfig | Create a global model config object
createOutcome | Create an outcome object
createPreprocessorFromJson | Reload a covariate preprocessor object from a JSON string containing a serialized preprocessor
createPreprocessorFromJsonString | Reload a covariate preprocessor object from a JSON string containing a serialized preprocessor
createRandomEffectSamples | Create a 'RandomEffectSamples' object
createRandomEffectsDataset | Create a random effects dataset object
createRandomEffectsModel | Create a 'RandomEffectsModel' object
createRandomEffectsTracker | Create a 'RandomEffectsTracker' object
expand_dims_1d | Convert scalar input to vector of dimension 'output_size', or check that input array is equivalent to a vector of dimension 'output_size'.
expand_dims_2d | Ensures that input is propagated appropriately to a matrix of dimension 'output_rows' x 'output_cols'.
expand_dims_2d_diag | Convert scalar input to square matrix of dimension 'output_size' x 'output_size' with 'input' along the diagonal, or check that input array is equivalent to a square matrix of dimension 'output_size' x 'output_size'.
Forest | Class that stores a single ensemble of decision trees (often treated as the "active forest")
ForestDataset | Dataset used to sample a forest
ForestModel | Class that defines and samples a forest model
ForestModelConfig | Object used to get / set parameters and other model configuration options for a forest model in the "low-level" stochtree interface
ForestSamples | Class that stores draws from an random ensemble of decision trees
getRandomEffectSamples | Generic function for extracting random effect samples from a model object (BCF, BART, etc...)
getRandomEffectSamples.bartmodel | Extract raw sample values for each of the random effect parameter terms.
getRandomEffectSamples.bcfmodel | Extract raw sample values for each of the random effect parameter terms.
GlobalModelConfig | Object used to get / set global parameters and other global model configuration options in the "low-level" stochtree interface
loadForestContainerCombinedJson | Combine multiple JSON model objects containing forests (with the same hierarchy / schema) into a single forest_container
loadForestContainerCombinedJsonString | Combine multiple JSON strings representing model objects containing forests (with the same hierarchy / schema) into a single forest_container
loadForestContainerJson | Load a container of forest samples from json
loadRandomEffectSamplesCombinedJson | Combine multiple JSON model objects containing random effects (with the same hierarchy / schema) into a single container
loadRandomEffectSamplesCombinedJsonString | Combine multiple JSON strings representing model objects containing random effects (with the same hierarchy / schema) into a single container
loadRandomEffectSamplesJson | Load a container of random effect samples from json
loadScalarJson | Load a scalar from json
loadVectorJson | Load a vector from json
Outcome | Outcome / partial residual used to sample an additive model.
predict.bartmodel | Predict from a sampled BART model on new data
predict.bcfmodel | Predict from a sampled BCF model on new data
preprocessPredictionData | Preprocess covariates for use in a 'ForestDataset' at prediction time.
preprocessTrainData | Preprocess covariates for use in a 'ForestDataset' at train time.
RandomEffectSamples | Class that wraps the "persistent" aspects of a C++ random effects model.
RandomEffectsDataset | Dataset used to sample a random effects model
RandomEffectsModel | The core "model" class for sampling random effects.
RandomEffectsTracker | 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.
resetActiveForest | Reset an active forest, either from a specific forest in a 'ForestContainer' or to an ensemble of single-node (i.e. root) trees
resetForestModel | Re-initialize a forest model (tracking data structures) from a specific forest in a 'ForestContainer'
resetRandomEffectsModel | Reset a 'RandomEffectsModel' object based on the parameters indexed by 'sample_num' in a 'RandomEffectsSamples' object
resetRandomEffectsTracker | Reset a 'RandomEffectsTracker' object based on the parameters indexed by 'sample_num' in a 'RandomEffectsSamples' object
rootResetRandomEffectsModel | Reset a 'RandomEffectsModel' object to its "default" state
rootResetRandomEffectsTracker | Reset a 'RandomEffectsTracker' object to its "default" state
sampleGlobalErrorVarianceOneIteration | Sample one iteration of the (inverse gamma) global variance model
sampleLeafVarianceOneIteration | Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!)
sample_bart_posterior_predictive | Sample from the posterior predictive distribution for outcomes modeled by BART
sample_bcf_posterior_predictive | Sample from the posterior predictive distribution for outcomes modeled by BCF
sample_without_replacement | Draw 'sample_size' samples from 'population_vector' without replacement, weighted by 'sampling_probabilities'
saveBARTModelToJson | Convert the persistent aspects of a BART model to (in-memory) JSON
saveBARTModelToJsonFile | Convert the persistent aspects of a BART model to (in-memory) JSON and save to a file
saveBARTModelToJsonString | Convert the persistent aspects of a BART model to (in-memory) JSON string
saveBCFModelToJson | Convert the persistent aspects of a BCF model to (in-memory) JSON
saveBCFModelToJsonFile | Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file
saveBCFModelToJsonString | Convert the persistent aspects of a BCF model to (in-memory) JSON string
savePreprocessorToJsonString | Convert the persistent aspects of a covariate preprocessor to (in-memory) JSON string
stochtree | stochtree: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference