【问题标题】:Errors while dredging a pre-setup glmmTMB using fitTMB() in R在 R 中使用 fitTMB() 疏浚预设置 glmmTMB 时出错
【发布时间】:2021-08-13 04:57:18
【问题描述】:

我正在使用专门设计的glmmTMB 来运行具有随机效应的加权二项式模型。 MuMIn 中的 dredge() 函数通常与 glmmTMB 兼容,但我收到错误消息。

使用iris 数据集的可重现示例。请注意,由于随机生成但仍在运行,模型会显示收敛警告。我自己的模型的设置方式完全相同,并且在这样运行时确实会收敛。

library(TMB)
library(glmmTMB)
library(MuMIn)
library(tidyverse)

#Set up the data to fit a negative binomial model
data(iris)
df <- iris %>%
  mutate(used=rep(c(0,1),times=75)) #random binomial response variable


# Create the model according to Muff et al. (2020)
## Link: https://conservancy.umn.edu/bitstream/handle/11299/204737/fisher_rsf_and_ssf.html?sequence=27&isAllowed=y
df$weights <- ifelse(df$used == 1, 1, 1000)

# Set up the model, but do not yet fit it
TMBStruc.ex <- glmmTMB(used~
                      Sepal.Length +
                      Sepal.Width +
                      Petal.Length +
                      Petal.Width +
                      (1|Species) +
                      (0+Sepal.Length|Species) +
                      (0+Sepal.Width|Species) +
                      (0+Petal.Length|Species) +
                      (0+Petal.Width|Species),
                    data=df, family=binomial, weight=weights, doFit=FALSE)

# Fix the standard deviation of the first random term, which is the (1|id) component 
# in the above model equation
TMBStruc.ex$parameters$theta[1] = log(1e3)

# Tell glmmTMB not to change the first entry of the vector of variances, 
# and give all other variances another indicator to make sure they can be freely estimated
TMBStruc.ex$mapArg = list(theta=factor(c(NA,1:4))) #The 1:X value has to be the number of fixed terms  

m <- glmmTMB:::fitTMB(TMBStruc.ex) #This is successful
summary(m)

dredge(m) #Not successful 

#I get the following error:
## Error in seq_len(ncols) :
##   argument must be coercible to non-negative integer
## In addition: Warning messages:
##   1: In while (CLASS == "list") { :
##       the condition has length > 1 and only the first element will be used
##   2: In seq_len(ncols) : first element used of 'length.out' argument

我尝试直接运行dredge 并成功(如下所示),所以它与我设置它的方式有关。

TMBStruc.ex2 <- glmmTMB(used~
                         Sepal.Length +
                         Sepal.Width +
                         Petal.Length +
                         Petal.Width +
                         (1|Species) +
                         (0+Sepal.Length|Species) +
                         (0+Sepal.Width|Species) +
                         (0+Petal.Length|Species) +
                         (0+Petal.Width|Species),
                       data=df, family=binomial, weight=weights) #This is successful
dredge(TMBStruc.ex2) #This is successful

有没有办法解决我发现的错误并在所有预设和参数完好无损的情况下运行挖泥机?

【问题讨论】:

  • 另一个不疏浚的好理由 :-)
  • 我还没有仔细看这个,但是最近版本的 glmmTMB(至少是开发版本,我不记得它是否在 CRAN 版本中)允许您指定一个map 参数来修复一些值(以及 start 参数来指定它们的固定值);这样做可能会解决您通过 fitTMB 破解它时遇到的任何问题
  • 谢谢@Ben Bolker。我会调查的。我目前的计划是看看我是否可以绕过疏浚,但我可能会回到这个。除了当前的问题,我意识到TMBStruc.ex$mapArg = list(theta=factor(c(NA,1:4))) 中的 4 必须根据模型当前运行的参数数量进行更改,这使得事情变得更加困难。
  • 是的,theta 的不同长度肯定是一个挑战。

标签: r statistics modeling


【解决方案1】:

如果我们将startmap 直接传递给glmmTMB,这似乎可以正常工作(从glmmTMB 的1.0.0 版本开始就可以了):

m <- glmmTMB(used~
                      Sepal.Length +
                      Sepal.Width +
                      Petal.Length +
                      Petal.Width +
                      (1|Species) +
                      (0+Sepal.Length|Species) +
                      (0+Sepal.Width|Species) +
                      (0+Petal.Length|Species) +
                      (0+Petal.Width|Species),
                      data=df,
                      family=binomial,
                      weight=weights,
                      start = list(theta=c(log(1e3), rep(0,4))),
                      map = list(theta=factor(c(NA, 1:4)))
                      )

summary(m)
dredge(m)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多