R新手在这里。我在使用lmerTest
和stargazer
时遇到问题。我正在按照本教程进行操作,以使stargazer
与R中的lme4
一起使用。
http://svmiller.com/blog/2015/02/quasi-automating-the-inclusion-of-random-effects-in-rs-stargazer-package/
我运行此示例没有任何问题。
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
将不再起作用。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
对象有多困难? 最佳答案
这是一个简单的修复。将lmerTest
(位于类merModLmerTest
中)的输出转换为lmerMod
类。这将与观星者兼容。
class(model) <- "lmerMod"