1

使用 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")) 
4

1 回答 1

0

这现在(截至今天)适用于新的/正在开发的broom.mixed包,例如

devtools::install_github("bbolker/broom.mixed")

希望这会很快出现在 CRAN 上,但这对我来说只是中等优先级,我不想在至少 90% 完成之前将它发布到 CRAN。欢迎请求请求!

最后一步改变了一点(一方面,我似乎没有abbfun):

modList = lme4:::namedList(zipoiss, zinb1, zinb2, zinb1_bs, zinb2_bs)
coefs = ldply(modList,tidy,effect="fixed",conf.int=TRUE,
              .id="model") %>%
  select(model,term,component,estimate,conf.low,conf.high) %>%
  filter(!term %in% c("(Intercept)","NCalls"))

警告:这些glmmTMB模型工具的开发是相当新的/实验性的;您应该 (1) 仔细检查您的结果,并 (2)如果某些事情没有按预期工作,请报告问题。

于 2018-03-25T23:51:58.663 回答