我正在尝试比较包含我的数据集中所有变量的各种混合效应逻辑(或某些结果 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 的模型。请有人建议我如何构建它以使其运行?(此外,是否有一种相对简单的方法来仅包含与变量“组”而不是与所有其他变量的交互?)
编辑:作为最后的尝试,我也尝试使用此处提供的建议(尽管我认为我可能有些困惑):glmulti and liner mixed models to use the following code,但这也不起作用:
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)
提前致谢!