Home forums Mixed Models Visualizing Random Effects

Viewing 1 reply thread
  • Author
    Posts
    • #245
      Aaron Gardony
      Participant

      Using lme4 models I was able to plot random effects of using the command:

      dotplot(ranef(lme4_model, postVar=TRUE))

      When I try to use this command with the mixed model produced by afex I get the following error:

      Error in UseMethod (“ranef”) :
      no applicable method for ‘ranef’ applied to an object of class “mixed”

      Do you have any guidance for how to visualize random effect with afex? Any advice would be appreciated!

    • #246
      henrik
      Keymaster

      The problem is that afex::mixed returns an object, of class "mixed", where the original lme4 object is in slot full_model:

      library("afex")
      data("Machines", package = "MEMSS") 
      m1 <- mixed(score ~ Machine + (Machine|Worker), data=Machines)
      
      str(m1, 1)
      # List of 5
      #  $ anova_table      :Classes ‘anova’ and 'data.frame':	1 obs. of  4 variables:
      #   ..- attr(*, "heading")= chr [1:3] "Mixed Model Anova Table (Type 3 tests, KR-method)\n" "Model: score ~ Machine + (Machine | Worker)" "Data: Machines"
      #   ..- attr(*, "sig_symbols")= chr [1:4] " +" " *" " **" " ***"
      #  $ full_model       :Formal class 'merModLmerTest' [package "lmerTest"] with 13 slots
      #  $ restricted_models: NULL
      #  $ tests            : NULL
      #  $ data             :'data.frame':	54 obs. of  3 variables:
      #  - attr(*, "class")= chr "mixed"
      #  - attr(*, "type")= num 3
      #  - attr(*, "method")= chr "KR"

      So one just needs to pass this slot to the corresponding function and not the whole object. This works for example via $:

      library("lattice")
      dotplot(ranef(m1$full_model, condV=TRUE))

      Hope that helps!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.