R stargazer,lme4和lmerTest不兼容 [英] R stargazer, lme4 and lmerTest incompatibility

查看:363
本文介绍了R stargazer,lme4和lmerTest不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R新手在这里.我在使用lmerTeststargazer时遇到问题.我正在按照此处的教程操作,以使stargazer与R中的lme4一起使用.

R novice here. I'm having issues working with lmerTest and stargazer. I was following the tutorial here to get stargazer to work with lme4 in R.

http://svmiller.com/blog/2015/02/quasi-automating-the-inclusion-of-random-effects-in-rs-stargazer-package/

我没有任何问题地运行了这个示例.

I ran this example with no issues.

library(lme4)
library(stargazer)
data(cake)
summary(M1 <- lmer(angle ~ temp + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE))
summary(M2 <- lmer(angle ~ factor(temperature) + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE))
anova(M1,M2)
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)")
)

虽然可行,但如果我包含lmerTest软件包,则stargazer不再有效.

While that works, if I include the lmerTest package, stargazer no longer works.

library(lme4)
library(lmerTest)
library(stargazer)
data(cake)
summary(M1 <- lmer(angle ~ temp + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE))
summary(M2 <- lmer(angle ~ factor(temperature) + (1 | replicate) + (1|recipe:replicate), cake, REML= FALSE))
anova(M1,M2)
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

我真的很想使用stargazer,但是我的实验要求使用merModLmerTest对象,而stargazer不支持.有人知道解决方法吗?将merModLmerTest对象转换为兼容的lmerMod对象有多困难?

I really would like to use stargazer but my experiments require the use of merModLmerTest objects, which stargazer doesn't support. Does someone know of a workaround? How difficult would it be to cast a merModLmerTest object into a lmerMod object that would be compatible?

推荐答案

这是一个简单的解决方法.将lmerTest(位于类merModLmerTest中)的输出转换为lmerMod类.这将与观星者兼容.

This is an easy fix. Convert the output of the lmerTest (which is in class merModLmerTest) to the lmerMod class. This will be compatible with stargazer.

class(model) <- "lmerMod"

这篇关于R stargazer,lme4和lmerTest不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆