2

I am using lmer from the lme4 package and lmerTest. My regression looks as follows:

r1 <- lmer(a ~ b + c + as.factor(d) + (1 | e), data = df)

I would like to use stargazer and used this code:

stargazer(r1, type = "text")

However, it doesn't work. R returns this error:

Error in objects[[i]]$zelig.call : $ operator not defined for this S4 class

Actually I don't know what the problem is, I already checked if there are packages which are incompatible with each other but that does not seem to be the case. Does anyone have an idea what the problem might be or if there is an alternative to stargazer when using lmer?

Sean Burgess
  • 67
  • 1
  • 5

1 Answers1

3

This is a compatibility issue between lmerTest and stargazer. If lmerTest is loaded into R along with lme4, then it changes the class of the model objects from "lmerMod" to "lmerModLmerTest". Only the former is compatible with stargazer.

The simplest fix is to avoid loading lmerTest in the first place, which worked for me.

The real fix (from R stargazer, lme4 and lmerTest incompatibility) is to change the class of your model object back to the compatible one:

class(r1) <- "lmerMod"