Skip to content
Prev 201578 / 398506 Next

predict: remove columns with new levels automatically

On Nov 25, 2009, at 1:48 AM, Andreas Wittmann wrote:

            
If you use str to look at the lm1 object you will find at the bottom a  
list called "x":

lm1$x will show you the factors that were present in variables at the  
time of the model creation
 > lm1$x
$z
[1] "A" "B" "C"

New testing scenario good level and bad level:

test <- data.frame(x=t<-rnorm(2), y=t+rnorm(2), z=c("B", "D") )
  lm1 <- lm(x ~ ., data=training)
  predict(lm1, subset(test, z %in% lm1$x$z) )  # get prediction for  
good level only
         1
0.4225204
David Winsemius, MD
Heritage Laboratories
West Hartford, CT