lme4中混合效应逻辑回归的glmulti语法

问题描述 投票:3回答:1

我试图比较包含我的数据集中所有变量的各种混合效果逻辑(或某些结果伽玛)模型的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 and liner mixed models使用以下代码,但这也不起作用:

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)

提前致谢!

r lme4 mixed-models glmulti
1个回答
0
投票

我自己也感到困惑,并尝试将glmulti应用于配备glmmTMB的混合效果模型,并获得了与您相同的错误消息。我没有设法使它与glmulti一起工作,但似乎MuMIn包here的功能挖掘对我有用。也许你可以试试这个? (如果您还没有找到解决方案)。

© www.soinside.com 2019 - 2024. All rights reserved.