2

I have run the linear mixed model using lme4 package. Then to see all pair of contrasts, I have to run the lsmeans function using lsmeans package. This is the function I run:

library('lme4')
library('lsmeans')
lsmeans(lmer1, pairwise ~ vowel * experience * lang_sound, adjust="tukey")

However I cannot see the whole output as there are too many pairs. Can anyone tell me what I should do to get the output from this function?

I have tried 'sink()' but it doesn't work. Maybe because there is no name of the lsmeans command I ran. I am using RStudio on Windows.

double-beep
  • 5,031
  • 17
  • 33
  • 41
user3288202
  • 313
  • 1
  • 4
  • 14

1 Answers1

2

The sink function does work, but you have to give a file name to save the output. For example

sink(file = "lsm-output.txt")
lsmeans(...)
sink()

The last sink() call reverts output back to the console.

That said, I don't think you need to see all those pairwise comparisons. I'd suggest doing the lsmeans and comparisons in separate calls. And you can do comparisons of one factor's levels conditionally on the other two by using pairs with a by argument:

library("lsmeans")
lmer1.lsm <- lsmeans(lmer1, ~ vowel * experience * lang_sound)
lmer1.lsm     # display the means
pairs(lmer1.lsm, by = c("experience", "lang_sound"))
pairs(lmer1.lsm, by = c("vowel", "lang_sound"))
pairs(lmer1.lsm, by = c("vowel", "experience"))

I also think you should visualize the results you have, e.g. by constructing an interaction plot:

lsmip(lmer1.lsm, experience ~ vowel | lang_sound)

some interchanging of the factors in this call may prove more satisfactory.

Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
  • Hi rvl, thank you for your advice. The pair commands work very well. I can now see the pair contrasts in a much easier way. (I should have known this a long time ago, shame me.) One question I'd like to ask: when I run: lmer1.lsm <- lsmeans(lmer1, ~ vowel * experience * lang_sound), I have got this message: Error in match(x, table, nomatch = 0L) : 'match' requires vector arguments In addition: Warning message: 'lsmeans' is deprecated. Use 'lsmeansLT' instead. See help("Deprecated") and help("lmerTest-deprecated"). What does this mean? – user3288202 Mar 30 '17 at 16:52
  • @user3288202 The message you report comes from the **lmerTest** package. You should use the **lsmeans** package. For a period of time, both packages had an `lsmeans` function, and **lmerTest** decided to rename theirs `lsmeansLT` to avoid confusion. But there is a transitional period where **lmerTest** still has its old `lsmeans` function, but issues a warning that it will disappear in the future. (PS - did you try `help("lmerTest-deprecated")`? It might have been helpful.) – Russ Lenth Mar 30 '17 at 18:13
  • Hmmm, I tried that help command and it didn't help. Note: to make sure you're using the right `lsmeans` function when **lmerTest** is loaded, use `lsmeans::lsmeans(...)` – Russ Lenth Mar 30 '17 at 18:19