Learn R Programming

rbart (version 1.0)

rbartModelMatrix: Model Matrix for BART

Description

rbartModelMatrix takes a data frame of explanatory variables (x) and turns it into a numeric matrix suitable for BART. This is used when some of the x variables are factors. The returned matrix will first have columns for all the numeric variables in the data frame and then columns for all the factors expanded into binary dummy variables. Note that if a factor has k levels, then BART wants k dummies (not k-1 as in linear regression). So for example, a factor with two levels named xf, will result in two columns named xf1 and xf2.

Usage

rbartModelMatrix(xdf)

Arguments

xdf

Data frame to be turned into a matrix for BART.

Value

Matrix from of explanatory variables in the data frame xdf.

Examples

Run this code
# NOT RUN {
set.seed(99)
xdf = data.frame(x1=1:15,x2=as.factor(c(rep(1,5),rep(2,5),rep(3,5))),
           x3=runif(15),x4=as.factor(c(rep(1,5),rep(2,10))))
print(head(xdf))

xm = rbartModelMatrix(xdf)
print(head(xm))
# }

Run the code above in your browser using DataLab