【发布时间】:2019-04-25 14:32:42
【问题描述】:
我正在尝试使用 lme4 包中的 glmer 来模拟几个变量对发生自循环的可能性的影响。这是一个非常大的数据集,包含 >900,000 个数据点。
当我尝试运行模型时出现此错误。
SLMod <- glmer(SL ~ species*season + (1|code), data=SL, family=binomial)
Warning message:
In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0013493 (tol = 0.001,
component 1)
这是输出
summary(SLMod)
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: SL ~ species * season + (1 | code)
Data: SL
AIC BIC logLik deviance df.resid
708076.5 708135.1 -354033.2 708066.5 906441
Scaled residuals:
Min 1Q Median 3Q Max
-1.6224 -0.4324 -0.3136 -0.1983 5.0722
Random effects:
Groups Name Variance Std.Dev.
code (Intercept) 0.8571 0.9258
Number of obs: 906446, groups: code, 180
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.29729 0.05944 -21.824 < 2e-16 ***
speciesSilvertip Shark 0.05593 0.06390 0.875 0.381
seasonwet season 0.09617 0.01008 9.537 < 2e-16 ***
speciesSilvertip Shark:seasonwet season -0.10809 0.01354 -7.983 1.43e-15 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) spcsSS ssnwts
spcsSlvrtpS -0.585
seasonwtssn 0.009 -0.004
spcsSShrk:s -0.007 0.001 -0.744
convergence code: 0
Model failed to converge with max|grad| = 0.0013493 (tol = 0.001, component 1)
这是一组动物运动的数据集,在同一点连续检测并计算时间差。如果时间差大于 10 分钟,则这已被确定为自循环并给出 1,如果小于 10 分钟则为 0。数据示例如下。
structure(list(code = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label =
"2388", class = "factor"),
species = c("Silvertip Shark", "Silvertip Shark", "Silvertip Shark",
"Silvertip Shark", "Silvertip Shark", "Silvertip Shark"),
sex = c("F", "F", "F", "F", "F", "F"), TL = c(112, 112, 112,
112, 112, 112), datetime = structure(c(1466247120, 1466247420,
1467026100, 1469621400, 1469879640, 1470397200), class = c("POSIXct",
"POSIXt"), tzone = ""), year = c("2016", "2016", "2016",
"2016", "2016", "2016"), month = c(6, 6, 6, 7, 7, 8), hour = c(11,
11, 12, 13, 12, 12), season = c("dry season", "dry season",
"dry season", "dry season", "dry season", "dry season"),
daynight = c("day", "day", "day", "day", "day", "day"), SL = c(0,
0, 1, 1, 1, 1)), row.names = c(NA, 6L), class = "data.frame")
我使用此代码随机抽取了我的数据集,仅 50% 的数据
SL50 <- SL %>% sample_frac(0.5)
并在该数据集上运行相同的代码,它运行良好,没有错误。我想知道我正在运行的数据集的大小是否存在问题。但是,我在使用 50% 采样数据的不同模型中遇到了类似的错误,当我在 10% 的数据上运行该代码时,该错误消失了。
SLMod <- glmer(SL ~ species*daynight + (1|code), data=SL50,
family=binomial)
Warning message:
In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0010195 (tol = 0.001,
component1)
它尝试为每个模型处理的数据大小是否可能存在问题?有没有办法解决这个问题?
【问题讨论】:
-
这里的随机效应术语是什么?
code? -
是的,代码是动物 ID。数据集中有多种动物,因此将其作为随机效应包含在内。