0

I have a data frame with about 40 rows of data and I am trying to run a multiple regression analysis. I am a beginner with R and don't know what's wrong. I have cleaned out the NA's with the omit.na function

Regression <- lm(y ~ annu+gdp+pce+int+oil+usex+exf+inxf+m.2, data = data)

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels In addition: Warning message: In storage.mode(v) <- "double" : NAs introduced by coercion

thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • 2
    The error tells you that one of the categorical IVs has only a single level. Since you don't share `data`, it's impossible for us to know which one. You can reproduce the error with e.g. `lm(mpg ~ wt + tmp, transform(mtcars, tmp = factor(1)))`. – Maurits Evers Mar 30 '22 at 01:57
  • 1
    Seconding Maurits's point - try `sapply(data, \(x) length(unique(na.omit(x))) )` and see which of your variables have only 1 unique value. – thelatemail Mar 30 '22 at 02:00

0 Answers0