Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels

This error occurs while applying glm() function for logistic regression if the data set has any variable with only NAs OR any of the variables in the data set has only one value.


To avoid this error, all the NAs in the data set must be either removed or taken care by replacing them with appropriate values. Once this is done all the variables with only one value must be removed from the data set used to train the model.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.