Converts a data frame with numeric and factor contents into a matrix,
suitable for use with
bart. Unlike in linear regression,
factors containing more than two levels result in dummy variables being
created for each level.
Data frame of explanatory variables.
Logical or list controling whether or not columns that are constants or factor
levels with no instances are omitted from the result. When a list, must be of
length equal to
Not currently implemented.
Note that if you have train and test data frames, it may be best
rbind the two together, apply
to the result, and then pull them back apart. Alternatively, save the drop
attribute used in creating the train data and use it when creating a matrix
from the test data. Example given below.
A matrix with columns corresponding to the elements of the data frame. If
drop = TRUE
or is a list, the attribute
drop on the result is set to the list used when creating
Vincent Dorie: [email protected].
1 2 3 4 5 6 7 8 9 10 11 12 13
iv <- 1:10 rv <- runif(10) f <- factor(rep(seq.int(3), c(4L, 4L, 2L)), labels = c("alice", "bob", "charlie")) df <- data.frame(iv, rv, f) mm <- makeModelMatrixFromDataFrame(df) ## create test and train matrices with disjoint factor levels train.df <- df[1:8,] test.df <- df[9:10,] train.mm <- makeModelMatrixFromDataFrame(train.df) test.mm <- makeModelMatrixFromDataFrame(test.df, attr(train.mm, "drop"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.