使用 Owls 数据和glmmTMB
包,我想直观地比较来自不同零膨胀模型的回归系数,这些模型在使用的系列(ZIPOISS、ZINB1、ZINB2)和有/无偏移量(logBroodSize)中有所不同。
然而,我的第一个问题是获得系数。包中的tidy
函数broom
应该为您提供系数,以便稍后用 绘制它们ggplot
,但是当我尝试获取它们时出现以下错误:
modList= list(zipoiss, zinb1, zinb2, zinb1_bs, zinb2_bs)
coefs= ldply(modList,tidy,effect="fixed",conf.int=TRUE,
.id="model") %>%
mutate(term=abbfun(term)) %>%
select(model,term,estimate,conf.low,conf.high) %>%
filter(!term %in% c("Intercept","Intercept.1","NCalls","zi_NCalls"))
Error in as.data.frame.default(x) :
cannot coerce class ""glmmTMB"" to a data.frame
Also: Warning message:
In tidy.default(X[[i]], ...) :
No method for tidying an S3 object of class glmmTMB , using as.data.frame
知道可能出了什么问题吗?我已经被告知没有正确的版本broom
可能是原因,但是我已经安装了正确的版本......接下来提供了一个可重现示例的代码:
# Packages and dataset
library(glmmTMB)
library(broom) # devtools::install_github("bbolker/broom")
library(plyr)
library(dplyr)
data(Owls,package="glmmTMB")
Owls = plyr::rename(Owls, c(SiblingNegotiation="NCalls"))
Owls = transform(Owls,
ArrivalTime=scale(ArrivalTime, center=TRUE, scale=FALSE),
obs=factor(seq(nrow(Owls))))
# Models
zipoiss<-glmmTMB(NCalls~(FoodTreatment+ArrivalTime)*SexParent+
offset(logBroodSize)+(1|Nest),
data=Owls,
ziformula = ~ 1,
family="poisson")
zinb2<- glmmTMB(NCalls~(FoodTreatment+ArrivalTime)*SexParent+
offset(logBroodSize)+(1|Nest),
data=Owls,
ziformula = ~ 1,
family="nbinom2")
zinb1 <- glmmTMB(NCalls~(FoodTreatment+ArrivalTime)*SexParent+
offset(logBroodSize)+(1|Nest),
data=Owls,
ziformula = ~ 1,
family="nbinom1")
zinb1_bs<- glmmTMB(NCalls~(FoodTreatment+ArrivalTime)*SexParent+
BroodSize+(1|Nest),
data=Owls,
ziformula = ~ 1,
family="nbinom1")
zinb2_bs<- glmmTMB(NCalls~(FoodTreatment+ArrivalTime)*SexParent+
BroodSize+(1|Nest),
data=Owls,
ziformula = ~ 1,family="nbinom2")
# Get coefficients ("coefs" does not work yet...)
modList = list(zipoiss, zinb1, zinb2, zinb1_bs, zinb2_bs)
coefs = ldply(modList,tidy,effect="fixed",conf.int=TRUE,
.id="model") %>%
mutate(term=abbfun(term)) %>%
select(model,term,estimate,conf.low,conf.high) %>%
filter(!term %in% c("Intercept","Intercept.1","NCalls","zi_NCalls"))