glmmTMB 中的错误:在起始参数值处负对数似然为 NaN

时间:2021-07-15 22:14:15

标签: r modeling mixed-models log-likelihood glmmtmb

我已经按照本文中的方法使用 glmmTMB 运行了一系列混合效应条件逻辑回归模型,以评估动物资源的使用:https://besjournals.onlinelibrary.wiley.com/doi/abs/10.1111/1365-2656.13087。大多数情况下,模型似乎工作正常,但对于某些模型,我得到了错误:

Error in glmmTMB: negative log-likelihood is NaN at starting parameter values

有人可以解释一下这是什么意思,或者为什么会用外行的话解释这个错误?我不知道在 optim() 中调整参数是否会有所帮助。我想这可能与我的数据中由居中引起的负值有关,但我已经尝试使用所有正的未居中数据(仍然缩放)以及将每个条件组中的第一个值排序为正值。奇怪的是,我让它在一个模型上工作,但不是任何其他模型。我还尝试将数据细分为更小的块以找出错误所在,但是当我这样做时,我没有收到任何错误。有时,当我将数据的 3/4 进行子集化时,它会起作用,有时则不起作用,即使公式/模型相同并且我为该子集提取的观察数也相同,这让我觉得是数据中的某些东西,或者它是如何读取数据的。

我已经包含了一个模拟数据结构的示例数据集,但显然它太小了,无法在没有收敛问题的情况下运行模型。我的实际数据集很大——大约有 680 万个观测值。

任何见解都值得真正赞赏 - 这变得非常令人沮丧。提前致谢。

# Create example data frame
test <- data.frame(Animal.ID = as.numeric(c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3)),
          str_ID = as.integer(c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6)),
          Diel_period = as.factor(c(0,0,0,1,1,1,2,2,2,3,3,3,0,0,0,1,1,1)),
          HC = as.factor(c(0,1,2,1,2,0,0,0,2,1,0,2,1,2,1,0,1,1)),
          Used = as.integer(1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0),
          Elevation = c(0.1,0.2,-0.15,0.2,-0.3,0.4,0.5,-0.6,0.1,0.2,-0.1,-0.96,0.5,-0.4,0.6,-0.11,-0.7,0.42),
          Slope = c(-0.6,0.1,0.2,-0.1,-0.96,0.5,-0.4,0.1,0.2,-0.15,0.2,-0.3,0.4,0.5,0.6,-0.11,-0.7,0.42))

str(test)

# Set up model without running
TMBStruc11 = glmmTMB(Used ~ -1 + HC + Slope + I(Slope^2) + Elevation + Diel_period + HC*Diel_period +(1|str_ID) + 
                       (0 + Slope | Animal.ID) + (0 + Elevation | Animal.ID),family=poisson, data=test, doFit=FALSE)

# Set the value of the standard deviation of the first random effect
TMBStruc11$parameters$theta[1] = log(1e3)

# Get number of parameters to be estimated and tell glmmTMB not to change the first standard 
# deviation, all other values are freely estimated (and are different from each other)
nvarparm<-length(TMBStruc11$parameters$theta)
TMBStruc11$mapArg = list(theta=factor(c(NA,1:(nvarparm-1))))

#Fit model
glmm11 <- glmmTMB:::fitTMB(TMBStruc11)

0 个答案:

没有答案