Начинается ли Lavaan с EM-алгоритма, а затем переходит к квазиньютоновскому методу? - PullRequest
1 голос
/ 07 мая 2019

Когда я выполняю следующий CFA в lavaan, используя FIML, кажется, что алгоритм сначала использует EM, а затем NLMINB (квазиньютон).Я думаю, что знаю, как управлять аспектами оптимизации NLMINB, используя аргумент control, но я не знаю, как или могу ли я контролировать часть 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.tol, em.iter.max и em.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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...