【问题标题】:Planned Contrasts on glmmTMBglmmTMB 上的计划对比度
【发布时间】:2018-08-16 22:54:40
【问题描述】:

抱歉,如果这是一个重复的问题。许多人发布了寻找一种方法来对 glmmTMB 中的条件模型(固定因子)进行事后分析。我想在某些组之间进行有计划的对比,而不是测试每个成对比较(例如 Tukey)。

下面的代码在 nlme:lme 上运行良好。但是,它会在下面的代码中返回错误。

Error in modelparm.default(model, ...) : 
  dimensions of coefficients and covariance matrix don't match

有没有办法在 glmmTMB 上进行计划对比?

#filtdens is a dataframe and TRT,DATE,BURN,VEG are factors
filtdens <- merged %>% filter(!BLOCK %in% c("JB2","JB4","JB5") & MEAS =="DENS" & 
                      group == "TOT" & BURN == "N" & VEG == "C")
filtdens$TD <- interaction(filtdens$TRT, filtdens$DATE)
mod2 <- glmmTMB(count~(TD)+(1|BLOCK),
                 data=filtdens,
        zi=~1,
        family=nbinom1(link = "log"))

k1 <- matrix(c(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,

       0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0,

       0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0,

       0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1), byrow = T, ncol = 12)

summary(glht(mod2, linfct=k1),test=adjusted("bonferroni"))

【问题讨论】:

    标签: r comparison mixed-models


    【解决方案1】:

    一个可重现的示例会有所帮助,但是:开发版本中的this vignette 提供了应该启用multcomp::linfct 的代码,即:

    glht_glmmTMB <- function (model, ..., component="cond") {
        glht(model, ...,
             coef. = function(x) fixef(x)[[component]],
             vcov. = function(x) vcov(x)[[component]],
             df = NULL)
    }
    modelparm.glmmTMB <- function (model, 
                                   coef. = function(x) fixef(x)[[component]],
                                   vcov. = function(x) vcov(x)[[component]],
                                   df = NULL, component="cond", ...) {
        multcomp:::modelparm.default(model, coef. = coef., vcov. = vcov.,
                            df = df, ...)
    }
    

    测试(这个例子是 Tukey,但我不明白为什么它不应该更普遍地工作......)

    library(glmmTMB)
    data("cbpp",package="lme4")
    cbpp_b1 <- glmmTMB(incidence/size~period+(1|herd),
                   weights=size,family=binomial,
                   data=cbpp)
    g1 <- glht(cbpp_b1, linfct = mcp(period = "Tukey"))
    summary(g1)
    

    这适用于当前的 CRAN 版本,但 glmmTMB 的当前 开发 版本提供了更多选项(例如 emmeans();参见上面链接的小插图)。您需要通过devtools::install_github("glmmTMB/glmmTMB/glmmTMB") 安装(您还需要安装编译工具)。

    【讨论】:

    • 感谢 Ben,感谢您完成这项工作以及您所做的所有其他工作。
    • 对于那些在 R3.5.1 之间的兼容性问题之间存在兼容性问题的人。和 Rtools3.5 运行 devtools 时,这解决了问题:community.rstudio.com/t/rtools-not-recognized-r3-5-1-rtools-3-5/…
    • 使用glht 我得到错误Error in glht.matrix(fitUSA, linfct = B) : ‘ncol(linfct)’ is not equal to ‘length(coef(model))’glht_glmmTMB 我得到错误` glht.matrix(model, ..., coef. = function(x) fixef( x)[[component]], : 'ncol(linfct)' is not equal to 'length(coef(model))' . I have tried with linfct = B, where B is a matrix (like k1` above) 有这么多行作为固定效应估计模型和 1 列或 2 列,但两个选项都会产生相同的错误。
    • 我不得不尝试这种方式,因为我不想对比 2 个类别的相同因子,而是两个不同的变量
    • @iago,您能否发布一个可重现的示例作为新问题?
    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 2023-02-08
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    相关资源
    最近更新 更多