- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 R 中的 lme4
的 glmer
函数分析数据(包括在下面)。我正在构建的模型包含一个泊松分布响应变量 (obs
)、一个随机因子 (area
)、一个连续偏移量 (duration
), 五个连续固定效应 (can_perc
, can_n
, time
, temp
, cloud_cover
) 和一个二项式固定效应因子 (burnt
)。在拟合模型之前,我检查了共线性并删除了所有共线性变量。
初始模型为:
q1 = glmer(obs ~ can_perc + can_n + time * temp +
cloud_cover + factor(burnt) + (1|area) + offset(dat$duration),
data=dat, family=poisson, na.action = na.fail)
(注意:我需要将 na.action
指定为“na.fail”,因为我稍后想 dredge()
模型,这是必需的.)
运行模型会给出以下警告:
"Hessian is numerically singular: parameters are not uniquely determined"
在模型的类似变体中,我也收到了警告:
"In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?"
根据我对此处建议的有限理解https://rdrr.io/cran/lme4/man/troubleshooting.html在其他地方,这两个警告都反射(reflect)了一个类似的问题,即 Hessian(逆曲率矩阵)具有较大的特征值,表明(在数值公差范围内)表面在某个方向上是完全平坦的。根据警告和链接中的建议,我使用 scale()
重新调整了所有连续预测变量。我还缩放了偏移量变量(我尝试了缩放和不缩放这个变量)。具有缩放预测变量的模型在这里:
q2 = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp +
s.cloud_cover + factor(burnt) + (1|area) +
offset(dat$s.duration),
data=dat, family=poisson, na.action = na.fail)
但是我还没有逃脱特征值!缩放模型给出了两个警告:
"unable to evaluate scaled gradient"
"Model failed to converge: degenerate Hessian with 1 negative eigenvalues"
我在网上搜索了很多,除了检查模型没有被错误指定之外,找不到其他案例/解决方案来处理预测变量缩放后的特征值问题。
基于这些页面/文档: https://cran.r-project.org/web/packages/lme4/lme4.pdf
https://rdrr.io/cran/lme4/man/isSingular.html
https://stats.stackexchange.com/questions/242109/model-failed-to-converge-warning-in-lmer
和其他人,
我有:
检查了模型规范和数据是否有错误(我没有看到任何错误 - 我是否遗漏了什么?)
使用 is_singular(x, tol = 1e-05)
检查奇点(此函数调用不知何故从 isSingular()
演变为当前形式?):所有模型都给出 FALSE。
使用 converge_ok(q2, tolerance = 0.001)
检查收敛性度量:所有模型都给出 FALSE,除非我大幅增加容差;然而,它们在收敛措施上确实存在很大差异。
尝试了如下不同的优化器/模型估计方法:
glmerControl(optimizer = "bobyqa") 和 glmerControl(optimizer ="Nelder_Mead")
glmerControl(optimizer ='optimx', optCtrl=list(method='nlminb'))
all_fit()
函数。 代码如下:
# singularity and convergence for first two models:
is_singular(s1, tol = 1e-05) # FALSE (a good thing?)
converge_ok(s1, tol = 1e-05) # FALSE (a bad thing?) 0.0259109730912352
is_singular(s2, tol = 1e-05) # FALSE (a good thing?)
converge_ok(s2, tol = 1e-05) # FALSE (a bad thing?) 0.0023434329028163
# I looked at singularity and converge measures for the others below, but omitted for brevity.
# Alternate optimisations for q1:
q1.bobyqa = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
# Warning 1: unable to evaluate scaled gradient
# Warning 2: Model failed to converge: degenerate Hessian with 1 negative eigenvalues
q1.neldermead = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer ="Nelder_Mead", optCtrl = list(maxfun = 2e5)))
# Warning: unable to evaluate scaled gradient Hessian is numerically singular: parameters are not uniquely determined
q1.nlminb = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer ='optimx', optCtrl=list(method='nlminb')))
# Warning: Parameters or bounds appear to have different scalings. This can cause poor performance in optimization.
# It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.convergence code 9999 from optimxError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, : (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
all_fit(q1)
# Alternate optimisations for q2:
q2.bobyqa = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover + factor(burnt) + (1|area) + offset(dat$s.duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
# Warning 1: unable to evaluate scaled gradient
# Warning 2: Model failed to converge: degenerate Hessian with 1 negative eigenvalues
q2.neldermead = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover + factor(burnt) + (1|area) + offset(dat$s.duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer ="Nelder_Mead", optCtrl = list(maxfun = 2e5)))
# Warning: unable to evaluate scaled gradient Hessian is numerically singular: parameters are not uniquely determined
q2.nlminb = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover + factor(burnt) + (1|area) + offset(dat$s.duration), data=dat, family=poisson, na.action = na.fail, control = glmerControl(optimizer ='optimx', optCtrl=list(method='nlminb')))
# Warning: Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
all_fit(q2)
is_singular(s1, tol = 1e-05) # FALSE (a good thing?)
[1] FALSE
converge_ok(s1, tol = 1e-05) # FALSE (a bad thing?) 0.0259109730912352
0.0259109730912352
FALSE
is_singular(s2, tol = 1e-05) # FALSE (a good thing?)
[1] FALSE
alternate optimisations for original model:
q1.bobyqa = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues
alternate optimisations for original model:
q1.bobyqa = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues
q1.neldermead = glmer(obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1|area) + offset(dat$duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer ="Nelder_Mead", optCtrl = list(maxfun = 2e5)))
unable to evaluate scaled gradient Hessian is numerically singular: parameters are not uniquely determined
all_fit(q1)
bobyqa. : unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues[OK]
Nelder_Mead. : unable to evaluate scaled gradient Hessian is numerically singular: parameters are not uniquely determined[OK]
optimx.nlminb : Parameters or bounds appear to have different scalings.
This can cause poor performance in optimization.
It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.convergence code 9999 from optimxParameters or bounds appear to have different scalings.
This can cause poor performance in optimization.
It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.convergence code 9999 from optimx[ERROR]
optimx.L-BFGS-B : Parameters or bounds appear to have different scalings.
This can cause poor performance in optimization.
It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.convergence code 9999 from optimxParameters or bounds appear to have different scalings.
This can cause poor performance in optimization.
It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.convergence code 9999 from optimx[ERROR]
nloptwrap.NLOPT_LN_NELDERMEAD : [ERROR]
nloptwrap.NLOPT_LN_BOBYQA : [ERROR]
nmkbw. : [ERROR]
$`bobyqa.`
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1 | area) + offset(dat$duration)
Data: dat
AIC BIC logLik deviance df.resid
311.0473 330.3356 -146.5237 293.0473 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 1.992
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept) can_perc can_n time temp
-67.4998 -1.3180 0.0239 4.8025 1.7793
cloud_cover factor(burnt)unburnt time:temp
-0.3813 18.5676 -0.1748
convergence code 0; 2 optimizer warnings; 0 lme4 warnings
$Nelder_Mead.
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: obs ~ can_perc + can_n + time * temp + cloud_cover + factor(burnt) + (1 | area) + offset(dat$duration)
Data: dat
AIC BIC logLik deviance df.resid
311.0473 330.3356 -146.5237 293.0473 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 1.992
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept)
can_perc can_n time temp
-67.48057 -1.31791 0.02389 4.80463 1.78012
cloud_cover factor(burnt)unburnt time:temp
-0.38118 18.52637 -0.17483
convergence code 0; 2 optimizer warnings; 0 lme4 warnings
$optimx.nlminb
<std::runtime_error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate>
$`optimx.L-BFGS-B`
<std::runtime_error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate>
$nloptwrap.NLOPT_LN_NELDERMEAD
<simpleError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): Downdated VtV is not positive definite>
$nloptwrap.NLOPT_LN_BOBYQA
<simpleError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): Downdated VtV is not positive definite>
$nmkbw.
<std::runtime_error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate>
alternate optimisations for q2:
q2.bobyqa = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover + factor(burnt) + (1|area) + offset(dat$s.duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables?
q2.neldermead = glmer(obs ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover + factor(burnt) + (1|area) + offset(dat$s.duration), data=dat, family=poisson, na.action = na.fail, glmerControl(optimizer ="Nelder_Mead", optCtrl = list(maxfun = 2e5)))
unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues
all_fit(q2)
bobyqa. : Model is nearly unidentifiable: large eigenvalue ratio
- Rescale variables?[OK]
Nelder_Mead. : unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues[OK]
optimx.nlminb : Model is nearly unidentifiable: large eigenvalue ratio
- Rescale variables?[OK]
optimx.L-BFGS-B : unable to evaluate scaled gradientModel failed to converge: degenerate Hessian with 1 negative eigenvalues[OK]
nloptwrap.NLOPT_LN_NELDERMEAD : [ERROR]
nloptwrap.NLOPT_LN_BOBYQA : [ERROR]
nmkbw. : [ERROR]
$`bobyqa.`
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: n_shreiberi ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover +
factor(burnt) + (1 | area) + offset(dat$s.duration)
Data: dat
AIC BIC logLik deviance df.resid
316.8412 336.1294 -149.4206 298.8412 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 2.523
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept) s.can_perc s.can_n s.time s.temp
-18.19816 -0.22152 0.45839 0.05239 -0.24983
s.cloud_cover factor(burnt)unburnt s.time:s.temp
-0.19691 17.92390 -0.13948
convergence code 0; 1 optimizer warnings; 0 lme4 warnings
$Nelder_Mead.
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: n_shreiberi ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover +
factor(burnt) + (1 | area) + offset(dat$s.duration)
Data: dat
AIC BIC logLik deviance df.resid
316.8408 336.1290 -149.4204 298.8408 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 2.524
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept) s.can_perc s.can_n s.time s.temp
-19.29632 -0.22153 0.45840 0.05241 -0.24990
s.cloud_cover factor(burnt)unburnt s.time:s.temp
-0.19692 19.02091 -0.13949
convergence code 0; 2 optimizer warnings; 0 lme4 warnings
$optimx.nlminb
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: n_shreiberi ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover +
factor(burnt) + (1 | area) + offset(dat$s.duration)
Data: dat
AIC BIC logLik deviance df.resid
316.8412 336.1294 -149.4206 298.8412 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 2.523
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept) s.can_perc s.can_n s.time s.temp
-18.23626 -0.22152 0.45839 0.05239 -0.24983
s.cloud_cover factor(burnt)unburnt s.time:s.temp
-0.19691 17.96199 -0.13948
convergence code 0; 1 optimizer warnings; 0 lme4 warnings
$`optimx.L-BFGS-B`
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: poisson ( log )
Formula: n_shreiberi ~ s.can_perc + s.can_n + s.time * s.temp + s.cloud_cover +
factor(burnt) + (1 | area) + offset(dat$s.duration)
Data: dat
AIC BIC logLik deviance df.resid
316.8412 336.1294 -149.4206 298.8412 54
Random effects:
Groups Name Std.Dev.
area (Intercept) 2.524
Number of obs: 63, groups: area, 8
Fixed Effects:
(Intercept) s.can_perc s.can_n s.time s.temp
-18.23581 -0.22155 0.45841 0.05242 -0.24997
s.cloud_cover factor(burnt)unburnt s.time:s.temp
-0.19694 17.96246 -0.13943
convergence code 0; 2 optimizer warnings; 0 lme4 warnings
$nloptwrap.NLOPT_LN_NELDERMEAD
<simpleError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): Downdated VtV is not positive definite>
$nloptwrap.NLOPT_LN_BOBYQA
<simpleError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): Downdated VtV is not positive definite>
$nmkbw.
<simpleError in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev, grpFac = fac, maxit = maxit, verbose = verbose): Downdated VtV is not positive definite>
数据集可在此链接获得: https://www.dropbox.com/s/ud50uatztjq4bh9/20181217%20Surveys%20simplified%20data%20for%20stackX.xlsx?dl=0
在我看来,这些替代优化方法都没有成功;事实上,其中一些似乎引发了其他警告/错误,这会让我陷入另一个困境。
任何人都可以建议我如何在拟合这些模型方面取得进展吗?我的目的不是让这些成为最终模型,而是挖掘它们,然后从不同的替代子集模型中选择最优/顶级模型。
最佳答案
tl;dr 这看起来像是完全分离的情况;在你的“烧伤”状态下,你根本没有积极的结果。您不一定需要担心这一点 - AIC 比较应该仍然相当稳健 - 但您可能想在继续之前了解发生了什么。 GLMM FAQ 的相关部分讨论了这个问题(和补救措施) (在 CrossValidated 上有各种相关问题/答案)。
我怎么知道?以下是系数:
(Intercept) s.can_perc s.can_n s.time s.temp
-19.29632 -0.22153 0.45840 0.05241 -0.24990
s.cloud_cover factor(burnt)unburnt s.time:s.temp
-0.19692 19.02091 -0.13949
任何时候(二项式或泊松式)GLM 中的系数(绝对值)大于 8-10,您都必须担心(除非您正在查看以非常大的方式测量的数值协变量的系数单位,例如,如果您以十亿吨为单位查看后院的碳量)。这意味着预测变量的一个单位变化会导致对数赔率(例如)10 个单位的变化(对于二项式/logit 链接模型),例如从概率 0.006 (plogis(-5)
) 到 0.994 (plogis(5)
)。在您的情况下,截距为 -19.29,因此当所有预测变量的值都为零时,处于燃烧状态,您得到的概率为 4.2e-9。另一个巨大的系数用于 unburnt
(19.02),因此在未燃烧(未燃烧?)条件下所有预测变量的值为零时,您将得到 plogis(-19.29+19.02)
= 0.43。
关于r - lme4 glmer 中的缩放预测变量不会解决特征值警告;替代优化也没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53834754/
我正在使用 R 预测包拟合模型,如下所示: fit <- auto.arima(df) plot(forecast(fit,h=200)) 打印原始数据框和预测。当 df 相当大时,这
我正在尝试预测自有住房的中位数,这是一个行之有效的例子,给出了很好的结果。 https://heuristically.wordpress.com/2011/11/17/using-neural-ne
type="class"函数中的type="response"和predict有什么区别? 例如: predict(modelName, newdata=testData, type = "class
我有一个名为 Downloaded 的文件夹,其中包含经过训练的 CNN 模型必须对其进行预测的图像。 下面是导入图片的代码: import os images = [] for filename i
关于预测的快速问题。 我尝试预测的值是 0 或 1(它设置为数字,而不是因子),因此当我运行随机森林时: fit , data=trainData, ntree=50) 并预测: pred, data
使用 Python,我尝试使用历史销售数据来预测产品的 future 销售数量。我还试图预测各组产品的这些计数。 例如,我的专栏如下所示: Date Sales_count Department It
我是 R 新手,所以请帮助我了解问题所在。我试图预测一些数据,但预测函数返回的对象(这是奇怪的类(因子))包含低数据。测试集大小为 5886 obs。 160 个变量,当预测对象长度为 110 时..
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
下面是我的神经网络代码,有 3 个输入和 1 个隐藏层和 1 个输出: #Data ds = SupervisedDataSet(3,1) myfile = open('my_file.csv','r
我正在开发一个 Web 应用程序,它具有全文搜索功能,可以正常运行。我想对此进行改进并向其添加预测/更正功能,这意味着如果用户输入错误或结果为 0,则会查询该输入的更正版本,而不是查询结果。基本上类似
我对时间序列还很陌生。 这是我正在处理的数据集: Date Price Location 0 2012-01-01 1771.0
我有许多可变长度的序列。对于这些,我想训练一个隐马尔可夫模型,稍后我想用它来预测(部分)序列的可能延续。到目前为止,我已经找到了两种使用 HMM 预测 future 的方法: 1) 幻觉延续并获得该延
我正在使用 TensorFlow 服务提供初始模型。我在 Azure Kubernetes 上这样做,所以不是通过更标准和有据可查的谷歌云。 无论如何,这一切都在起作用,但是我感到困惑的是预测作为浮点
我正在尝试使用 Amazon Forecast 进行一些测试。我现在尝试了两个不同的数据集,它们看起来像这样: 13,2013-03-31 19:25:00,93.10999 14,2013-03-3
使用 numpy ndarray大多数时候我们不需要担心内存布局的问题,因为结果并不依赖于它。 除非他们这样做。例如,考虑这种设置 3x2 矩阵对角线的稍微过度设计的方法 >>> a = np.zer
我想在同一个地 block 上用不同颜色绘制多个预测,但是,比例尺不对。我对任何其他方法持开放态度。 可重现的例子: require(forecast) # MAKING DATA data
我正在 R 中使用 GLMM,其中混合了连续变量和 calcategories 变量,并具有一些交互作用。我使用 MuMIn 中的 dredge 和 model.avg 函数来获取每个变量的效果估计。
我能够在 GUI 中成功导出分类器错误,但无法在命令行中执行此操作。有什么办法可以在命令行上完成此操作吗? 我使用的是 Weka 3.6.x。在这里,您可以右键单击模型,选择“可视化分类器错误”并从那
我想在同一个地 block 上用不同颜色绘制多个预测,但是,比例尺不对。我对任何其他方法持开放态度。 可重现的例子: require(forecast) # MAKING DATA data
我从 UCI 机器学习数据集库下载了一个巨大的文件。 (~300mb)。 有没有办法在将数据集加载到 R 内存之前预测加载数据集所需的内存? Google 搜索了很多,但我到处都能找到如何使用 R-p
我是一名优秀的程序员,十分优秀!