在lme4中进行混合效应logistic回归的glmulti语法

3
我正在尝试比较包含数据集中所有变量的各种混合效应 logistic(或某些结果 gamma)模型的 AIC(或 AICc)值。这是我的数据集的简化版本,可以从此处下载:https://drive.google.com/file/d/1YO17J7Dx1cFD0Wf3fNGe-a37ccTKyWNp/view?usp=sharing。然而,我对 glmulti 还不熟悉,只使用了大约一个月的 lme4,所以我认为我做错了什么:
我按以下方式设置了包含所有变量的初始模型:
data_reprex <- read_csv("reprex_glmulti_data.csv")


data_reprex <- within(data_reprex, {
  Dog <- factor(Dog) 
  Box <-factor(Box)
  Sex <- factor(Sex)
  Group <- factor(Group)
  Breedtype <- factor(Breedtype)
  OwnerSeverity <- factor(OwnerSeverity, levels = c("None", "Mild", "Moderate", "Severe"))
})


outcome_model <- glmer(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
                         Group + Group*Interval + Group*Box + Group*Trial + Group*Age + Group*Sex + Group*Breedtype 
                       + (1 | Dog), data = data_reprex, family = binomial, nAGQ=100)

这个模型正常运行(除了一些我已经调查过的警告)。然而,我想要对这些变量的每种组合运行glmulti,以确定最佳模型,并尝试了几种不同形式的语法,基于我在网上找到的各种示例,但是这些都没有成功(我还尝试了更改标准和“confsetsize”设置):

attempt1 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
         Group + (1 | Dog), data=data_reprex,
       level=1, fitfunction=glmer, family= binomial, crit="aicc", confsetsize=150)

attempt2 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
                      Group + (1 | Dog), data=data_reprex,
                    level=1, fitfunction=glmer, crit="aicc", confsetsize=150)


attempt3 <- glmulti(outcome_model, level=2, fitfunction=glmer, crit=AICc)

attempt4 <- glmulti(outcome_model, level=2, crit=AICc)

错误信息包括:
Improper call of glmulti.

Error in .subset2(x, i, exact = exact) : 
  attempt to select less than one element in get1index

我有时会收到警告信息,例如:
 In Ops.factor(Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity,  :
  ‘+’ not meaningful for factors

In Ops.factor(Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +  : ‘|’ not meaningful for factors

我假设这是一个语法问题,我需要修改代码结构,因为我正在使用逻辑glmer而不是像我在网上找到的大多数示例一样的glm,并且从文档中我相信glmulti应该与lme4模型兼容。请问有人能指导我如何构建以使其运行?(此外,是否有一种相对简单的方法只包括与变量“Group”的交互作用,而不包括所有其他变量?)
编辑:作为最后一次尝试,我还尝试了在这里提供的建议(尽管我认为我可能有点困惑):glmulti和线性混合模型使用以下代码,但这也不起作用:
glmer2.glmulti <- setMethod('getfit', 'merMod', function(object, ...) {
  summ=summary(object)$coef
  summ1=summ[,1:2]
  if (length(dimnames(summ)[[1]])==1) {
    summ1=matrix(summ1, nr=1, dimnames=list(c("(Intercept)"),c("Estimate","Std. Error")))
  }
  cbind(summ1, df=rep(10000,length(fixef(object))))
})

attempt5 <- glmulti(SuccessBinary ~ Interval + Box + Trial + Age + Sex + Breedtype + OwnerSeverity +
                      Group + (1 | Dog), data=data_reprex,
                    level=1, fitfunction=glmer2.glmulti, family=binomial, crit="aicc", confsetsize=150)

谢谢您的提前帮助!


你找到解决方案了吗?我也遇到了同样的问题。 - Emily
抱歉,我刚提交了我的论文,并提到该软件包作为比较AIC的潜在方式,但是所有尝试将其用于此类模型的努力都失败了。 - Mel
感谢您的回复,恭喜您完成了!我发布了自己的问题,并被告知glmuli已经过时了,鼓励我寻找另一种方法。 - Emily
2个回答

1

我自己也感到困惑,并尝试将glmulti应用于使用glmmTMB拟合的混合效应模型,得到了与您类似的错误消息。我没有成功地使其与glmulti一起工作,但似乎MuMIn包中的dredge函数here对我有效。也许您可以尝试这个?(如果您还没有找到解决方案)。


0

我遇到了同样的问题,并在这里找到了解决方案

请注意,glmer.glmulti包装函数中包含了已弃用的REML参数。

编辑:提问者询问了与glmulti兼容的lme4::glmer的语法。我在这里写下了对我有效的内容,以便审核员可以批准答案。但基本上我只是复制粘贴了引用来源上的内容。

# wrapper function for argument fitfunction in glmulti()
glmer.glmulti <- function(formula, data, random = "", ...){
  glmer(paste(deparse(formula),random),
        data    = data, 
        # REML = F, # argument deprecated in newer version of lme4
        ...)
}

res1 <- glmulti(
  y = outcome_variable ~ predictor1 + predictor2,
  random  = "+(1|cluster_variable)",
  crit    = aicc,
  data    = data,
  family  = binomial,
  method  = "h",
  fitfunction = glmer.glmulti,
  marginality = F,
  level   = 1)

1
虽然这个链接可能回答了问题,但最好在这里包含答案的关键部分,并提供链接作为参考。仅有链接的答案可能会因为链接页面的更改而失效。- 来自审核 - undefined
1
@MicheleLaFerla 我写下了明确的答案。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接