5

I am trying to reproduce a simplified version of the R output described in this posting. More generally, this is related to my attempt to use the stargazer() function to generate a LaTex table from an lmer object.

Following the author's posting, I've loaded the appropriate libraries and successfully created two lmer objects using the following code:

library(lme4)
library(stargazer)
data(cake)
M1 <- lmer(angle ~ temp + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE)
M2 <- lmer(angle ~ factor(temperature) + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE)

When I attempt the following code, it returns the error below:

stargazer(M1, M2, style="ajps", 
title="An Illustrative Model Using Cake Data", 
dep.var.labels.include = FALSE, 
covariate.labels=c( "Temperature (Continuous)", 
"Temperature (Factor $<$ 185)", 
 "Temperature (Factor $<$ 195)", 
"Temperature (Factor $<$ 205)", 
"Temperature (Factor $<$ 215)", 
"Temperature (Factor $<$ 225)"))
Error in objects[[i]]$zelig.call : $ operator not defined for this S4 class

I do not understand the source of this error, nor how to remedy it, and I would be greatly appreciative of any help.

I am using RStudio version 0.99.441 in Desktop Mode.

My R version info is as follow:

platform       x86_64-apple-darwin13.4.0   
arch           x86_64                      
os             darwin13.4.0                
system         x86_64, darwin13.4.0        
status                                     
major          3                           
minor          2.0                         
year           2015                        
month          04                          
day            16                          
svn rev        68180                       
language       R                           
version.string R version 3.2.0 (2015-04-16)
nickname       Full of Ingredients     

My version of the stargazer package is 5.1, and my version of lme4 is 1.1-7

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Steve'sConnect
  • 145
  • 2
  • 8
  • It worked for me. Try reloading the R session, maybe there are some overlapping with other objects or data. – m0nhawk Jun 04 '15 at 17:14
  • Zelig is a package in the tradition Fox's 'Rcmdr' and 'Deducer' and 'rattle' and my favorite 'rms' (and apologies to Max Kuhn for another famous one that I'm failing to remember) of packages wrapping a unified set of helper functions around ordinary regression functions. You would need to present `sessionInfo()` for us to be sure, but I'm guessing it needed to be loaded for some bit of code to succeed. (It also worked for me in R v 3.1.2 on a Mac running Lion.) – IRTFM Jun 04 '15 at 17:15
  • Or maybe pkg::Zelig was loaded and (should not be) and masked a function that woudn't normally "go there". If so try restarting without Zelig. – IRTFM Jun 04 '15 at 18:28
  • 3
    Thanks for the all the feedback. @mOnhawk, apparently, I had failed to detach the `lmerTest` library before testing the script-- and it looks like there's something about that package that doesn't play nicely with `stargazer`; meanwhile, restarting R (as you suggested) and loading only the packages `lme4` and `stargazer` solved this problem. Thanks! @BondedDust, excellent tip about the `sessionInfo()`... I'll keep in mind for future postings. – Steve'sConnect Jun 05 '15 at 16:17
  • Why is `lmerTest` conflicting with `stargazer`? – Lumos Mar 18 '18 at 05:19

1 Answers1

3

You may add the following codes before you run stargazer.

class(M1) <- "lmerMod"
class(M2) <- "lmerMod"
Hao
  • 59
  • 6