routputlsmeans

How to see all output from Ismeans?


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.


Solution

  • 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.