Reputation: 424
I now see a warning when running gam()
. MWE below:
library(gam)
data(Boston, package = 'MASS')
model.gam <- gam(formula = medv ~ crim + zn, data = Boston)
The warning I receive is:
Warning message:
In model.matrix.default(mt, mf, contrasts) :
non-list contrasts argument ignored
I think this may relate to a change in the model.matrix()
function in the latest R release: https://cran.r-project.org/doc/manuals/r-release/NEWS.html. I did not receive a warning earlier today when running R version 3.5.
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] splines stats graphics grDevices utils datasets
[7] methods base
other attached packages:
[1] gam_1.16 foreach_1.4.4
loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1 yaml_2.2.0
[4] codetools_0.2-16 iterators_1.0.10
Upvotes: 2
Views: 2453
Reputation: 226761
tl;dr this looks like a (long-standing?) bug in gam::gam
that's exposed by the new warning in version 3.6.0, but seems more or less harmless.
To see what's going on, set options(warn=2)
(convert warnings to errors) and then run traceback()
after the error occurs.
...
4: warning("non-list contrasts argument ignored")
3: model.matrix.default(mt, mf, contrasts)
2: model.matrix(mt, mf, contrasts)
1: gam(formula = medv ~ crim + zn, data = Boston)
OK, the fact that the warning/error occurs inside model.matrix.default()
is not surprising. We have to examine/debug gam::gam
to see what's going on. If we examine the source code, the only place that "contrasts" occurs is:
X <- if (!is.empty.model(mt))
model.matrix(mt, mf, contrasts)
contrasts
is not an argument to the function, and can't have come from the ...
argument. The ...
argument gets passed through to gam.control()
, which also has a ...
argument -- which it silently ignores! Thus if you used gam(..., contrasts=contr.sum)
(or something like that) in the past, thinking it would change the contrasts, you were wrong. The only reason that this use of contrasts
did not throw a warning (for the use of an undefined global variable) is that there is a stats::contrasts
function that would be found.
It would be public-spirited to e-mail the maintainer (maintainer("gam")
) and let them know about this. Two possible fixes would be (1) remove the contrasts
argument from the model.matrix
call or (2) add a contrasts
argument to gam()
(default value NULL
) that will be passed through.
Upvotes: 1