指定glmer优化器时,挖泥机不起作用 [英] dredge doesn't work when specifying glmer optimizer

查看:268
本文介绍了指定glmer优化器时,挖泥机不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将R包MuMIn中的dredge与全局二项式glmer模型一起使用.我发现我需要使用control = glmerControl(optimizer="bobyqa")指定优化器以实现收敛.但是,当我使用dredge时,出现错误.如果减少模型中预测变量的数量,则可以删除bobyqa规范,进行收敛,并使用挖泥机.有什么办法可以让dredgeglmerControl(optimizer="bobyqa")一起使用?

I am trying to use dredge from the R package MuMIn with a global binomial glmer model. I find that I need to specify the optimizer with control = glmerControl(optimizer="bobyqa") for convergence. However, when I go to use dredge, I get an error. If I reduce the number of predictors in the model, I can remove the bobyqa specification, get convergence, and use dredge. Any way I can get dredge to go with glmerControl(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,use.last.params = FALSE,restart_edge = FALSE,boundary.tol = 1e-05,tolPwrss = 1e-07,compDev = TRUE,nAGQ0initStep = TRUE,checkControl = list(check.nobs.vs.rankZ ="ignore",check.nobs.vs.nlev ="stop",check.nlev.gtreq.5 ="ignore",check.nlev. gtr.1 ="stop",check.nobs.vs.nRE ="stop",check.rankX ="message + drop.cols",check.scaleX =警告",check.formula.LHS ="stop", check.response.not.const ="stop"),checkConv =列表(check.conv.grad =列表( 动作=警告",tol = 0.001,relTol = NULL),check.conv.singular = list(动作=消息",tol = 1e-04),check.conv.hess = list(动作=警告", tol = 1e-06)),optCtrl = list())

Error in glm.control(optimizer = c("bobyqa", "bobyqa"), calc.derivs = TRUE, : unused arguments (optimizer = c("bobyqa", "bobyqa"), calc.derivs = TRUE, use.last.params = FALSE, restart_edge = FALSE, boundary.tol = 1e-05, tolPwrss = 1e-07, compDev = TRUE, nAGQ0initStep = TRUE, checkControl = list(check.nobs.vs.rankZ = "ignore", check.nobs.vs.nlev = "stop", check.nlev.gtreq.5 = "ignore", check.nlev.gtr.1 = "stop", check.nobs.vs.nRE = "stop", check.rankX = "message+drop.cols", check.scaleX = "warning", check.formula.LHS = "stop", check.response.not.const = "stop"), checkConv = list(check.conv.grad = list( action = "warning", tol = 0.001, relTol = NULL), check.conv.singular = list(action = "message", tol = 1e-04), check.conv.hess = list(action = "warning", tol = 1e-06)), optCtrl = list())

推荐答案

tl; dr 可能是MuMIn::dredge()中的错误-我仍在挖掘-但如果您离开,它似乎可以正常运行超出extra="R^2"规范.

tl;dr probably a bug in MuMIn::dredge() - I'm still digging - but it seems to work OK if you leave out the extra="R^2" specification.

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)

所有这些都起作用-因此问题必须出在某些可选参数上.测试:

These all work - so the problem must be with some of the optional arguments. Testing that:

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,然后重新安装软件包...


If you really, really want your R^2 values you could download/unpack the source code to the package, edit line 101 of R/r.squaredLR.R as indicated below (add cl$control to the list of elements that are set to NULL, and re-install the package ...

===================================================================
--- 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

这篇关于指定glmer优化器时,挖泥机不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆