PIRLS 步骤减半,lme4 中带有 cloglog 链接

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

我使用

lme4::lmer()
family = binomial(link = cloglog)
得到 PIRLS 步减半错误。在我看来,我生成的数据可能是下面的模型过于复杂的,这可能是完整的答案,但我对错误注释的理解不够充分,无法自信。我看到另一个答案引用了不太规范的链接函数的行为,并且想知道机器中是否也可能存在导致此错误的问题。

数据,使用dput:

sub <- structure(list(sp = c("1", "1", "1", "1", "1", "2", "2", "2", 
                             "2", "2", "3", "3", "3", "3", "3", "4", "4", "4", "4", "4", "5", 
                             "5", "5", "5", "5"), rplct = c("X1", "X2", "X3", "X4", "X5", 
                                                            "X1", "X2", "X3", "X4", "X5", "X1", "X2", "X3", "X4", "X5", "X1", 
                                                            "X2", "X3", "X4", "X5", "X1", "X2", "X3", "X4", "X5"), abundance = c(131L, 
                                                                                                                                 124L, 128L, 114L, 108L, 62L, 57L, 62L, 65L, 54L, 45L, 45L, 35L, 
                                                                                                                                 38L, 33L, 29L, 31L, 30L, 32L, 30L, 21L, 20L, 25L, 23L, 28L), 
                      pres = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                               1, 1, 1, 1, 1, 1, 1, 1, 1), tot_ab = c(288L, 277L, 280L, 
                                                                      272L, 253L, 288L, 277L, 280L, 272L, 253L, 288L, 277L, 280L, 
                                                                      272L, 253L, 288L, 277L, 280L, 272L, 253L, 288L, 277L, 280L, 
                                                                      272L, 253L)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
                                                                                                                                            -25L))

拟合具有随机效应的模型没有错误,但没有偏移项:

no_off <- lme4::glmer(pres ~ (1|sp)
                       , family = binomial(link = cloglog)
                      , data = sub)

也没有偏移但没有随机效应:

no_re <- glm(pres ~ offset(log(tot_ab)) 
                             , family = binomial(link = cloglog)
                             , data = sub)

但是 PIRLS 将偏移量和 RE 的误差减半

smaller <- lme4::glmer(pres ~ offset(log(tot_ab)) + (1|sp)
               , family = binomial(link = cloglog)
               , data = sub)

本例中出现此错误的原因是什么?

我能够生成其他有趣且更易于解析的错误,例如在模拟不适当的数据时

Error: cannot generate feasible simplex
,但不确定我的问题是什么。

谢谢!

optimization precision lme4
1个回答
0
投票

我相信这个问题根本上是由 cloglog 反向链接函数的细(上?)尾部引起的。虽然我还没有深入挖掘并诊断出精确的问题,但我有一个解决方案:不要使用总丰度的对数作为偏移量,而是使用

log(tot_ab)/min(tot_ab)
;也就是说,不是对每个采样的个体有机体的发生概率进行建模,而是对在最小样本大小的样本中的发生概率进行建模。 (您还应该能够选择与最小样本大小相同数量级的整数。)下面的代码演示了在模拟数据上运行 1000 次时,拟合总是失败并显示
offset(log(tot_ab))
,但总是成功(尽管有可能是奇异拟合、收敛警告等)与最小缩放偏移。

library(lme4)
simfun <- function(seed = NULL) {
    if (!is.null(seed)) set.seed(seed)
    dd <- data.frame(sp = factor(rep(1:30, each = 5)),
                     tot_ab = rnbinom(150, mu = 250, size = 50))
    dd$pres <- suppressMessages(simulate(~ (1|sp) + offset(log(tot_ab))
                      , family = binomial(link = "cloglog")
                      , newdata = dd
                      , newparam = list(beta=-8, theta = 1))[[1]])
    dd
}

fitfun <- function(dd, fix_offset = FALSE) {
    if (!fix_offset) {
        form <- pres ~ (1|sp) + offset(log(tot_ab))
    } else {
        form <- pres ~ (1|sp) + offset(log(tot_ab)/min(tot_ab))
    }
    res <- try(
        suppressMessages(
            glmer(
                form
              , family = binomial(link = "cloglog")
              , data = dd)), silent = TRUE
    )
    if (!inherits(res, "try-error")) return("OK")
    as.character(res)
}

与原始偏移配合:

set.seed(101)
res <- replicate(1000, fitfun(simfun()))
table(res)
Error : (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
                                                                                     8 
                                            Error : cannot generate feasible simplex
                                                                                   983 
                          Error : pwrssUpdate did not converge in (maxit) iterations

                                                                                     9 

现在适合最小缩放偏移:

res <- replicate(1000, fitfun(simfun(), fix_offset = TRUE))
table(res)
res
  OK 
1000 
© www.soinside.com 2019 - 2024. All rights reserved.