BART is a Bayesian “sum-of-trees” model.
For a numeric response
In the spirit of “ensemble models”, each tree is constrained by a prior to be a weak learner so that it contributes a small amount to the overall fit.
gbmm(
x.train, y.train,
x.test=matrix(0,0,0), type='wbart',
u.train=NULL, B=NULL,
ntype=as.integer(
factor(type, levels=c('wbart', 'pbart'))),
sparse=FALSE, theta=0, omega=1,
a=0.5, b=1, augment=FALSE, rho=NULL,
xinfo=matrix(0,0,0), usequants=FALSE,
rm.const=TRUE,
sigest=NA, sigdf=3, sigquant=0.90,
k=2, power=2, base=0.95,
lambda=NA, tau.num=c(NA, 3, 6)[ntype],
offset=NULL,
ntree=c(200L, 50L, 50L)[ntype], numcut=100L,
ndpost=1000L, nskip=100L,
keepevery=c(1L, 10L, 10L)[ntype],
printevery=100L, transposed=FALSE,
hostname=FALSE,
mc.cores = 1L, ## mc.gbmm only
nice = 19L, ## mc.gbmm only
seed = 99L ## mc.gbmm only
)mc.gbmm(
x.train, y.train,
x.test=matrix(0,0,0), type='wbart',
u.train=NULL, B=NULL,
ntype=as.integer(
factor(type, levels=c('wbart', 'pbart'))),
sparse=FALSE, theta=0, omega=1,
a=0.5, b=1, augment=FALSE, rho=NULL,
xinfo=matrix(0,0,0), usequants=FALSE,
rm.const=TRUE,
sigest=NA, sigdf=3, sigquant=0.90,
k=2, power=2, base=0.95,
lambda=NA, tau.num=c(NA, 3, 6)[ntype],
offset=NULL,
ntree=c(200L, 50L, 50L)[ntype], numcut=100L,
ndpost=1000L, nskip=100L,
keepevery=c(1L, 10L, 10L)[ntype],
printevery=100L, transposed=FALSE,
hostname=FALSE,
mc.cores = 2L, nice = 19L, seed = 99L
)
Explanatory variables for training (in sample)
data. May be a matrix or a data frame, with (as usual) rows
corresponding to observations and columns to variables. If a
variable is a factor in a data frame, it is replaced with dummies.
Note that gbmm
will generate draws of x.train
.
Continuous or binary dependent variable for training (in sample) data.
If type
to specify a logit BART model.
Explanatory variables for test (out of sample)
data. Should have same structure as x.train
.
gbmm
will generate draws of x.test
.
Integer indices specifying the random effects.
The prior for the standard deviation of the random effects
is
You can use this argument to specify the type of fit.
'wbart'
for continuous BART or 'pbart'
for probit BART.
The integer equivalent of type
where
'wbart'
is 1 and 'pbart'
is 2.
Whether to perform variable selection based on a sparse Dirichlet prior rather than simply uniform; see Linero 2016.
Set
Set
Sparse parameter for
Sparse parameter for
Sparse parameter: typically
Whether data augmentation is to be performed in sparse variable selection.
You can provide the cutpoints to BART or let BART
choose them for you. To provide them, use the xinfo
argument to specify a list (matrix) where the items (rows) are the
covariates and the contents of the items (columns) are the
cutpoints.
If usequants=FALSE
, then the
cutpoints in xinfo
are generated uniformly; otherwise,
if TRUE
, uniform quantiles are used for the cutpoints.
Whether or not to remove constant variables.
The prior for the error variance
(sigest=NA
then the rough estimate will be the usual least squares
estimator. Otherwise the supplied value will be used.
Not used if
Degrees of freedom for error variance prior.
Not used if
The quantile of the prior that the rough estimate
(see sigest
) is placed at. The closer the quantile is to 1, the more
aggresive the fit will be as you are putting more prior weight on
error standard deviations (
For numeric k
is the number of prior
standard deviations k
is the number of prior standard
deviations k
is, the more
conservative the fitting will be.
Power parameter for tree prior.
Base parameter for tree prior.
The scale of the prior for the variance. If lambda
is zero,
then the variance is to be considered fixed and known at the given
value of sigest
. Not used if
The numerator in the tau
definition, i.e.,
tau=tau.num/(k*sqrt(ntree))
.
Continous BART operates on y.train
centered by
offset
which defaults to mean(y.train)
. With binary
BART, the centering is offset
defaults to F^{-1}(mean(y.train))
. You can use
the offset
parameter to over-ride these defaults.
The number of trees in the sum.
The number of possible values of usequants
). If a single number if given, this is used for all
variables. Otherwise a vector with length equal to
ncol(x.train)
is required, where the x.train
. If usequants is false, numcut equally
spaced cutoffs are used covering the range of values in the
corresponding column of x.train
. If usequants
is true, then
The number of posterior draws returned.
Number of MCMC iterations to be treated as burn in.
As the MCMC runs, a message is printed every printevery draws.
Every keepevery draw is kept to be returned to the user.
When running gbmm
in parallel, it is more memory-efficient
to transpose x.train
and x.test
, if any, prior to
calling mc.gbmm
.
When running on a cluster occasionally it is useful
to track on which node each chain is running; to do so
set this argument to TRUE
.
Setting the seed required for reproducible MCMC.
Number of cores to employ in parallel.
Set the job niceness. The default niceness is 19: niceness goes from 0 (highest) to 19 (lowest).
gbmm
returns an object of type gbmm
which is
essentially a list.
In the numeric
A matrix with ndpost rows and nrow(x.train) columns.
Each row corresponds to a draw
Same as yhat.train but now the x's are the rows of the test data.
train data fits = mean of yhat.train columns.
test data fits = mean of yhat.test columns.
post burn in draws of sigma, length = ndpost.
burn-in draws of sigma.
a matrix with ndpost rows and nrow(x.train) columns. Each row is for a draw. For each variable (corresponding to the columns), the total count of the number of times that variable is used in a tree decision rule (over all trees) is given.
The rough error standard deviation (
BART is a Bayesian MCMC method.
At each MCMC interation, we produce a draw from the joint posterior
Thus, unlike a lot of other modelling methods in R, we do not produce
a single model object from which fits and summaries may be extracted.
The output consists of values x.train
or the test data, x.test
.
For x.train
/x.test with missing data elements, gbmm
will singly impute them with hot decking. For one or more missing
covariates, record-level hot-decking imputation deWaPann11 is
employed that is biased towards the null, i.e., nonmissing values
from another record are randomly selected regardless of the
outcome. Since mc.gbmm
runs multiple gbmm
threads in
parallel, mc.gbmm
performs multiple imputation with hot
decking, i.e., a separate imputation for each thread. This
record-level hot-decking imputation is biased towards the null, i.e.,
nonmissing values from another record are randomly selected
regardless of y.train
.
Chipman, H., George, E., and McCulloch R. (2010) Bayesian Additive Regression Trees. The Annals of Applied Statistics, 4,1, 266-298 <doi:10.1214/09-AOAS285>.
Chipman, H., George, E., and McCulloch R. (2006) Bayesian Ensemble Learning. Advances in Neural Information Processing Systems 19, Scholkopf, Platt and Hoffman, Eds., MIT Press, Cambridge, MA, 265-272.
De Waal, T., Pannekoek, J. and Scholtus, S. (2011) Handbook of statistical data editing and imputation. John Wiley & Sons, Hoboken, NJ.
Friedman, J.H. (1991) Multivariate adaptive regression splines. The Annals of Statistics, 19, 1--67.
Linero, A.R. (2018) Bayesian regression trees for high dimensional prediction and variable selection. JASA, 113(522), 626--636.
# NOT RUN {
##simulate data (example from Friedman MARS paper)
f = function(x){
10*sin(pi*x[,1]*x[,2]) + 20*(x[,3]-.5)^2+10*x[,4]+5*x[,5]
}
sigma = 1.0 #y = f(x) + sigma*z , z~N(0,1)
n = 100 #number of observations
set.seed(99)
x=matrix(runif(n*10),n,10) #10 variables, only first 5 matter
Ey = f(x)
y=Ey+sigma*rnorm(n)
lmFit = lm(y~.,data.frame(x,y)) #compare lm fit to BART later
##test BART with token run to ensure installation works
set.seed(99)
bartFit = wbart(x,y,nskip=5,ndpost=5)
# }
# NOT RUN {
##run BART
set.seed(99)
bartFit = wbart(x,y)
##compare BART fit to linear matter and truth = Ey
fitmat = cbind(y,Ey,lmFit$fitted,bartFit$yhat.train.mean)
colnames(fitmat) = c('y','Ey','lm','bart')
print(cor(fitmat))
# }
Run the code above in your browser using DataLab