具有用户定义链接功能的glmer给出错误:(maxstephalfit)PIRLS分步未能减少偏差 [英] glmer with user-defined link function giving error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance

查看:204
本文介绍了具有用户定义链接功能的glmer给出错误:(maxstephalfit)PIRLS分步未能减少偏差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用具有随机效果的glmer的用户定义的链接功能时,我遇到了一个我不知道如何解决的错误:

While attempting to leverage a user-defined link function with a random-effect glmer, I've run into an error that I don't know how to troubleshoot:

Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate

有人对如何解决此错误有任何建议吗?它没有提供太多指导.

Does anyone have any advice on how one might approach resolving this error? It doesn't provide much direction.

我尝试按照 rpubs中概述的说明来定义新的链接函数(特别是缩放的logit)的说明. .com/bbolker/logregexp ,但如果定义的某些方面不正确,我也不会感到惊讶.看到我想念的东西吗?

I've attempted to follow the instructions for defining a new link function (specifically a scaled logit) as outlined at rpubs.com/bbolker/logregexp, but I would not be surprised if some aspect of my definition is incorrect. See anything I'm missing?

scaled_logit <- function(s = 1) {
  linkfun <- function(mu) log( max(0, mu / (s-mu)) )
  linkinv <- function(eta) s / (1 + exp(-eta))
  mu.eta <- function(eta) s * exp(-eta) / (1 + exp(-eta))^2
  valideta <- function(eta) TRUE
  link <- paste0('scaled_logit(',s,')')
  structure(list(linkfun = linkfun, linkinv = linkinv, mu.eta = mu.eta, valideta = valideta, name = link), class = 'link-glm')
}

此实现肯定有问题,因为估计对于标准二项式族(假定为logit链接)可以正常工作,但是当我使用s = 1引用此链接时,错误出了(应该是相同的).样本数据可以按如下方式生成:

There must be something wrong with this implementation, since estimation works fine with the standard binomial family (assumed logit link), but errors out when I reference this link with s=1 (which should be identical). Sample data can be generated as follows:

library(data.table)

courts <- 50
test_courts <- data.table(court = 1:courts,
                     court_factor = pmax(0, rnorm(courts, mean=1, sd=0.25)))
setkey(test_courts, court)
pros <- 100
test_pros <- data.table(ID = 1:pros,
                       deg1_rate = pmax(0, rnorm(pros, mean=0.02, sd=0.0075)))
setkey(test_pros, ID)

test_data <- data.table(expand.grid(ID = 1:pros, court = 1:courts))
setkeyv(test_data, c('ID','court'))
test_data <- merge(test_data, test_courts, by='court', all.x=TRUE)
test_data <- merge(test_data, test_pros  , by='ID'   , all.x=TRUE)

test_data[ , indict := sample(0:20, nrow(test_data), replace=TRUE)]
test_data[ , deg1 := rbinom(pros*courts, size=indict, prob=court_factor*deg1_rate)]

然后我一直在尝试估算简单模型

I've then been attempting to estimate the simple model

logit_link <- glmer(cbind(deg1, indict-deg1) ~ (1|ID) + (1|court), family=binomial, data=test_data[indict > 0])

和相应的替代方法

scaled_link <- glmer(cbind(deg1, indict-deg1) ~ (1|ID) + (1|court), family=binomial(link=scaled_logit()), data=test_data[indict > 0])

任何见解将不胜感激!我正在R 3.0.3上使用lme4 1.1.6.

Any insights would be appreciated! I'm using lme4 1.1.6 on R 3.0.3.

推荐答案

我认为您的问题可能出在未能固定"反向链接功能(即将结果严格限制在0到1之间)的情况下,但是事实证明(我认为)要比这简单得多-只是max()pmax()的混淆. (max()有一个非常危险的设计!)这对我有用:

I thought your problem would turn out to be with failing to "clamp" the inverse-link function (i.e. keeping the results strictly between 0 and 1), but it turns out that (I think) it's much simpler than that -- just a confusion of max() and pmax(). (max() has a pretty dangerous design!) This works for me:

scaled_logit <- function(s = 1) {
  linkfun <- function(mu) log( pmax(0, mu / (s-mu)) )
  linkinv <- function(eta) s / (1 + exp(-eta))
  mu.eta <- function(eta) s * exp(-eta) / (1 + exp(-eta))^2
  valideta <- function(eta) TRUE
  link <- paste0('scaled_logit(',s,')')
  structure(list(linkfun = linkfun, linkinv = linkinv, mu.eta = mu.eta, valideta = valideta, name = link), class = 'link-glm')
}

也就是说,对于将来的健壮性来说,最好使用pmax(epsilon,...)而不是pmax(0,...)并限制epsilon1-epsilon之间的反向链接函数(其中epsilon类似于1e-6).

That said, it would probably be a good idea for future robustness to make that pmax(epsilon,...) rather than pmax(0,...) and to constrain the inverse link function between epsilon and 1-epsilon (where epsilon is something like 1e-6).

PS可能应该尝试在PIRLS步骤中插入一些更强大的错误检查-当出现/非限定值的许多问题时,看起来就像是PIRLS故障一样.并不是真正的含义(nan似乎通过C ++代码传播而不会触发任何立即的失败...)

PS we (lme4 maintainers) should probably try to insert some more robust error-checking in the PIRLS step -- a lot of issues with NaN/non-finite values pop up looking like PIRLS failures, when that's not really what they are (nans seem to propagate through the C++ code without triggering any immediate failures ...)

这篇关于具有用户定义链接功能的glmer给出错误:(maxstephalfit)PIRLS分步未能减少偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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