rbartModelMatrix: Model Matrix for BART

Description Usage Arguments Value Examples

View source: R/rbartModelMatrix.R

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

1

Arguments

xdf

Data frame to be turned into a matrix for BART.

Value

Matrix from of explanatory variables in the data frame xdf.

Examples

1
2
3
4
5
6
7
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))

rbart documentation built on Aug. 1, 2019, 5:04 p.m.