wbart {BART} | R Documentation |

BART is a Bayesian “sum-of-trees” model.

For a numeric response *y*, we have
*y = f(x) + e*,
where *e ~ N(0,sigma^2)*.

*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 “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.

wbart( x.train, y.train, x.test=matrix(0.0,0,0), sparse=FALSE, theta=0, omega=1, a=0.5, b=1, augment=FALSE, rho=NULL, xinfo=matrix(0.0,0,0), usequants=FALSE, cont=FALSE, rm.const=TRUE, sigest=NA, sigdf=3, sigquant=.90, k=2.0, power=2.0, base=.95, sigmaf=NA, lambda=NA, fmean=mean(y.train), w=rep(1,length(y.train)), ntree=200L, numcut=100L, ndpost=1000L, nskip=100L, keepevery=1L, nkeeptrain=ndpost, nkeeptest=ndpost, nkeeptestmean=ndpost, nkeeptreedraws=ndpost, printevery=100L, transposed=FALSE )

`x.train` |
Explanatory variables for training (in sample) data. |

`y.train` |
Continuous dependent variable for training (in sample) data. |

`x.test` |
Explanatory variables for test (out of sample) data. |

`sparse` |
Whether to perform variable selection based on a sparse Dirichlet prior rather than simply uniform; see Linero 2016. |

`theta` |
Set |

`omega` |
Set |

`a` |
Sparse parameter for |

`b` |
Sparse parameter for |

`rho` |
Sparse parameter: typically |

`augment` |
Whether data augmentation is to be performed in sparse variable selection. |

`xinfo` |
You can provide the cutpoints to BART or let BART
choose them for you. To provide them, use the |

`usequants` |
If |

`cont` |
Whether or not to assume all variables are continuous. |

`rm.const` |
Whether or not to remove constant variables. |

`sigest` |
The prior for the error variance ( |

`sigdf` |
Degrees of freedom for error variance prior. |

`sigquant` |
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 ( |

`k` |
For numeric y,
k is the number of prior standard deviations |

`power` |
Power parameter for tree prior. |

`base` |
Base parameter for tree prior. |

`sigmaf` |
The SD of f. |

`lambda` |
The scale of the prior for the variance. |

`fmean` |
BART operates on |

`w` |
Vector of weights which multiply the standard deviation. |

`ntree` |
The number of trees in the sum. |

`numcut` |
The number of possible values of c (see 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 |

`ndpost` |
The number of posterior draws returned. |

`nskip` |
Number of MCMC iterations to be treated as burn in. |

`nkeeptrain` |
Number of MCMC iterations to be returned for train data. |

`nkeeptest` |
Number of MCMC iterations to be returned for test data. |

`nkeeptestmean` |
Number of MCMC iterations to be returned for test mean. |

`nkeeptreedraws` |
Number of MCMC iterations to be returned for tree draws. |

`printevery` |
As the MCMC runs, a message is printed every printevery draws. |

`keepevery` |
Every keepevery draw is kept to be returned to the user. |

`transposed` |
When running |

BART is an Bayesian MCMC method.
At each MCMC interation, we produce a draw from the joint posterior
*(f,sigma) \| (x,y)* in the numeric *y* case.

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).

`wbart`

returns an object of type `wbart`

which is
essentially a list.
In the numeric *y* case, the list has components:

`yhat.train` |
A matrix with ndpost rows and nrow(x.train) columns.
Each row corresponds to a draw |

`yhat.test` |
Same as yhat.train but now the x's are the rows of the test data. |

`yhat.train.mean` |
train data fits = mean of yhat.train columns. |

`yhat.test.mean` |
test data fits = mean of yhat.test columns. |

`sigma` |
post burn in draws of sigma, length = ndpost. |

`first.sigma` |
burn-in draws of sigma. |

`varcount` |
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. |

`sigest` |
The rough error standard deviation ( |

##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)) ## End(Not run)

[Package *BART* version 2.9 Index]