问题描述
我正在使用专门设计的 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 (将#修改为@)