用先前的估计值重新开始混合效应模型的估计 [英] Restart mixed effect model estimation with previously estimated values
问题描述
我正在使用包lme4
中的lmer()
来估计混合效果模型.效果很好,但是现在我要运行固定数量的迭代估算过程,然后通过指定由上一个估算过程计算出的起始值来恢复估算过程.
I'm using lmer()
in package lme4
to estimate mixed effects models. This works well, but now I want to run the estimation process for a fixed number of iterations, then resume the process by specifying start values, as calculated by the last estimation process.
根据?lmer
的帮助,可以通过设置参数来实现:
According to the help for ?lmer
this is possible, by setting the arguments:
-
start
-这些是新的起始值,根据帮助,可以从拟合模型中提取插槽ST
中的值并使用这些值,即使用x@ST
-
maxiter
-作为control
的命名参数提供
start
- these are the new start values, and according to the help one can extract the value in slotST
from a fitted model and use these, i.e. usex@ST
maxiter
- supplied as a named argument tocontrol
例如,假设我要使用iris
数据拟合lme
,则可以尝试以下方法:
So, for example, suppose I want to fit a lme
using the iris
data, one can try this:
library(lme4)
# Fit model with limited number of iterations
frm <- "Sepal.Length ~ Sepal.Width | Species"
x <- lmer(frm, data=iris,
verbose=TRUE, control=list(maxIter=1), model=FALSE)
# Capture starting values for next set of iterations
start <- list(ST=x@ST)
# Update model
twoStep <- lmer(frm, data=iris,
verbose=TRUE, control=list(maxIter=100), model=TRUE,
start=start)
这有效.看一下输出,其中第一列是REML,即随机效应的最大可能性.尤其要注意,模型2中的REML在模型1终止的地方开始:
This works. Take a look at the output, where the first column is the REML, i.e. the random effect maximum likelihood. Notice especially that the REML in model 2 starts where model 1 terminates:
> x <- lmer(frm, data=iris,
+ verbose=TRUE, control=list(maxIter=1), model=FALSE)
0: 264.60572: 0.230940 0.0747853 0.00000
1: 204.22878: 0.518239 1.01025 0.205835
1: 204.22878: 0.518239 1.01025 0.205835
> # Capture starting values for next set of iterations
> start <- list(ST=x@ST)
> # Update model
> twoStep <- lmer(frm, data=iris,
+ verbose=TRUE, control=list(maxIter=100), model=TRUE,
+ start=start)
0: 204.22878: 0.518239 1.01025 0.205835
1: 201.51667: 0.610272 2.00277 0.286049
2: 201.46706: 0.849203 1.94906 0.358809
3: 201.44614: 0.932371 1.88581 0.482423
4: 201.39421: 1.00909 1.71078 0.871824
5: 201.36543: 1.00643 1.60453 1.01663
6: 201.31066: 1.00208 1.35520 1.27524
7: 201.28458: 1.08227 1.22335 1.35147
8: 201.24330: 1.50333 0.679759 1.31698
9: 201.11881: 1.95760 0.329767 0.936047
但是,当我使用不同的maxIters
值时,它将不再起作用:
However, when I have a different value of maxIters
this no longer works:
x <- lmer(frm, data=iris,
verbose=TRUE, control=list(maxIter=3), model=FALSE)
start <- list(ST=x@ST)
twoStep <- lmer(frm, data=iris,
verbose=TRUE, control=list(maxIter=100), model=TRUE,
start=start)
请注意, REML值将以264 重新开始,即开头:
Notice that the REML value restarts at 264, i.e. the beginning:
> x <- lmer(frm, data=iris,
+ verbose=TRUE, control=list(maxIter=3), model=FALSE)
0: 264.60572: 0.230940 0.0747853 0.00000
1: 204.22878: 0.518238 1.01025 0.205835
2: 201.94075: 0.00000 1.51757 -1.18259
3: 201.71473: 0.00000 1.69036 -1.89803
3: 201.71473: 0.00000 1.69036 -1.89803
> # Capture starting values for next set of iterations
> start <- list(ST=x@ST)
> # Update model
> twoStep <- lmer(frm, data=iris,
+ verbose=TRUE, control=list(maxIter=100), model=TRUE,
+ start=start)
0: 264.60572: 0.230940 0.0747853 0.00000
1: 204.22878: 0.518238 1.01025 0.205835
2: 201.94075: 0.00000 1.51757 -1.18259
3: 201.71473: 0.00000 1.69036 -1.89803
4: 201.64641: 0.00000 1.82159 -2.44144
5: 201.63698: 0.00000 1.88282 -2.69497
6: 201.63649: 0.00000 1.89924 -2.76298
7: 201.63649: 4.22291e-08 1.90086 -2.76969
8: 201.63649: 4.22291e-08 1.90086 -2.76969
问题:如何使用从先前拟合的模型获得的起始值可靠地重新启动lmer()
?
Question: How can I reliably restart lmer()
with start values obtained from a previously fitted model?
会话信息:
packageVersion("lme4")
[1] ‘0.999999.2’
推荐答案
这是lme4中的一个已确认的错误,并根据注释
This was a confirmed bug in lme4 and as per the comments
我已经在github.com/lme4/lme4/issues/55 – Andrie 13年7月2日在15:42记录了一个问题
I've logged an issue at github.com/lme4/lme4/issues/55 – Andrie Jul 2 '13 at 15:42
现在应该为lmer修复此问题(尽管对于glmer则不是,这有点棘手). –本·博克(Ben Bolker)7月14日
This should be fixed now for lmer (although not for glmer, which is slightly trickier). – Ben Bolker Jul 14
当版本为< 0.99999911-6; 在CRAN上的lme4 的版本>从2013年9月21日开始为1.0-4.
That was back when the version was < 0.99999911-6; lme4 on CRAN has had versions > 1.0-4 since 21-Sep-2013.
这篇关于用先前的估计值重新开始混合效应模型的估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!