微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 R 中使用 fitTMB() 疏通预先设置的 glmmTMB 时出错

如何解决在 R 中使用 fitTMB() 疏通预先设置的 glmmTMB 时出错

我正在使用专门设计的 glmmTMB 来运行具有随机效应的加权二项式模型。 dredge()MuMIn 函数通常与 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),weight=weights) #This is successful
dredge(TMBStruc.ex2) #This is successful

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。