.getXlevels
Record Levels of Factors Used in a Model
Description
Records the levels of the factors used as predictors in a model.
Usage
.getXlevels(Terms, m)
Arguments
Terms |
an object of class terms as made by the terms function.
|
m |
a data.frame containing the variables used in the Terms argument.
|
Details
This function is used in modeling functions (for example, lm) where
it is typically used to create the xlevels component of the return value.
The predict method for the modeling function should use this
component to map character strings to integers when converting the
newdata to a data.frame
similar to the data argument used to fit the model.
(predict.lm does this by calling model.matrix.lm.)
Many modeling algorithms use character predictors
directly without mapping them to an integer,
so they have no need for .getXlevels.
Users of modeling functions have no need of .getXlevels;
rather, it is for writers of modeling functions.
Value
returns a list with one component for each character-valued or factor-valued
predictor listing the levels in that predictor.
See Also
Examples
myFormula <- y ~ x1 + x2
myDataFrame <- data.frame(
y=1:10,
x1=log(1:10),
x2=factor(rep(c("B","C"),c(4,6)), levels=c("C","B","A")),
x3=factor(rep(c("P","Q","R"),c(3,3,4))))
.getXlevels(terms(myFormula),
model.frame(myFormula, drop.unused.levels = TRUE, data = myDataFrame))