Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning message - dummy from dummies package

I am using the dummies package to generate dummy variables for categorical variables, some with more than two categories.

testdf<- data.frame(
  "A" = as.factor(c(1,2,2,3,3,1)),
  "B" = c('A','B','A','B','C','C'),
  "C"= c('D','D','E','D','D','E'))
#
#Generate dummy variables:
#
testdf<- cbind(testdf, dummy(testdf$C, sep='_'))
testdf<- cbind(testdf, dummy(testdf$B, sep='_'))

For both commands I get:

Warning message:
In model.matrix.default(~x - 1, model.frame(~x - 1), contrasts = FALSE) :
  non-list contrasts argument ignored

The results seem correct though. Can you please advice regarding the reason of the warning?

like image 245
Max_IT Avatar asked Jun 17 '19 18:06

Max_IT


1 Answers

In the code for dummy, the function calls

mm <- model.matrix(~x - 1, model.frame(~x - 1), contrasts = FALSE)

Note they are passing "FALSE" to the contrasts= arguments (which is really the contrasts.arg= argument). According to the ?model.matrix help page, this is supposed to be a list of contrasts. It's not supposed to be a TRUE/FALSE value. Note this additional message in the help page ?model.matrix

Whereas invalid contrasts.args have been ignored always, they are warned about since R version 3.6.0

So basically the package used a parameter incorrectly that was silently ignored in previous version of R, but starting in R 3.6 now triggers a warning. The behavior isn't any different, but the warning is new. It doesn't look like that package has been updated since 2012 so it might not ever get updated to make the warning go away.

like image 149
MrFlick Avatar answered Oct 03 '22 04:10

MrFlick