I'm getting the following error, despite the fact that all my fixed
effects were converted to factors and had their contrast attributes
set prior to calling glmer.
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Calls: glmer ... model.matrix -> model.matrix.default -> contrasts<-
Here is the model specification:
glmer(press ~ truth*adj*idn*num + (1|subj), data=wl,
family=binomial(link="probit"))
Here are the predictors. As you can see, they are all already factors
and have contrasts set, so I can't figure out why glmer is trying to
set contrasts anyway, much less why it thinks any of these have fewer
than two levels:
R> head(wl$truth)
[1] neither neither neither neither neither neither
attr(,"contrasts")
target foil
neither 0 0
target 1 0
foil 0 1
Levels: neither target foil
R> head(wl$adj)
[1] TRUE TRUE TRUE TRUE TRUE TRUE
attr(,"contrasts")
TRUE
TRUE 1
FALSE -1
Levels: TRUE FALSE
R> head(wl$idn)
[1] FALSE FALSE FALSE FALSE FALSE FALSE
attr(,"contrasts")
TRUE
TRUE 1
FALSE -1
Levels: TRUE FALSE
R> head(wl$num)
[1] six six six six six six
attr(,"contrasts")
three
three 1
six -1
Levels: three six
Here is the session info:
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lme4_1.1-7 Rcpp_0.11.2 Matrix_1.1-4
loaded via a namespace (and not attached):
[1] grid_3.1.1 lattice_0.20-29 MASS_7.3-34 minqa_1.2.3
nlme_3.1-117 nloptr_1.0.4 splines_3.1.1 tools_3.1.1
Can anybody shed some light on what is going on here, and / or how to
work around it? I've run similar models with very similar data on
slightly older versions of lme4 (but still >1.0) and never run into
this, so I'm wondering if a bug was introduced in the latest version.
-- dan
Daniel McCloy
http://dan.mccloy.info/
Postdoctoral Research Fellow
Institute for Learning and Brain Sciences
University of Washington