View source: R/BMTrees_prediction.R
BMTrees_prediction | R Documentation |
Provides predictions for outcomes in longitudinal data using Bayesian Trees Mixed-Effects Models (BMTrees) and its semiparametric variants. The function predicts values for test data while accounting for random effects, complex relationships, and potential model misspecification.
BMTrees_prediction(
X_train,
Y_train,
Z_train,
subject_id_train,
X_test,
Z_test,
subject_id_test,
model = c("BMTrees", "BMTrees_R", "BMTrees_RE", "mixedBART"),
binary = FALSE,
nburn = 3000L,
npost = 4000L,
skip = 1L,
verbose = TRUE,
seed = NULL,
tol = 1e-20,
resample = 5,
ntrees = 200,
pi_CDP = 0.99
)
X_train |
A matrix of covariates in the training set. |
Y_train |
A numeric or logical vector of outcomes in the training set. |
Z_train |
A matrix of random predictors in the training set. |
subject_id_train |
A character vector of subject IDs in the training set. |
X_test |
A matrix of covariates in the testing set. |
Z_test |
A matrix of random predictors in the testing set. |
subject_id_test |
A character vector of subject IDs in the testing set. |
model |
A character string specifying the predictive model. Options are |
binary |
Logical. Indicates whether the outcome is binary ( |
nburn |
An integer specifying the number of burn-in iterations for Gibbs sampler.
Default: |
npost |
An integer specifying the number of posterior samples to collect. Default: |
skip |
An integer indicating the thinning interval for MCMC samples. Default: |
verbose |
Logical. If |
seed |
An optional integer for setting the random seed to ensure reproducibility. Default: |
tol |
A numeric tolerance value to prevent numerical overflow and underflow in the model. Default: |
resample |
An integer specifying the number of resampling steps for the CDP prior. Default: |
ntrees |
An integer specifying the number of trees in BART. Default: |
pi_CDP |
A value between 0 and 1 for calculating the empirical prior in the CDP prior. Default: |
A list containing posterior samples and predictions:
Posterior samples of the fixed-effects from BART on training data.
Posterior samples of covariance matrices in random effects.
Posterior samples of lambda parameter in CDP normal mixture on random errors.
Posterior samples of lambda parameter in CDP normal mixture on random-effects.
Posterior samples of the coefficients in random effects.
Posterior samples of random effects for training data.
Posterior samples of error deviation.
Posterior expectations of training data outcomes, equal to fixed-effects + random effects.
Posterior expectations of testing data outcomes, equal to fixed-effects + random effects.
Posterior predictive distributions for training outcomes, equal to fixed-effects + random effects + predictive residual.
Posterior predictive distributions for testing outcomes, equal to fixed-effects + random effects + predictive residual.
Posterior samples of location parameters in CDP normal mixture on random errors.
Posterior samples of location parameters in CDP normal mixture on random effects.
This function utilizes modified C++ code originally derived from the BART3 package (Bayesian Additive Regression Trees). The original package was developed by Rodney Sparapani and is licensed under GPL-2. Modifications were made by Jungang Zou, 2024.
For more information about the original BART3 package, see: https://github.com/rsparapa/bnptools/tree/master/BART3
data = simulation_prediction(n_subject = 100, seed = 1234, nonlinear = TRUE,
nonrandeff = TRUE, nonresidual = TRUE)
# To make it faster to compile and check, we only run 30 iterations for burn-in
# and 40 for posterior sampling phases.
# Please increase to 3000 and 4000 iterations, respectively, when running the model.
model = BMTrees_prediction(data$X_train, data$Y_train, data$Z_train,
data$subject_id_train, data$X_test, data$Z_test, data$subject_id_test, model = "BMTrees",
binary = FALSE, nburn = 30L, npost = 40L, skip = 1L, verbose = TRUE, seed = 1234)
model$post_predictive_y_test
model$post_sigma
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.