View source: R/posterior_transformation.R
| sample_bart_posterior_predictive | R Documentation |
Sample from the posterior predictive distribution for outcomes modeled by BART
sample_bart_posterior_predictive(
model_object,
X = NULL,
leaf_basis = NULL,
rfx_group_ids = NULL,
rfx_basis = NULL,
num_draws_per_sample = NULL
)
model_object |
A fitted BART model object of class |
X |
A matrix or data frame of covariates. Required if the BART model depends on covariates (e.g., contains a mean or variance forest). |
leaf_basis |
A matrix of bases for mean forest models with regression defined in the leaves. Required for "leaf regression" models. |
rfx_group_ids |
A vector of group IDs for random effects model. Required if the BART model includes random effects. |
rfx_basis |
A matrix of bases for random effects model. Required if the BART model includes random effects. |
num_draws_per_sample |
The number of posterior predictive samples to draw for each posterior sample. Defaults to a heuristic based on the number of samples in a BART model (i.e. if the BART model has >1000 draws, we use 1 draw from the likelihood per sample, otherwise we upsample to ensure intervals are based on at least 1000 posterior predictive draws). |
Array of posterior predictive samples with dimensions (num_observations, num_posterior_samples, num_draws_per_sample) if num_draws_per_sample > 1, otherwise (num_observations, num_posterior_samples).
n <- 100
p <- 5
X <- matrix(rnorm(n * p), nrow = n, ncol = p)
y <- 2 * X[,1] + rnorm(n)
bart_model <- bart(y_train = y, X_train = X)
ppd_samples <- sample_bart_posterior_predictive(
model_object = bart_model, X = X
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.