In both cases, $f$ is the sum of many tree models. The goal is to have very flexible inference for the uknown function $f$.
In the spirit of
bart(
x.train, y.train, x.test=matrix(0.0,0,0),
sigest=NA, sigdf=3, sigquant=.90,
k=2.0,
power=2.0, base=.95,
binaryOffset=0,
ntree=200,
ndpost=1000, nskip=100,
printevery=100, keepevery=1, keeptrainfits=TRUE,
usequants=FALSE, numcut=100, printcutoffs=0,
verbose=TRUE)
## S3 method for class 'bart':
plot(
x,
plquants=c(.05,.95), cols =c('blue','black'),
...)
bart
will generate draws of $f(x)$ for each $x$ which is a row of x.test.bart
which contains the information to be plotted.plot
method sets mfrow to c(1,2) and makes two plots.
The first plot is the sequence of kept draws of $\sigma$
including the burn-in draws. Initially these draws will decline as BART finds fit
and then level off when the MCMC has burnt in.
The second plot has $y$ on the horizontal axis and posterior intervals for
the corresponding $f(x)$ on the vertical axis.
bart
returns a list assigned class
Note that in the binary $y$, case yhat.train and yhat.test are
$f(x)$ + binaryOffset. If you want draws of the probability
$P(Y=1 | x)$ you need to apply the normal cdf (pnorm
)
to these values.
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 $f^*(x)$ (and $\sigma^*$ in the numeric case) where * denotes a particular draw. The $x$ is either a row from the training data (x.train) or the test data (x.test).
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.
Friedman, J.H. (1991) Multivariate adaptive regression splines. The Annals of Statistics, 19, 1--67.
pdbart
##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
##run BART
set.seed(99)
bartFit = bart(x,y,ndpost=200) #default is ndpost=1000, this is to run example fast.
plot(bartFit) # plot bart fit
##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