makeind {BayesTree} | R Documentation |
Build x matrix from x data frame (convert factors to dummies)
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
makeind(
x,
all=TRUE)
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
Examples
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)
[Package BayesTree version 0.3-1.5 Index]