0

List.

I have a generalized mixed model using lmer.test package and calling glmer. I can get a good model, however I can't get the output of the LSMEANS and Diff means.

Here's what I have

library(plyr)
library(lubridate)
library(chron)
library(reshape)
library(lattice)
library(car)
library(lmerTest)


fm17<-glmer(I(Steps+1)~Treatment + treatdate +Weight + BF+ (1|Block) +(0+treatdate|exp.unit), family=poisson)
summary(fm17,ddf="Kenward-Roger")
qqnorm(resid(fm17),main="QQ Model 17")
plot(fm17,main="Residual Model 17")
anova(fm17, ddf="Kenward-Roger")
lsmeans(fm17)
difflsmeans(fm17)

Everything runs fine until LSMEANS statement

Here's the output summary(fm17,ddf="Kenward-Roger") qqnorm(resid(fm17),main="QQ Model 17") plot(fm17,main="Residual Model 17") anova(fm17, ddf="Kenward-Roger") All the above work fine

lsmeans(fm17) Error in lsmeans(fm17) : The model is not linear mixed effects model difflsmeans(fm17) Error in difflsmeans(fm17) : The model is not linear mixed effects model

Any help on how to get that output back would be much appreciated.

Dan
  • 143
  • 4
  • 13

2 Answers2

3

The lsmeans package does support glmerMod objects, but it does not support Kenward-Rogers df for these models(nor does the pbkrtest package that these rely on). What factors do you want lsmeans of? You need to name them in the call. Do something like this

detach(lmerTest)
library(lsmeans)
lsmeans(fm17, "Treatment")
pairs(.Last.value)

The df show as NA in the results, indicating that asymptotic results ($z$ tests and CIs) are used.

Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
  • Using the code above, This is what I get > lsmeans(fm17,"Treatment") Error in eval(expr, envir, enclos) : object 'Treatment' not found Error in ref.grid(object = ) : Possible remedy: Supply the data used in the 'data' argument > pairs(.Last.Value) Error in pairs(.Last.Value) : object '.Last.Value' not found – Dan Mar 03 '15 at 16:29
  • It appears that it is unable to reconstruct the data for some reason, or that the predictor names differ from what you show in your posting. Try `ref.grid(fm17)` and see if you get anything. – Russ Lenth Mar 03 '15 at 17:14
  • I've revisited this, and this is what I get. It seems that getting lsmeans and diff means should be readily available to do. What are your recommendations for getting the output? > ref.grid(fm.s7) Error in model.frame.default(formula = datahourly ~ Treatment + BFStrata + : invalid type (list) for variable 'datahourly' Error in ref.grid(fm.s7) : Possible remedy: Supply the data used in the 'data' argument – Dan Jun 07 '15 at 12:28
  • I dunno, but you gave it a different model than your original question, so this is kind of a moving target. Your original model had `I(Steps+1)` as the response; this new one involves a variable `datahourly` which is apparently a `list`, so I don't see how it could be part of the model formula. – Russ Lenth Jun 07 '15 at 14:26
  • That's what's weird. The model hasn't changed. Datahourly is the dataset. I don't know why it's pulling that in. Ideas? – Dan Jun 07 '15 at 14:38
  • I don't think fm.s7 is the fitted model! Try fm17 like you had before – Russ Lenth Jun 07 '15 at 14:41
  • the model is basically the same. I did fix an error during data manipulation prior to the model. – Dan Jun 07 '15 at 14:44
  • I just don't know. If you can send a worksheet (or link thereof) with the data and model to me (see developer info for **lsmeans**) I can take a look. But it'll probably be a couple days as I'm traveling. – Russ Lenth Jun 07 '15 at 16:57
  • I woke up in the middle of the night with an insight... I wonder if you have a dollar sign in your model formula, e.g. `y ~ foo$x`. If so, this will not work because `lsmeans` uses the `all.vars` function to identify the variables in the model, and with the above formula, it would return `"y", "foo", "x"` rather than `"y", "foo$x"`. If you change the model so there are no dollar signs or subscripts in the model formula, you might find success. – Russ Lenth Jun 10 '15 at 17:26
2

lmerTest supports only linear mixed effects models (lmer objects). The anova method that you use comes actually from the lme4 package, and that is why you do not get an error - the model fm17 is of class glmerMod. In the lmerTest only anova for the lmer objects is re-specified. The lsmeans and difflsmeans functions that you use come from the lmerTest package and thereby give you an error saying that your model is not an lmer object.

alku
  • 56
  • 1