[R-sig-ME] post-hoc tests of lmerTest models using lsmeans

Lenth, Russell V russell-lenth at uiowa.edu
Thu Nov 30 17:29:00 CET 2017


One issue is that it appears you are confusing two packages that both have an 'lsmeans' function. May I suggest using 'lsmeans::lsmeans(...)' to make sure you have the right one? Or avoid the issue altogether by downloading the emmeans (estimated marginal means) package and using the 'emmeans' function (exact same syntax as lsmeans::lsmeans).

The other issue is that you hand-coded the factors rather than letting 'lmer' do it for you. Since no factors were found, that's why you got empty output from 'lmerTest::lsmeans'. There is a way to do it with the model you already fitted, but it's simpler to refit it:

    library("lme4")
    library("emmeans")
    Shift.lm <- lmer(Shift ~ factor(Movement) * factor(Finger) + (1|subject), data = data)
    emmeans(Shift.lm, pairwise ~ Movement | Finger)

Notes: (1) 'adjust = "tukey"' is unneeded because it is already the default. (2) You said you wanted to compare the levels of 'Movement' for each 'Finger', so I changed the specs so that's what you get (it sets 'Finger' as a "by" variable). See the documentation for 'emmeans' and the package vignettes, especially the one on interactions.

Russ

Russell V. Lenth  -  Professor Emeritus
Department of Statistics and Actuarial Science   
The University of Iowa  -  Iowa City, IA 52242  USA   
Voice (319)335-0712 (Dept. office)  -  FAX (319)335-3017



Message: 1
Date: Wed, 29 Nov 2017 21:32:28 +0000
From: Yuqi Liu <yliu at psych.udel.edu>
To: "r-sig-mixed-models at r-project.org"
	<r-sig-mixed-models at r-project.org>
Subject: [R-sig-ME] post-hoc tests of lmerTest models using lsmeans
Message-ID: <db4868f6d7f942669b4f8dfa22b74621 at Mercury.psych.udel.edu>
Content-Type: text/plain; charset="UTF-8"

Dear R experts,

  I have a question on testing simple effects after finding out significant interaction using lmerTest. My data has two within-subjects fixed factors: Movement (synchronous or asynchronous), and Finger (one finger, or four fingers). The two levels of Movement factor were dummy-coded as 0.5 and -0.5, so were the two levels of Finger factor. The DV is called Shift. My model looks like this:

  Shift.lm <- lmer(Shift~Movement*Finger+(1|subject), data=data)

  There was a significant interaction of Movement and Finger, so I wanted to test simple effects by comparing synchronous and asynchronous movements at each level of Finger. I was planning to use lsmeans to do this, but I got two questions. First, when I just typed > lsmeans(Shift.lm) to look at descriptive info in each condition, R output nothing other than the headers:

  > lsmeans(Shift.lm)
Least Squares Means table:
     Estimate Standard Error DF t-value Lower CI Upper CI p-value

  In addition, I typed the command below to test simple effects, but getting this error message:

> lsmeans(Shift.lm, pairwise~Finger * Movement ,adjust="tukey")
Error in match(x, table, nomatch = 0L) :
  'match' requires vector arguments

  I don't know what I am missing here, I also don't know if lsmeans is the best way to do it. Could anyone give any suggestions?

Thank you for your help,
Yuqi



More information about the R-sig-mixed-models mailing list