kat
kat

Reputation: 125

allEffects() on GLMM gives an error message

I get the following error messgae in R when I try to use allEffects() from the effects-package on a GLMM (mpc7j) created with glmer() from lme4:

> mpc7j<- glmer(correct_response ~ pc * Stim.cond + sess:pc + sess:Stim.cond +
                (1|item.no) + (1|id), data=d7nowl, family=binomial)

> allEffects(mpc7j)
Error in eval(expr, envir, enclos) : Object 'sess' not found

When I use allEffects() on a different model ("dummy") on the same data without a term including "sess" in the fixed effects, it works just fine.

> dummy<- glmer(correct_response ~ pc * Stim.cond + (1|item.no) + (1|id),
                data=d7nowl, family=binomial)

I used str(mpc7j) to check my model and it looks like "sess" is in there as factor in the group of contrast treatments.

.. .. ..$ pc       : chr "contr.treatment"
.. .. ..$ Stim.cond: chr "contr.treatment"
.. .. ..$ sess     : chr "contr.treatment"

"sess" is a factor with 2 levels and refers to the time of testing (repeated measures, session1 and session2). One of the subjects I tested was tested only once, not twice like all the other subjects. Could that have anything to do with the error?

I would appreciate any pointers as to what I am doing wrong here or where I should look for a solution. I already googled the error message without success. The R documentation on the allEffects() function did not help me either. Help, please?

EDIT: When I try to use plotLMER.fnc() from languageR, I get this error:

> plotmpc7j<-plotLMER.fnc(mpc7j)
log odds are back-transformed to probabilities
Fehler: Indizierung außerhalb der Grenzen

The last line translates to something like "error: Indices outside bounds".

Upvotes: 2

Views: 1832

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226087

Even though this is incomplete, I'm posting it as an answer rather than as a comment because it's long and contains a lot of code ... (I can go back and delete it later ...

The bottom line, so far, is that this is not a glmer/GLMM-specific problem, but a problem with a model that includes interaction terms (in this case sess:pc and sess:Stim.cond) without the main effects (sess) (in general such models are odd and often, but not always, wrong ... which may be why they're not handled by the effects package). I would consider contacting the package maintainers (maintainer("effects")) ...

Create a dummy data set with the correct structure:

d7nowl <- expand.grid(pc=factor(LETTERS[1:2]),
                      Stim.cond=factor(letters[1:2]),
                      sess=factor(1:2),
                      item.no=factor(1:10),id=factor(1:10))
d7nowl$correct_response <- rbinom(nrow(d7nowl),size=1,prob=0.5)

Fit the GLMM:

g1 <- glmer(correct_response ~ pc * Stim.cond + sess:pc + sess:Stim.cond +
            (1|item.no) + (1|id), data=d7nowl, family=binomial)

## reproduce error
try(allEffects(g1)) 
## Error in eval(expr, envir, enclos) : object 'sess' not found

Now try a similar model with a GLM.

g2 <- glm(correct_response ~ pc * Stim.cond + sess:pc + sess:Stim.cond,
            data=d7nowl, family=binomial)    
try(allEffects(g2)) ## same error

allEffects gives us an answer (I haven't checked to see if it makes sense) if we either add the main effect of sess or (as pointed out in the original question) take out the interactions with sess.

g3 <- update(g2,.~.+sess)
try(allEffects(g3)) ## OK

g4 <- update(g2,.~.-sess:pc-sess:Stim.cond)
try(allEffects(g4)) ## OK

If I try to simplify still further allEffects still breaks, but with a different error message:

g5 <- glm(correct_response ~ pc + sess:pc, data=d7nowl, family=binomial)
try(allEffects(g5))
## Error in mod.matrix[, components] : subscript out of bounds

Understanding exactly what's going wrong will require digging into the guts of effects:::analyze.model (an internal utility function) to see where the logic goes wrong.

Upvotes: 1

Related Questions