Learn R Programming

SBMTrees (version 1.4)

BMTrees_prediction: Bayesian Trees Mixed-Effects Models for Predicting Longitudinal Outcomes

Description

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.

Usage

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,
  ntrees = 200,
  pi_DP = 0.99,
  k = 2
)

Value

A list containing posterior samples and predictions:

post_tree_train

Posterior samples of the fixed-effects from BART on training data.

post_Sigma

Posterior samples of covariance matrices in random effects.

post_lambda_G

Posterior samples of lambda parameter in DP normal mixture on random errors.

post_lambda_F

Posterior samples of lambda parameter in DP normal mixture on random-effects.

post_B

Posterior samples of the coefficients in random effects.

post_random_effect_train

Posterior samples of random effects for training data.

post_sigma

Posterior samples of error deviation.

post_expectation_y_train

Posterior expectations of training data outcomes, equal to fixed-effects + random effects.

post_expectation_y_test

Posterior expectations of testing data outcomes, equal to fixed-effects + random effects.

post_predictive_y_train

Posterior predictive distributions for training outcomes, equal to fixed-effects + random effects + predictive residual.

post_predictive_y_test

Posterior predictive distributions for testing outcomes, equal to fixed-effects + random effects + predictive residual.

post_eta

Posterior samples of location parameters in DP normal mixture on random errors.

post_mu

Posterior samples of location parameters in DP normal mixture on random effects.

Arguments

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 "BMTrees", "BMTrees_R", "BMTrees_RE", and "mixedBART". Default: "BMTrees".

binary

Logical. Indicates whether the outcome is binary (TRUE) or continuous (FALSE). Default: FALSE.

nburn

An integer specifying the number of burn-in iterations for Gibbs sampler. Default: 3000L.

npost

An integer specifying the number of posterior samples to collect. Default: 4000L.

skip

An integer indicating the thinning interval for MCMC samples. Default: 1L.

verbose

Logical. If TRUE, displays MCMC progress. If FALSE, shows a progress bar. Default: TRUE.

seed

An optional integer for setting the random seed to ensure reproducibility. Default: NULL.

tol

A numeric tolerance value to prevent numerical overflow and underflow in the model. Default: 1e-20.

ntrees

An integer specifying the number of trees in BART. Default: 200.

pi_DP

A value between 0 and 1 for calculating the empirical prior in the DP prior. Default: 0.99.

k

A numeric value for the BART prior parameter controlling the standard deviation of the terminal node values. Default: 2.0.

References

For more information about the original BART3 package, see: https://github.com/rsparapa/bnptools/tree/master/BART3

Examples

Run this code
data <- simulation_prediction_conti(
  train_prop = 0.7,
  n_subject = 20,
  seed = 1234,
  nonlinear = TRUE,
  residual = "normal",
  randeff = "MVN"
)
model <- BMTrees_prediction(
  X_train = data$X_train,
  Y_train = data$Y_train,
  Z_train = data$Z_train,
  subject_id_train = data$subject_id_train,
  X_test = data$X_test,
  Z_test = data$Z_test,
  subject_id_test = data$subject_id_test,
  model = "BMTrees",
  binary = FALSE,
  nburn = 0L, npost = 1L, skip = 1L, verbose = FALSE, seed = 1234
)

Run the code above in your browser using DataLab