gpt4 book ai didi

r - glmmTMB 上的计划对比

转载 作者:行者123 更新时间:2023-12-04 01:53:27 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

关于r - glmmTMB 上的计划对比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51886334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com