makeind: Build x matrix from x data frame (convert factors to dummies)

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Converts factors to dummies.
Note that with more than one level, BART needs a dummy for each level of a factor (unlike in linear regression where one of the dummies is dropped).

Usage

1
2
3

Arguments

x

Data frame of explanatory variables.

all

If all=TRUE, a factor with p levels will be replaced by all p dummies. If all=FALSE, the pth dummy is dropped.

Details

Uses function class.ind from the nnet library. Note that if you have train and test data frames, it may be best to rbind the two together, apply makeind to the result, and then pull them back apart.

Value

A matrix.
Numerical variables come first, and then the appended dummies.

Author(s)

Hugh Chipman: hugh.chipman@acadiau.ca
Robert McCulloch: robert.mcculloch@chicagogsb.edu.

See Also

bart

Examples

1
2
3
4
5
6
7
x1 = 1:10
x2 = as.factor(c(rep(1,5),rep(2,5)))
x3 = as.factor(c(1,1,1,2,2,2,4,4,4,4))
levels(x3) = c('rob','hugh','ed')
x = data.frame(x1,x2,x3)

junk = makeind(x)

BayesTree documentation built on May 1, 2019, 11:30 p.m.

Related to makeind in BayesTree...