Warning message - dummy from dummies package

一个人想着一个人 提交于 2019-12-24 11:23:50

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/56637183/warning-message-dummy-from-dummies-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!