2

我正在尝试dredge将 R 包MuMIn与全局二项式glmer模型一起使用。我发现我需要control = glmerControl(optimizer="bobyqa")为收敛指定优化器。但是,当我去使用时dredge,我得到一个错误。如果我减少模型中预测变量的数量,我可以删除bobyqa规范,获得收敛,并使用疏通。我有什么办法可以dredgeglmerControl(optimizer="bobyqa")吗?

test.glob=glmer(exploitpark~X + as.factor(Y) + Z + A + B + (1|ID), 
                family=binomial(), 
                glmerControl(optimizer="bobyqa"), data=df)
options(na.action = "na.fail")   #  prevent fitting models to different datasets
test.Set = dredge(test.glob, beta=c("partial.sd"), extra = c("R^2"))

Fixed term is "(Intercept)"

glm.control(optimizer = c("bobyqa", "bobyqa"), calc.derivs = TRUE, : 未使用的参数 (optimizer = c("bobyqa", "bobyqa"), calc.derivs = TRUE, 使用。 last.params = FALSE,restart_edge = FALSE,boundary.tol = 1e-05,tolPwrss = 1e-07,compDev = TRUE,nAGQ0initStep = TRUE,checkControl = list(check.nobs.vs.rankZ = “忽略”,检查。 nobs.vs.nlev = “停止”,check.nlev.gtreq.5 = “忽略”,check.nlev.gtr.1 = “停止”,check.nobs.vs.nRE = “停止”,check.rankX = "message+drop.cols", check.scaleX = "警告", check.formula.LHS = "stop", check.response.not.const = "stop"), checkConv = list(check.conv.grad = list (action = "警告", tol = 0.001, relTol = NULL), check.conv.singular = list(action = "消息",tol = 1e-04),check.conv.hess = list(action = "warning",tol = 1e-06)),optCtrl = list())

4

2 回答 2

2

tl;博士可能是一个错误MuMIn::dredge()-我仍在挖掘-但如果您省略extra="R^2"规范,它似乎可以正常工作。

可重现的例子

set.seed(101)
dd <- data.frame(x1=rnorm(200),x2=rnorm(200),x3=rnorm(200),
                 f=factor(rep(1:10,each=20)),
                 n=50)
library(lme4)
dd$y <- simulate(~x1+x2+x3+(1|f),
                 family=binomial,
                 weights=dd$n,
                 newdata=dd,
                 newparams=list(beta=c(1,1,1,1),
                                theta=1))[[1]] 
## fit model
m0 <- glmer(y~x1+x2+x3+(1|f),
            family=binomial,
            weights=n,
            data=dd,
            na.action="na.fail")

现在尝试 glmer()+dredge(),有和没有优化器规范

library(MuMIn)
d0 <- dredge(m0)
m1 <- update(m0, control=glmerControl(optimizer="bobyqa"))
d1 <- dredge(m1)

这些都有效——所以问题一定出在一些可选参数上。测试:

d0B <- dredge(m0, beta=c("partial.sd"), extra = c("R^2")) ## works
d1B <- try(dredge(m1, beta=c("partial.sd"), extra = c("R^2"))) ## fails

哪个额外的论点是罪魁祸首?

d1C <- dredge(m1, beta=c("partial.sd"))  ## works
d1D <- try(dredge(m1, extra=c("R^2")))   ## fails

如果您真的非常想要您的 R^2 值,您可以将源代码下载/解压缩到包中,R/r.squaredLR.R如下所示编辑第 101 行(添加cl$control到设置为的元素列表中NULL,然后重新安装包.. .

===================================================================
--- R/r.squaredLR.R (revision 443)
+++ R/r.squaredLR.R (working copy)
@@ -98,7 +98,7 @@
        if(formulaArgName != "formula")
            names(cl)[names(cl) == formulaArgName] <- "formula"
        cl$formula <- update(as.formula(cl$formula), . ~ 1)
-       cl$method <- cl$start <- cl$offset <- contrasts <- NULL
+       cl$method <- cl$start <- cl$offset <- cl$control <- contrasts <- NULL
    }
    cl <- cl[c(TRUE, names(cl)[-1L] %in% names(call2arg(cl)))]
    if(evaluate) eval(cl, envir = envir) else cl
于 2018-12-19T17:57:15.627 回答
2

问题在于r.squaredLR(由 暗示extra = "R^2"),它试图用的参数拟合一个glm空模型。(我将尝试在即将发布的 MuMIn 版本中实现此错误的解决方案。)glmercontrol = glmerControl(optimizer="bobyqa")

glmer(或一般混合模型)的情况下,使用r.squaredGLMM而不是r.squaredLR. 因此,您需要提供一个从(返回 a )dredge的结果中提取 R^2 向量的函数。例如:r.squaredGLMMmatrix

# (following Ben Bolker's example above))
# Fit a null model with RE (use a non-exported function .nullFitRE or specify it by hand:
nullmodel <- MuMIn:::.nullFitRE(m1)
# the above step is not necessary, but avoids repeated re-fitting of the null model.

dredge(m1, beta="partial.sd", extra =list(R2 = function(x) {
    r.squaredGLMM(x, null = nullmodel)["delta", ]
}))
于 2018-12-20T07:30:05.980 回答