remove_missing_levels {sperrorest} | R Documentation |
remove_missing_levels
Description
Accounts for missing factor levels present only in test data but not in train data by setting values to NA
Usage
remove_missing_levels(fit, test_data)
Arguments
fit |
fitted model on training data |
test_data |
data to make predictions for |
Value
data.frame with matching factor levels to fitted model
Examples
foo <- data.frame(
response = rnorm(3),
predictor = as.factor(c("A", "B", "C"))
)
model <- lm(response ~ predictor, foo)
foo.new <- data.frame(predictor = as.factor(c("A", "B", "C", "D")))
predict(model, newdata = remove_missing_levels(
fit = model,
test_data = foo.new
))
[Package sperrorest version 3.0.5 Index]