lavaan是否从EM算法开始,然后过渡到准牛顿法?

时间:2019-05-07 15:31:44

标签: r optimization factor-analysis r-lavaan

当我使用FIML在lavaan中执行以下CFA时,该算法似乎首先使用EM,然后使用NLMINB(准牛顿)。我想我知道如何使用control参数来控制NLMINB优化的各个方面,但是我不知道如何或是否可以控制EM部分。这是一个例子。

library(lavaan)
library(MASS)

set.seed(23)

N = 1000

cov = cbind(c(2,0.5),c(0.5,1))

s = mvrnorm(n=N, mu=c(0, 0), Sigma=cov)

m1 = 0.5 + 1*s[, 1] + rnorm(sd=2, n=N)
m2 = 2 + 1*s[, 2] + rnorm(sd=1.5, n=N)
m3 = -3 + 2*s[, 1] -4*s[, 2] + rnorm(sd=4, n=N)
m4 = -1 + 1.5*s[, 1] + 2*s[, 2] + rnorm(sd=0.5, n=N)
m5 = 3 - 1*s[, 1] + 1*s[, 2] + rnorm(sd=3, n=N)
m6 = 2 + 1.2*s[, 1] + 5*s[, 2] + rnorm(sd=1, n=N)

M = data.frame(cbind(m1, m2, m3, m4, m5, m6))
M[1:N/2, 1] = NaN
M[(N/2):N, 2] = NaN

cfa.model <- '
f1 =~ 1*m1 + m3 + m4 + m5 + m6
f2 =~ 1*m2 + m3 + m4 + m5 + m6
f1 ~ f2
'

fcols = c('f1', 'f2')

K = length(fcols)
J = dim(M)[2]

cfa.fit = cfa(cfa.model, data=M, verbose=T, missing='fiml')

lav_mvnorm_missing_h1_estimate_moments: start EM steps
  EM iteration:    0  fx =    18.3174217817 
  EM iteration:    1  fx =    15.6282551073  delta par =  19.11017973 
  EM iteration:    2  fx =    15.5451600829  delta par =  1.44838250 
  EM iteration:    3  fx =    15.5164722286  delta par =  0.76379400 
  EM iteration:    4  fx =    15.5073993955  delta par =  0.40644568 
  EM iteration:    5  fx =    15.5047273405  delta par =  0.21650406 
  EM iteration:    6  fx =    15.5039730261  delta par =  0.11529083 
  EM iteration:    7  fx =    15.5037645370  delta par =  0.06137652 
  EM iteration:    8  fx =    15.5037073934  delta par =  0.03267151 
  EM iteration:    9  fx =    15.5036917538  delta par =  0.01739197 
  EM iteration:   10  fx =    15.5036874644  delta par =  0.00925903 
  EM iteration:   11  fx =    15.5036862834  delta par =  0.00492977 
  EM iteration:   12  fx =    15.5036859567  delta par =  0.00262500 
  EM iteration:   13  fx =    15.5036858659  delta par =  0.00139788 
  EM iteration:   14  fx =    15.5036858406  delta par =  0.00074446 
  EM iteration:   15  fx =    15.5036858335  delta par =  0.00039650 
  EM iteration:   16  fx =    15.5036858315  delta par =  0.00021118 
  EM iteration:   17  fx =    15.5036858309  delta par =  0.00011248 
  EM iteration:   18  fx =    15.5036858307  delta par =  0.00005991 
  EM iteration:   19  fx =    15.5036858307  delta par =  0.00003191 
  EM iteration:   20  fx =    15.5036858307  delta par =  0.00001700 
  EM iteration:   21  fx =    15.5036858307  delta par =  0.00000906 
  EM iteration:   22  fx =    15.5036858307  delta par =  0.00000482 
  EM iteration:   23  fx =    15.5036858307  delta par =  0.00000257 
  EM iteration:   24  fx =    15.5036858307  delta par =  0.00000137 
  EM iteration:   25  fx =    15.5036858307  delta par =  0.00000073 

Sigma:
           [,1]       [,2]      [,3]       [,4]        [,5]       [,6]
[1,]  6.0799427   1.454745  4.174588 -1.8771549   5.3453480  0.5556121
[2,]  1.4547451  30.295454 -4.094796 -3.4055107 -14.1147626 -3.3789417
[3,]  4.1745879  -4.094796 11.996882 -1.6843854  19.1101797  2.9004991
[4,] -1.8771549  -3.405511 -1.684385 10.3429869  -0.3690654 -0.2135262
[5,]  5.3453480 -14.114763 19.110180 -0.3690654  36.1675277  5.9716330
[6,]  0.5556121  -3.378942  2.900499 -0.2135262   5.9716330  3.3292615

Mu:
[1]  0.4809515 -3.0504037 -1.0852005  2.9048318  1.9060771  2.0361792

Quasi-Newton steps using NLMINB:
Objective function  = 1.7888525861901217
Objective function  = 0.9851575525661351
Objective function  = 0.7268540538683199
Objective function  = 0.2557896906942654
Objective function  = 0.7584160209525388
Objective function  = 0.2684653920239848
Objective function  = 0.1621520991171366
Objective function  = 0.1107424088803395
Objective function  = 0.1296883105884570
Objective function  = 0.0940788568119677
Objective function  = 0.0864652417773026
Objective function  = 0.0721041765085504
Objective function  = 0.0633494325628670
Objective function  = 0.0536747272719555
Objective function  = 0.0502247477693007
Objective function  = 0.0413637133003633
Objective function  = 0.0379406459862457
Objective function  = 0.0320174820525629
Objective function  = 0.0289101640770371
Objective function  = 0.0270354297037469
Objective function  = 0.0249629540989424
Objective function  = 0.0218359256938889
Objective function  = 0.0189369273140114
Objective function  = 0.0151031226656801
Objective function  = 0.0122718907717312
Objective function  = 0.0092584807074578
Objective function  = 0.0088751763044188
Objective function  = 0.0076123912076485
Objective function  = 0.0072493252272530
Objective function  = 0.0068247176958316
Objective function  = 0.0060616745422601
Objective function  = 0.0056170211463220
Objective function  = 0.0052462215041258
Objective function  = 0.0050492301407967
Objective function  = 0.0049205710553393
Objective function  = 0.0048659503391200
Objective function  = 0.0047987479162090
Objective function  = 0.0047462742914490
Objective function  = 0.0047077661522730
Objective function  = 0.0046831461851964
Objective function  = 0.0046626232584908
Objective function  = 0.0046420155019389
Objective function  = 0.0046148542070785
Objective function  = 0.0045882334071630
Objective function  = 0.0045639326820144
Objective function  = 0.0045483001134041
Objective function  = 0.0045363191382677
Objective function  = 0.0045248956450150
Objective function  = 0.0045110841388443
Objective function  = 0.0045045565114492
Objective function  = 0.0045006776349314
Objective function  = 0.0044984370789782
Objective function  = 0.0044953995539645
Objective function  = 0.0044928442197820
Objective function  = 0.0044905504696340
Objective function  = 0.0044897178432395
Objective function  = 0.0044890460805611
Objective function  = 0.0044885013990150
Objective function  = 0.0044879390368715
Objective function  = 0.0044876121320216
Objective function  = 0.0044873608054701
Objective function  = 0.0044870882203005
Objective function  = 0.0044864608711661
Objective function  = 0.0044854094744728
Objective function  = 0.0044834872439443
Objective function  = 0.0044816758042803
Objective function  = 0.0044804928677538
Objective function  = 0.0044803025628157
Objective function  = 0.0044802822439056
Objective function  = 0.0044802750925212
Objective function  = 0.0044802743608985
Objective function  = 0.0044802732265765
Objective function  = 0.0044802730781361
Objective function  = 0.0044802729972568
Objective function  = 0.0044802729735727
Objective function  = 0.0044802729459699
Objective function  = 0.0044802729251341
Objective function  = 0.0044802729060658
Objective function  = 0.0044802728936952
Objective function  = 0.0044802728880020
Objective function  = 0.0044802728859707
Objective function  = 0.0044802728850044
Objective function  = 0.0044802728842646
Objective function  = 0.0044802728836046
Objective function  = 0.0044802728834483
Objective function  = 0.0044802728834483
convergence status (0=ok):  0 
nlminb message says:  relative convergence (4) 
number of iterations:  79 
number of function evaluations [objective, gradient]:  85 80 
Computing VCOV for se = standard ... done.
Computing TEST for test = standard ... done.

因此很明显,EM是在NLMINB之前完成的。所以,首先我想知道为什么。其次,我可以修改有关此初始EM步骤的任何内容吗?我尝试使用em参数,例如em.fx.tolem.iter.maxem.dx.tol,但没有任何效果。

cfa.fit = cfa(cfa.model, data=M, verbose=T, missing='fiml', em.iter.max=5, optim.method='em')

cfa.fit = cfa(cfa.model, data=M, verbose=T, missing='fiml', em.iter.max=5)

但无论哪种情况,EM迭代都超过5。

0 个答案:

没有答案