Home forums Mixed Models plotting models created by lmer_alt functions

Viewing 1 reply thread
  • Author
    • #180
      Jarkko Hautala

      I’m trying to plot the results of my mixed model, e.g.:

      emmip(model, a~b|c, CIs = TRUE)
      a=dichotomous within-subject fixed factor
      b=numeric, continuous between-subject fixed factor
      c=dichotomous between-subject fixed factor

      The problem is that resulting plot has only one value on x-axis, the mean of b.
      Also I noticed that several handy plotting packages such as visreg or effects do not work on models constructed by afex.

      WHat might be happening here?

    • #181

      emmip() is not part of afex, but part of the emmeans package. So I am not the one that can provide adequate support. I am also not sure what it is supposed to do in this case or if it even supports numerical covariates on the x-axis.

      In general, lmer_alt returns the same object as lmer or glmer. In the default setting it returns objects of class merModLmerTest for lmer objects. If you prefer the ‘true’ merMod objects returned from lme4 in this case you can change this via:
      afex_options(lmer_function = "lme4") (but note that then method = "KR" and "S" stop working).

      mixed returns objects of class mixed, for which the slot full_model contains the same model oject as lmer_alt.

      Thus, objects returned from lmer_alt (or the full_model slot of mixed objects) should in principle work with all functions which work with merMod objects. For example for effects:

      data("Machines", package = "MEMSS") # some example data
      m1 <- mixed(score ~ Machine + (Machine  || Worker), data=Machines, expand_re = TRUE)
      # when using effects with mixed we need to set contr.sum globally:
      plot(Effect("Machine", m1$full_model))
      # equal to:
      emmeans(m1, "Machine")
      ## compare again (now gives wrong results):
      plot(Effect("Machine", m1$full_model))

      In principle this should also work for objects returned from lmer_alt. However it does not right now, because it does not set the data argument correctly (I will correct this in the next version and on github). For now the following works:

      m2 <- lmer_alt(score ~ Machine + (Machine  || Worker), data=Machines)
      m2@call[["data"]] <- as.name("Machines")
      plot(Effect("Machine", m2))
Viewing 1 reply thread
  • You must be logged in to reply to this topic.