Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Predict function in R: factor has new levels error

$
0
0

So I've built a MLR model in R, it has a categorical variable in it with like 93 levels (so many). I tried grouping some levels or removing the predictor altogether but this had a negative impact so I've had to leave it in. Model seems to be working fine so I want to created a predicted vs observed plot, however when I run the predict function on my model it comes up with this error:

"Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor C has new levels xxxx, yyyy"

Has anyone had this error before? I'm not sure how to fix it, and it only comes up when I try to predict.

Here's the code I used also:

lm12<-lm(log(A)~B+C+log(D)+E+F+log(G)+log(H), data=mydata)
pred<-predict(lm12,mydata)

(B and C are categorical, the rest are continuous.)

Thank you!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>