1

I am trying to run a MANOVA and run into the error:

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

I am aware that this occurs when a variable only has 1 level, or has multiple levels but only values for 1 of those levels. I have two variables that give this error, however, their table results are:

$varA

 No Yes 
 81 314 

$varB

 No Yes 
 35 363

The issue occurs after recoding one level of both of these variables. The cell counts were too low (5 and 2 respectively), due to which I have recoded them as NA. I then drop the unused level:

df$varA[df$varA=="unusableLevel"] <- NA
df$varB[df$varB=="unusableLevel"] <- NA
df <- droplevels(df)

Both variables are correctly specified as factors. I have tried using different methods for recoding the unusable level to NA. I have been scratching my head at this for a while. Unfortunately I cannot produce a minimal reproducible example as I am not allowed to share any of the data in any form.

Thanks for any help!

kneijenhuijs
  • 1,189
  • 1
  • 12
  • 21
  • 1
    you could try what's recommended [here](https://stackoverflow.com/questions/44200195/how-to-debug-contrasts-can-be-applied-only-to-factors-with-2-or-more-levels-er) – stevec Jul 26 '18 at 09:53
  • 1
    Hah! That actually worked. Turns out that after deletion of the NAs on other variables, all data points on one of the levels of both those variables disappeared. Thanks, I hadn't found that check! – kneijenhuijs Jul 26 '18 at 10:11

0 Answers0