Learn R Programming

BartMixVs (version 1.0.0)

mc.wbart: BART for continuous responses with parallel computation

Description

BART is a Bayesian approach to nonparametric function estimation and inference using a sum of trees. For a continuous response \(y\) and a \(p-\)dimensional vector of predictors \(x = (x_1, ..., x_p)'\), BART models \(y\) and \(x\) using $$y = f(x) + \epsilon,$$ where \(f\) is a sum of Bayesian regression trees function and \(\epsilon ~ N(0, \sigma^2)\). The function mc.wbart() is inherited from the CRAN R package 'BART' and is a variant of the function wbart() with parallel computation.

Usage

mc.wbart(
  x.train,
  y.train,
  x.test = matrix(0, 0, 0),
  sparse = FALSE,
  theta = 0,
  omega = 1,
  a = 0.5,
  b = 1,
  augment = FALSE,
  rho = NULL,
  xinfo = matrix(0, 0, 0),
  numcut = 100L,
  usequants = FALSE,
  cont = FALSE,
  rm.const = TRUE,
  power = 2,
  base = 0.95,
  split.prob = "polynomial",
  k = 2,
  sigmaf = NA,
  sigest = NA,
  sigdf = 3,
  sigquant = 0.9,
  lambda = NA,
  fmean = mean(y.train),
  w = rep(1, length(y.train)),
  ntree = 200L,
  ndpost = 1000L,
  nskip = 100L,
  keepevery = 1L,
  printevery = 100L,
  keeptrainfits = TRUE,
  transposed = FALSE,
  verbose = FALSE,
  mc.cores = 2L,
  nice = 19L,
  seed = 99L
)

Arguments

x.train

A matrix or a data frame of predictors values (for training) with each row corresponding to an observation and each column corresponding to a predictor. If a predictor is a factor with \(q\) levels in a data frame, it is replaced with \(q\) dummy variables.

y.train

A vector of continuous response values for training.

x.test

A matrix or a data frame of predictors values for testing, which has the same structure as x.train.

sparse

A Boolean argument indicating whether to replace the discrete uniform distribution for selecting a split variable with a categorical distribution whose event probabilities follow a Dirichlet distribution (see Linero (2018) for details).

theta

Set theta parameter; zero means random.

omega

Set omega parameter; zero means random.

a

A sparse parameter of \(Beta(a, b)\) hyper-prior where \(0.5<=a<=1\); a lower value induces more sparsity.

b

A sparse parameter of \(Beta(a, b)\) hyper-prior; typically, \(b=1\).

augment

A Boolean argument indicating whether data augmentation is performed in the variable selection procedure of Linero (2018).

rho

A sparse parameter; typically \(\rho = p\) where \(p\) is the number of predictors.

xinfo

A matrix of cut-points with each row corresponding to a predictor and each column corresponding to a cut-point. xinfo=matrix(0.0,0,0) indicates the cut-points are specified by BART.

numcut

The number of possible cut-points; If a single number is given, this is used for all predictors; Otherwise a vector with length equal to ncol(x.train) is required, where the \(i-\)th element gives the number of cut-points for the \(i-\)th predictor in x.train. If usequants=FALSE, numcut equally spaced cut-points are used to cover the range of values in the corresponding column of x.train. If usequants=TRUE, then min(numcut, the number of unique values in the corresponding column of x.train - 1) cut-point values are used.

usequants

A Boolean argument indicating how the cut-points in xinfo are generated; If usequants=TRUE, uniform quantiles are used for the cut-points; Otherwise, the cut-points are generated uniformly.

cont

A Boolean argument indicating whether to assume all predictors are continuous.

rm.const

A Boolean argument indicating whether to remove constant predictors.

power

The power parameter of the polynomial splitting probability for the tree prior. Only used if split.prob="polynomial".

base

The base parameter of the polynomial splitting probability for the tree prior if split.prob="polynomial"; if split.prob="exponential", the probability of splitting a node at depth \(d\) is base\(^d\).

split.prob

A string indicating what kind of splitting probability is used for the tree prior. If split.prob="polynomial", the splitting probability in Chipman et al. (2010) is used; If split.prob="exponential", the splitting probability in Rockova and Saha (2019) is used.

k

The number of prior standard deviations that \(E(Y|x) = f(x)\) is away from \(+/-.5\). The response (y.train) is internally scaled to the range from \(-.5\) to \(.5\). The bigger k is, the more conservative the fitting will be.

sigmaf

The standard deviation of f.

sigest

A rough estimate of the error standard deviation, the square of which follows an inverse chi-squared prior. If sigest=NA, the rough estimate will be the usual least square estimator; Otherwise, the supplied value will be used.

sigdf

The degrees of freedom for the error variance prior.

sigquant

The quantile of the error variance prior, where sigest is placed. The closer the quantile is to 1, the more aggressive the fit will be.

lambda

The scale parameter of the error variance prior.

fmean

BART operates on y.train centered by fmean.

w

A vector of weights which multiply the standard deviation.

ntree

The number of trees in the ensemble.

ndpost

The number of posterior samples returned.

nskip

The number of posterior samples burned in.

keepevery

Every keepevery posterior sample is kept to be returned to the user.

printevery

As the MCMC runs, a message is printed every printevery iterations.

keeptrainfits

A Boolean argument indicating whether to keep yhat.train or not.

transposed

A Boolean argument indicating whether the matrices x.train and x.test are transposed.

verbose

A Boolean argument indicating whether any messages are printed out.

mc.cores

The number of cores to employ in parallel.

nice

Set the job niceness. The default niceness is \(19\) and niceness goes from \(0\) (highest) to \(19\) (lowest).

seed

Seed required for reproducible MCMC.

Value

The function mc.wbart() returns an object of type wbart which essentially is a list consisting of the following components.

sigma

A vector with nskip+ndpost*keepevery posterior samples of \(\sigma\).

yhat.train.mean

colMeans(yhat.train).

yhat.train

A matrix with ndpost rows and nrow(x.train) columns with each row corresponding to a draw \(f*\) from the posterior of \(f\) and each column corresponding to a training data point. The \((i,j)\)-th element of the matrix is \(f*(x)\) for the \(i\)-th kept draw of \(f\) and the \(j\)-th training data point. Burn-in posterior samples are dropped.

yhat.test.mean

colMeans(yhat.test).

yhat.test

A matrix with ndpost rows and nrow(x.test) columns with each row corresponding to a draw \(f*\) from the posterior of \(f\) and each column corresponding to a test data point. The \((i,j)\)-th element of the matrix is \(f*(x)\) for the \(i\)-th kept draw of \(f\) and the \(j\)-th test data point. Burn-in posterior samples are dropped.

varcount

A matrix with ndpost rows and ncol(x.train) columns with each row corresponding to a draw of the ensemble and each column corresponding to a predictor. The \((i,j)\)-th element is the number of times that the \(j\)- th predictor is used as a split variable in the \(i\)-th posterior sample.

varprob

A matrix with ndpost rows and ncol(x.train) columns with each row corresponding to a draw of the ensemble and each column corresponding to a predictor. The \((i,j)\)-th element is the split probability of the \(j\)- th predictor in the \(i\)-th posterior sample. Only useful when DART is fit, i.e., sparse=TRUE.

treedraws

A list containing the posterior samples of the ensembles (trees structures, split variables and split values); Can be used for prediction.

proc.time

The process time of running the function wbart().

mu

BART operates on y.train centered by fmean.

mr.vecs

A list of \(ncol(x.train)\) sub-lists with each corresponding to a predictor; Each sub-list contains ndpost vectors with each vector containing the (birth) Metropolis ratios for splits using the predictor as the split variable in that posterior sample.

vip

A vector of variable inclusion proportions (VIP) proposed in Chipman et al. (2010).

within.type.vip

A vector of within-type VIPs proposed in Luo and Daniels (2021).

pvip

A vector of marginal posterior variable inclusion probabilities (PVIP) proposed in Linero (2018); Only useful when DART is fit, i.e., sparse=TRUE.

varprob.mean

A vector of posterior split probabilities (PSP) proposed in Linero (2018); Only useful when DART is fit, i.e., sparse=TRUE.

mr.mean

A matrix with ndpost rows and ncol(x.train) columns with each row corresponding to a draw of the ensemble and each column corresponding to a predictor. The \((i,j)\)-th element is the average Metropolis acceptance ratio per splitting rule using the \(j\)-th predictor in the \(i\)-th posterior sample.

mi

A vector of Metropolis importance (MI) proposed in Luo and Daniels (2021).

rm.const

A vector of indicators for the predictors (after dummification) used in BART; when the indicator is negative, it refers to remove that predictor.

ndpost

The number of posterior samples returned.

Details

This function is inherited from BART::mc.wbart() and is a variant of the function wbart() with parallel computation. While the original features of BART::wbart() are preserved, two modifications are made. The first modification is to provide two types of split probability for BART. One split probability is proposed in Chipman et al. (2010) and defined as $$p(d) = \gamma * (1+d)^{-\beta},$$ where \(d\) is the depth of the node, \(\gamma \in (0,1)\) and \(\beta \in (0,\infty)\). The other split probability is proposed by Rockova and Saha (2019) and defined as $$p(d) = \gamma^d,$$ where \(\gamma \in (1/n, 1/2)\). BART with the second split probability is proved to achieve the optimal posterior contraction. The second modification is to provide five types of variable importance measures (vip, within.type.vip, pvip, varprob.mean and mi) in the return object, for the sake of the existence of mixed-type predictors.

References

Chipman, H. A., George, E. I. and McCulloch, R. E. (2010). "BART: Bayesian additive regression trees." Ann. Appl. Stat. 4 266--298.

Linero, A. R. (2018). "Bayesian regression trees for high-dimensional prediction and variable selection." J. Amer. Statist. Assoc. 113 626--636.

Luo, C. and Daniels, M. J. (2021) "Variable Selection Using Bayesian Additive Regression Trees." arXiv preprint arXiv:2112.13998.

Rockova V, Saha E (2019). <U+201C>On theory for BART.<U+201D> In The 22nd International Conference on Artificial Intelligence and Statistics (pp. 2839<U+2013>2848). PMLR.

Sparapani, R., Spanbauer, C. and McCulloch, R. (2021). "Nonparametric machine learning and efficient computation with bayesian additive regression trees: the BART R package." J. Stat. Softw. 97 1--66.

See Also

wbart.

Examples

Run this code
# NOT RUN {
## simulate data (Scenario C.M.1. in Luo and Daniels (2021))
set.seed(123)
data = mixone(100, 10, 1, FALSE)
## parallel::mcparallel/mccollect do not exist on windows
if(.Platform$OS.type=='unix') {
## test mc.wbart() function
  res = mc.wbart(data$X, data$Y, ntree=10, nskip=100, ndpost=100, mc.cores=2)
}
# }

Run the code above in your browser using DataLab