Home forums Mixed Models Post-Hoc Test with lsmeans error with uncorrelated random effects

Viewing 1 reply thread
  • Author
    Posts
    • #213
      René Sch.
      Participant

      Dear Henrik,

      I have a simple model, a categorical predictor with 3 levels and find a sign. effect, and now want to test, where this effect comes from by using lsmeans::pairs (or ::contrast) post-hoc tests (same happens with the “emmeans” package).

      But when I run a mixed model (any dataset) with uncorrelated random intercepts and slopes, e.g.
      mod1<-mixed(y~x+(1+x||subjects), method=”LRT”, data=data, expand_re=TRUE)

      and afterwards do
      lsm.options(lmer.df = “Satterthwaite”)
      lsmeans(mod1, ~ x, data=mod1$data)

      I get the following error:
      Error in eval(predvars, data, env) : Object ‘re1.x1’ not found

      Can you please give me a hint, or is there an alternative? I need this post – hoc test desperately 🙂

      Best, René

      • This topic was modified 6 years, 4 months ago by René Sch..
    • #217
      henrik
      Keymaster

      One surprising solution (surprising in the sense that I only know about it for a few days) is to set set_data_arg = FALSE. In the current CRAN version (but not in the current development and next CRAN version), this throws quite a few errors which can be safely ignored.

      library("afex")
      data("Machines", package = "MEMSS") 
      m1 <- mixed(score ~ Machine + (Machine||Worker), data=Machines, 
                  expand_re = TRUE, set_data_arg = FALSE)
      emm_options(lmer.df = "Satterthwaite")
      emmeans(m1, "Machine")
      #  Machine   emmean       SE    df lower.CL upper.CL
      #  A       52.35556 2.397324  7.35 46.74094 57.97017
      #  B       60.32222 2.633283  9.04 54.36898 66.27546
      #  C       66.27222 2.836796 11.56 60.06544 72.47901
      # 
      # Degrees-of-freedom method: satterthwaite 
      # Confidence level used: 0.95 

      Alternatively, a different method for calculating the df can also be chosen:

      m2 <- mixed(score ~ Machine + (Machine||Worker), data=Machines, expand_re = TRUE)
      emm_options(lmer.df = "Satterthwaite")
      emmeans(m2, "Machine")
      # Error in eval(predvars, data, env) : object 're1.Machine1' not found
      
      emm_options(lmer.df = "asymptotic")
      emmeans(m2, "Machine")
      #  Machine   emmean       SE  df asymp.LCL asymp.UCL
      #  A       52.35556 2.397324 Inf  47.65689  57.05422
      #  B       60.32222 2.633283 Inf  55.16108  65.48336
      #  C       66.27222 2.836796 Inf  60.71220  71.83224
      # 
      # Degrees-of-freedom method: asymptotic 
      # Confidence level used: 0.95 
      
      emm_options(lmer.df = "kenward-roger")
      emmeans(m2, "Machine")
      #  Machine   emmean       SE    df lower.CL upper.CL
      #  A       52.35556 2.397324  7.35 46.74087 57.97024
      #  B       60.32222 2.633283  9.04 54.36897 66.27548
      #  C       66.27222 2.836796 11.60 60.06746 72.47698
      # 
      # Degrees-of-freedom method: kenward-roger 
      # Confidence level used: 0.95 
      

      I am currently deliberating whether to use set_data_arg = FALSE as the new default.

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