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

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

问题描述

这里是R新手.我在使用 lmerTeststargazer 时遇到问题.我按照这里的教程让 stargazer 在 R.

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天全站免登陆