本文介绍了glmmTMB上的计划的对比度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是重复的问题。许多人已经发布了寻找方法来对glmmTMB中的条件模型(固定因子)进行事后分析。我想在某些组之间进行计划内的对比,而不是测试每个成对的对比(例如Tukey)。但是,它在下面的代码上返回错误。

  modelparm.default(model,...)中的错误:$ b系数和协方差矩阵的$ b维数与

不匹配吗? glmmTMB?

  #filtdens是一个数据框,而TRT,DATE,BURN,VEG是
filtdens的因子<-合并%>%过滤器(!BLOCK%in%c( JB2, JB4, JB5)& MEAS == DENS&
group == TOT& = = N& VEG == C)
filtdens $ TD<-交互作用(filtdens $ TRT,filtdens $ DATE)
mod2<-glmmTMB(count〜(TD)+( 1 | BLOCK),
data = filtdens,
zi =〜1,
family = nbinom1(link = log))

k1 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))


解决方案

一个可复制的示例是有用,但是:开发版本中的提供应启用 multcomp :: linfct 的代码,即:

  glht_glmmTMB<-函数(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一起使用,但是我不明白为什么它不应该更普遍地工作... )

 库(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)安装(还需要安装编译工具)。


Apologies if this is a repeat question. Many have posted looking looking for a way to do post-hoc analyses on the conditional model (fixed factors) in glmmTMB. I want to do plannned contrasts between certain groups, not test every pairwise comparison (e.g. Tukey).

The code below worked well on nlme:lme for a lmm. However, it returns an error on the code below.

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

Is there a way to do planned contrasts on a 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"))
解决方案

A reproducible example would be helpful, but: this vignette in the development version offers code that ought to enable multcomp::linfct, i.e.:

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, ...)
}

Test (this example is with Tukey, but I don't see why it shouldn't work more generally ...)

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)

This works with the current CRAN version, but the current development version of glmmTMB offers more options (e.g. emmeans(); see the above-linked vignette). You'll need to install via devtools::install_github("glmmTMB/glmmTMB/glmmTMB") (you'll need compilation tools installed as well).

这篇关于glmmTMB上的计划的对比度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 04:21