raise iterations

2,041 views
Skip to first unread message

Paul Johnson

unread,
Apr 30, 2013, 7:05:05 PM4/30/13
to lav...@googlegroups.com
Hello, Yves and others:

I'm doing consulting, we are running into a problem with lavaan fitting, fails to converge.  How do we use the control list?

As you see here, I've tried to use control to raise the allowed number to a ridiculously high value, but it is ignored, lavaan still stops at 250.

What's up with that?

> fit1 <- lavaan(model=mod1, data=dat, meanstructure=TRUE, control = list(eval.max = 40000,
+                                                          iter.max = 200000))
Warning message:
In lavaan(model = mod1, data = dat, meanstructure = TRUE, control = list(eval.max = 40000,  :
  lavaan WARNING: model has NOT converged!
> summary(fit1)
** WARNING ** lavaan (0.5-12) did NOT converge after 250 iterations
** WARNING ** Estimates below are most likely unreliable

  Number of observations                           823

  Estimator                                         ML

....

> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8   
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8  
 [7] LC_PAPER=C                 LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] rockchalk_1.7.5.1 car_2.0-16        nnet_7.3-6        lavaan_0.5-12   
[5] quadprog_1.5-5    pbivnorm_0.5-1    mnormt_1.4-5      boot_1.3-7      
[9] MASS_7.3-23     

loaded via a namespace (and not attached):
[1] compiler_2.15.3 stats4_2.15.3   tools_2.15.3  

Paul Johnson
University of Kansas
http://pj.freefaculty.org
Message has been deleted

Paul Johnson

unread,
May 2, 2013, 5:22:45 PM5/2/13
to lav...@googlegroups.com


On Thursday, May 2, 2013 9:22:18 AM UTC-5, Yves Rosseel wrote:
On 05/01/2013 01:05 AM, Paul Johnson wrote:
> Hello, Yves and others:
>
> I'm doing consulting, we are running into a problem with lavaan fitting,
> fails to converge.  How do we use the control list?

The control list can be used to pass arguments directly to the optimizer
(nlminb by default). For example, control=list(iter.max=500)

> As you see here, I've tried to use control to raise the allowed number
> to a ridiculously high value, but it is ignored, lavaan still stops at 250.
>
> What's up with that?
>
>  > fit1 <- lavaan(model=mod1, data=dat, meanstructure=TRUE, control =
> list(eval.max = 40000,
> +                                                          iter.max =
> 200000))
> Warning message:
> In lavaan(model = mod1, data = dat, meanstructure = TRUE, control =
> list(eval.max = 40000,  :
>    lavaan WARNING: model has NOT converged!
>  > summary(fit1)
> ** WARNING ** lavaan (0.5-12) did NOT converge after 250 iterations

I don't think it has been ignored. The optimizer simply gave up after
250 iterations. If you run the problem with verbose=TRUE, you will see
the 'optimizer message' at the end, saying why it gave up.

Try this:

# normal run
example(cfa)

# do only 5 iterations
fit <- cfa(HS.model, data=HolzingerSwineford1939,
control=list(iter.max=5), verbose=TRUE)

You have the message at the end:

nlminb message says:  iteration limit reached without convergence (10)
number of iterations:  5


Yves.

Oh, you mean that even if I request 1,000,000 iterations, nlminb will refuse for its own reasons, and it does not matter at all what I put in the lavaan command. That makes sense, given what I see here.  But, on the other hand, there is no indication that nlminb noticed that I ask for a lot more iterations. See what I mean? (paste below).

But I'd still like to know what people do in a case like this.  Yesterday I put in another post in the forum pointing out that this same thing does converge if we set mimic="Mplus", sooner or later I hope I will understand if that means Mplus is giving a wrong answer or the default format is not workable :)

Here's what I see:
> library(lavaan)
> fit1 <- lavaan(model = mod1, data = dat, meanstructure = TRUE, control =
+                list(eval.max = 40000, iter.max = 200000), verbose = TRUE)
init cin0 values:  
init ceq0 values:  0 0 8.792597 4.941128
init slack values:  0.1 0.1 0.1 0.1
init inactive idx:  
init con0 values:  0 0 8.792597 4.941128
K = max con0:  8.792597
Objective function  = 5.4368258821

Starting inner optimization [ 1 ]:
lambda:  10 10 10 10
mu:  11.3732
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258821
Objective function  = 5.4368258820
Objective function  = 5.4368258819
Objective function  = 5.4368258816
Objective function  = 5.4368258808
Objective function  = 5.4368258777
Objective function  = 5.4368258651
Objective function  = 5.4368258149
Objective function  = 5.4368256140
Objective function  = 5.4368248103
Objective function  = 5.4368215957
Objective function  = 5.4368087401
Objective function  = 5.4367573634
Objective function  = 5.4365525839
Objective function  = 5.4357451036
Objective function  = 5.4327011399
Objective function  = 5.4234851428
Objective function  = 5.4330095922
Objective function  = 6.1560680843
Objective function  = 17.2454181040
Objective function  =          Inf
Objective function  = 15.7759485313
Objective function  = 16.9066252312
Objective function  = 20.6509973695
Objective function  = 8.9515694481
Objective function  = 13.4866939731
Objective function  = 7.4009536504
Objective function  = 7.5554213915
Objective function  = 6.4464780087
Objective function  = 5.8019038366
Objective function  = 6.5931784508
Objective function  = 6.2291681423
Objective function  = 5.4949646802
Objective function  = 5.3003950938
Objective function  = 4.7466319661
Objective function  = 4.1811630261
Objective function  = 3.9110500331
Objective function  = 4.0394730231
Objective function  = 3.5716883289
Objective function  = 3.4240568418
Objective function  = 3.1132523411
Objective function  = 3.1058530023
Objective function  = 2.9437713477
Objective function  = 2.8490778165
Objective function  = 2.7069251781
Objective function  = 2.5912558691
Objective function  = 2.5341873822
Objective function  = 2.3744888564
Objective function  = 2.3031247646
Objective function  = 2.1889324584
Objective function  = 2.1481082439
Objective function  = 2.0109400532
Objective function  = 1.9442192596
Objective function  = 1.8498917813
Objective function  = 1.8476346537
Objective function  = 1.7143432963
Objective function  = 1.7101853349
Objective function  = 1.6437593793
Objective function  = 1.6090542721
Objective function  = 1.5610361457
Objective function  = 1.5304142159
Objective function  = 1.5112938936
Objective function  = 1.3019243750
Objective function  = 1.2220961501
Objective function  = 1.1428204768
Objective function  = 1.0190344906
Objective function  = 0.9530631773
Objective function  = 0.9444191233
Objective function  = 1.1161544863
Objective function  = 0.8654118975
Objective function  = 0.8578886679
Objective function  = 0.8160645740
Objective function  = 0.7940941771
Objective function  = 0.7787785856
Objective function  = 0.7628698322
Objective function  = 0.7483324817
Objective function  = 0.7267670623
Objective function  = 0.7019134389
Objective function  = 0.6880352669
Objective function  = 0.6634308308
Objective function  = 0.6517228757
Objective function  = 0.6355319307
Objective function  = 0.6345147901
Objective function  = 0.6330962140
Objective function  = 0.6258033995
Objective function  = 0.6097981346
Objective function  = 0.6051929699
Objective function  = 0.6006655926
Objective function  = 0.5959245401
Objective function  = 0.5907494520
Objective function  = 0.5858821920
Objective function  = 0.5823403093
Objective function  = 0.5763371966
Objective function  = 0.5662795354
Objective function  = 0.5539521007
Objective function  = 0.5434686132
Objective function  = 0.5321662933
Objective function  = 0.5202363218
Objective function  = 0.5079087294
Objective function  = 0.4962570999
Objective function  = 0.4836886982
Objective function  = 0.4716106646
Objective function  = 0.4599568890
Objective function  = 0.4494926908
Objective function  = 0.4364658774
Objective function  = 0.4269336252
Objective function  = 0.4171669974
Objective function  = 0.4051224186
Objective function  = 0.3956420751
Objective function  = 0.3857528316
Objective function  = 0.3752110374
Objective function  = 0.3639618891
Objective function  = 0.3536858804
Objective function  = 0.3426979201
Objective function  = 0.3294062044
Objective function  = 0.3204905011
Objective function  = 0.3061291201
Objective function  = 0.2836194447
Objective function  = 0.2681793307
Objective function  = 0.2815026444
Objective function  = 0.2620355067
Objective function  = 0.2581497041
Objective function  = 0.2562415558
Objective function  = 0.2564441393
Objective function  = 0.2567182032
Objective function  = 0.2558220794
Objective function  = 0.2553181080
Objective function  = 0.2549874224
Objective function  = 0.2547902959
Objective function  = 0.2546645301
Objective function  = 0.2545588816
Objective function  = 0.2545121275
Objective function  = 0.2544718192
Objective function  = 0.2544511638
Objective function  = 0.2544431087
Objective function  = 0.2544238228
Objective function  = 0.2544156577
Objective function  = 0.2544063757
Objective function  = 0.2544140066
Objective function  = 0.2544056038
Objective function  = 0.2543991483
Objective function  = 0.2543974733
Objective function  = 0.2543973046
Objective function  = 0.2543969524
Objective function  = 0.2543969477
Objective function  = 0.2543968468
Objective function  = 0.2543967682
Objective function  = 0.2543967825
Objective function  = 0.2543967523
Objective function  = 0.2543967491
Objective function  = 0.2543967494
Objective function  = 0.2543967488
Objective function  = 0.2543967445
Objective function  = 0.2543967431
Objective function  = 0.2543967431
cin0 values:  
ceq0 values:  0.8792582 0.8792586 0.8792619 0.879261
active threshold:  0.8792597 0.8792597 0.8792597 0.8792597
inactive idx:  
con0 values:  0.8792582 0.8792586 0.8792619 0.879261
K = max con0:  0.8792619  Kprev =  8.792597

Starting inner optimization [ 2 ]:
lambda:  1.623907e-05 1.219238e-05 -2.511793e-05 -1.46067e-05
mu:  11.3732
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967431
Objective function  = 0.2543967432
Objective function  = 0.2543967439
Objective function  = 0.2543967574
Objective function  = 0.2543969778
Objective function  = 0.2544005238
Objective function  = 0.2544573676
Objective function  = 0.2553690544
Objective function  = 0.2700782225
Objective function  = 0.5134127129
Objective function  = 2.0266394172
Objective function  = 3.2066120331
Objective function  = 1.5872213932
Objective function  = 1.8787206269
Objective function  = 1.5386204344
Objective function  = 1.8872993550
Objective function  = 1.6894403081
Objective function  = 1.3529445838
Objective function  = 1.4492129238
Objective function  = 1.4742795902
Objective function  = 1.3660843295
Objective function  = 1.3465754529
Objective function  = 1.2611605764
Objective function  = 1.2124848910
Objective function  = 1.1445132237
Objective function  = 1.0909497870
Objective function  = 1.0213093357
Objective function  = 1.0155212551
Objective function  = 1.0062838999
Objective function  = 0.9315113762
Objective function  = 0.8702791655
Objective function  = 0.8589805591
Objective function  = 0.7821203875
Objective function  = 0.7690589724
Objective function  = 0.7325698741
Objective function  = 0.6918211718
Objective function  = 0.6883333240
Objective function  = 0.6355892337
Objective function  = 0.6024364624
Objective function  = 0.5743726838
Objective function  = 0.5555300542
Objective function  = 0.5261852850
Objective function  = 0.4927626416
Objective function  = 0.4701431031
Objective function  = 0.4579368981
Objective function  = 0.4280178260
Objective function  = 0.4030488753
Objective function  = 0.3916718690
Objective function  = 0.3667293652
Objective function  = 0.3533394607
Objective function  = 0.3338885253
Objective function  = 0.3195837720
Objective function  = 0.3078471726
Objective function  = 0.2945289171
Objective function  = 0.2874019421
Objective function  = 0.2813316085
Objective function  = 0.2717661919
Objective function  = 0.2678045329
Objective function  = 0.2687961329
Objective function  = 0.2647322724
Objective function  = 0.2610267256
Objective function  = 0.2599839875
Objective function  = 0.2600213582
Objective function  = 0.2613339790
Objective function  = 0.2589664442
Objective function  = 0.2583382708
Objective function  = 0.2577567894
Objective function  = 0.2574270018
Objective function  = 0.2569726748
Objective function  = 0.2566634263
Objective function  = 0.2557081097
Objective function  = 0.2551741167
Objective function  = 0.2557466046
Objective function  = 0.2548981463
Objective function  = 0.2549347262
Objective function  = 0.2547332726
Objective function  = 0.2546390873
Objective function  = 0.2545954690
Objective function  = 0.2546008111
Objective function  = 0.2546596306
Objective function  = 0.2545730329
Objective function  = 0.2545462344
Objective function  = 0.2545250678
Objective function  = 0.2544994269
Objective function  = 0.2544836620
Objective function  = 0.2545178274
Objective function  = 0.2544808075
Objective function  = 0.2544737502
Objective function  = 0.2544702851
Objective function  = 0.2544620862
Objective function  = 0.2544514877
Objective function  = 0.2544458883
Objective function  = 0.2544218692
Objective function  = 0.2544692764
Objective function  = 0.2544060395
Objective function  = 0.2544121059
Objective function  = 0.2544038650
Objective function  = 0.2544023298
Objective function  = 0.2544005887
Objective function  = 0.2543997579
Objective function  = 0.2543990944
Objective function  = 0.2543984993
Objective function  = 0.2543978598
Objective function  = 0.2543978975
Objective function  = 0.2543977479
Objective function  = 0.2543970953
Objective function  = 0.2543969028
Objective function  = 0.2543968449
Objective function  = 0.2543969458
Objective function  = 0.2543968510
Objective function  = 0.2543968124
Objective function  = 0.2543967891
Objective function  = 0.2543967761
Objective function  = 0.2543967674
Objective function  = 0.2543967599
Objective function  = 0.2543967579
Objective function  = 0.2543967493
Objective function  = 0.2543967470
Objective function  = 0.2543967460
Objective function  = 0.2543967441
Objective function  = 0.2543967430
Objective function  = 0.2543967438
Objective function  = 0.2543967427
Objective function  = 0.2543967425
Objective function  = 0.2543967425
Objective function  = 0.2543967424
Objective function  = 0.2543967423
Objective function  = 0.2543967423
Objective function  = 0.2543967423
Objective function  = 0.2543967422
Objective function  = 0.2543967422
cin0 values:  
ceq0 values:  1.316035e-06 9.917957e-07 -2.345261e-06 -1.211035e-06
active threshold:  1.427836e-06 1.072027e-06 -2.208518e-06 -1.284308e-06
inactive idx:  
con0 values:  1.316035e-06 9.917957e-07 -2.345261e-06 -1.211035e-06
K = max con0:  2.345261e-06  Kprev =  0.8792619

Starting inner optimization [ 3 ]:
lambda:  1.271526e-06 9.12486e-07 1.555208e-06 -8.333489e-07
mu:  11.3732
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
cin0 values:  
ceq0 values:  1.316035e-06 9.917957e-07 -2.345261e-06 -1.211035e-06
active threshold:  1.118001e-07 8.023121e-08 1.367432e-07 -7.327301e-08
inactive idx:  
con0 values:  1.316035e-06 9.917957e-07 -2.345261e-06 -1.211035e-06
K = max con0:  2.345261e-06  Kprev =  2.345261e-06

Starting inner optimization [ 4 ]:
lambda:  1.271526e-06 9.12486e-07 1.555208e-06 -8.333489e-07
mu:  113.732
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
cin0 values:  
ceq0 values:  1.316035e-06 9.917956e-07 -2.34526e-06 -1.211035e-06
active threshold:  1.118001e-08 8.023121e-09 1.367432e-08 -7.327301e-09
inactive idx:  
con0 values:  1.316035e-06 9.917956e-07 -2.34526e-06 -1.211035e-06
K = max con0:  2.34526e-06  Kprev =  2.345261e-06

Starting inner optimization [ 5 ]:
lambda:  1.271526e-06 9.12486e-07 1.555208e-06 -8.333489e-07
mu:  1137.32
Objective function  = 0.2543967422
Objective function  = 0.2543967422
Objective function  = 0.2543967422
cin0 values:  
ceq0 values:  1.316035e-06 9.917956e-07 -2.34526e-06 -1.211035e-06
active threshold:  1.118001e-09 8.023121e-10 1.367432e-09 -7.327301e-10
inactive idx:  
con0 values:  1.316035e-06 9.917956e-07 -2.34526e-06 -1.211035e-06
K = max con0:  2.34526e-06  Kprev =  2.345261e-06
convergence status (0=ok):  11
nlminb.constr message says:  Convergence due to lack of progress in parameter updates
number of outer iterations:  5
number of inner iterations:  250
number of function evaluations [objective, gradient]:  325 252

yrosseel

unread,
May 3, 2013, 8:15:31 AM5/3/13
to lav...@googlegroups.com
On 05/02/2013 11:22 PM, Paul Johnson wrote:
> Oh, you mean that even if I request 1,000,000 iterations, nlminb will
> refuse for its own reasons, and it does not matter at all what I put in
> the lavaan command.

Indeed. To decide when to stop, nlminb() uses a couple of 'stopping
tolerances' (see http://netlib.bell-labs.com/cm/cs/cstr/153.pdf section
page 7). Which can be tweaked. But tweaking them is an art.

My general impression is that the stopping tolerances used by commercial
SEM packages are slightly more liberal, compared to the ones used (by
default) in lavaan. I'm not sure if this is a good thing or not.

> the other hand, there is no indication that nlminb noticed that I ask
> for a lot more iterations. See what I mean? (paste below).

The number of iterations are merely an upper limit.

> Yesterday I put in another post in the forum pointing out that this same
> thing does converge if we set mimic="Mplus", sooner or later I hope I
> will understand if that means Mplus is giving a wrong answer or the
> default format is not workable :)

To answer this, we would need more diagnostics about the quality of the
'solution': are all the elements of the gradient small enough? What are
the charateristics of the parameter-surface around the solution, etc...
Another thing on my TODO list.

Yves.

yrosseel

unread,
May 2, 2013, 10:22:18 AM5/2/13
to lav...@googlegroups.com
On 05/01/2013 01:05 AM, Paul Johnson wrote:
> Hello, Yves and others:
>
> I'm doing consulting, we are running into a problem with lavaan fitting,
> fails to converge. How do we use the control list?

The control list can be used to pass arguments directly to the optimizer
(nlminb by default). For example, control=list(iter.max=500)

> As you see here, I've tried to use control to raise the allowed number
> to a ridiculously high value, but it is ignored, lavaan still stops at 250.
>
> What's up with that?
>
> > fit1 <- lavaan(model=mod1, data=dat, meanstructure=TRUE, control =
> list(eval.max = 40000,
> + iter.max =
> 200000))
> Warning message:
> In lavaan(model = mod1, data = dat, meanstructure = TRUE, control =
> list(eval.max = 40000, :
> lavaan WARNING: model has NOT converged!
> > summary(fit1)
> ** WARNING ** lavaan (0.5-12) did NOT converge after 250 iterations

Reply all
Reply to author
Forward
0 new messages