Search code examples
rlmposthoc

Posthoc analysis in lmm: unexecuted


I am trying to solve the error:

Error in if ((misc$estType == "pairs") && (paste(c("", by), collapse = ",") != : missing value where TRUE/FALSE needed

My code:

model1 <- lmer (Y ~ X1 * X2 + (1|"FACTOR of 13 levels"), data=data, REML = FALSE)

library (emmeans)

post_hoc <- emmeans (model1, ~ X1*X2)

pairs (post_hoc, adjust="tukey")

But it returns the above error. I've tried to change the code, but I haven't succeeded. Can someone help me solve it, please?


Solution

  • I think I know what is going on. I believe that X1 and X2 are both numeric predictors. Therefore, your post_hoc lists just one case -- the one where X1 and X2 are each at their mean value. Try this:

    post_hoc
    

    (Just type the name of the object and hit return. This will display it.)

    I would bet money that there is just one case listed, but betting on this site is probably frowned upon. You can't compare one thing, and that's why you get an error.

    If those predictors are really supposed to be factors, you need to fit a model that recognizes them as such, e.g.,

    model2 <- lmer(factor(X1) * factor(X2) + (1|subject), 
                   data = data, REML = TRUE)
    

    Your model1 is almost surely useless, because it fits the equation of a hyperbolic surface in two numeric variables.

    I'll see if I can get contrast() and pairs() to display a more informative error message.