Specifying multiple chains in runmlwin

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
duyvh0309
Posts: 1
Joined: Fri Jun 19, 2020 1:02 pm

Specifying multiple chains in runmlwin

Post by duyvh0309 »

Is it possible to specify a definite number of chains (eg 3 as in WinBugs) or have I missed something here (I do not seem to find that option in the help file).

If this is not possible at the moment, could it be incorporated in a future update?

ChrisCharlton
Posts: 1174
Joined: Mon Oct 19, 2009 10:34 am

Re: Specifying multiple chains in runmlwin

Post by ChrisCharlton »

Some years ago (2012) I wrote the attached prefix command to allow this. This works as follows:

Code: Select all

. use http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial, clear

// Calculate IGLS estimates
. runmlwin normexam cons standlrt, level2(school: cons) level1(student: cons) nopause
 
MLwiN 3.05 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Run time (seconds)   =       0.64
Number of iterations =          4
Log likelihood       = -4678.6211
Deviance             =  9357.2423
------------------------------------------------------------------------------
    normexam |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |   .0023908   .0400224    0.06    0.952    -.0760516    .0808332
    standlrt |   .5633712   .0124654   45.19    0.000     .5389395    .5878029
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |   .0921275   .0181475      .0565591     .127696
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |    .565731   .0126585      .5409208    .5905412
------------------------------------------------------------------------------

// Set initial values for each chain
. marixt a = e(b)
. matrix b = a
. matrix b[1,1] = 1
. matrix b[1,2] = 0

// Run two MCMC chains
. multichain, inits(a b) : runmlwin normexam cons standlrt, level2(school: cons) level1(student: cons) nopause mcmc(on)
 
MLwiN 3.05 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: MCMC

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Burnin                     =        500
Chain                      =       5000
Thinning                   =          1
Run time (seconds)         =       2.52
Deviance (dbar)            =    9208.82
Deviance (thetabar)        =    9148.97
Effective no. of pars (pd) =      59.85
Bayesian DIC               =    9268.66
------------------------------------------------------------------------------
    normexam |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
-------------+----------------------------------------------------------------
        cons |   .0013325   .0421552      231   0.498    -.0776169    .0851904
    standlrt |   .5633124   .0125354     3916   0.000     .5389242    .5879933
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |     Mean   Std. Dev.   ESS     [95% Cred. Int]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |  .0973183    .02049   2828    .064413  .1445396
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |   .566342  .0126871   4913   .5417516  .5919709
------------------------------------------------------------------------------
 
MLwiN 3.05 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: MCMC

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Burnin                     =        500
Chain                      =       5000
Thinning                   =          1
Run time (seconds)         =       2.55
Deviance (dbar)            =    9208.82
Deviance (thetabar)        =    9148.97
Effective no. of pars (pd) =      59.85
Bayesian DIC               =    9268.66
------------------------------------------------------------------------------
    normexam |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
-------------+----------------------------------------------------------------
        cons |   .0013325   .0421552      231   0.498    -.0776169    .0851904
    standlrt |   .5633124   .0125354     3916   0.000     .5389242    .5879933
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |     Mean   Std. Dev.   ESS     [95% Cred. Int]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |  .0973183    .02049   2828    .064413  .1445396
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |   .566342  .0126871   4913   .5417516  .5919709
------------------------------------------------------------------------------

------------------------------------------------------------------------------

// View BGRD chain diagnostic statistics
. matrix list e(B)

e(B)[50,5]
            c1         c2         c3         c4         c5
 r1  .68312595  .90853652  .66988518          1  .89335015
 r2  .86865761  .85725696  .78779448  .84521799  .89912244
 r3  .63704335  .88245776   .9247912  .86091557  .97551593
 r4  .84370954  .93449771  .96733374   .8759235          1
 r5  .83405644  .95183309  .85799606  .85031875  .97656503
 r6  .77426206  .96488972  .97007375  .83159597  .94610829
 r7  .77143619  .97590778  .93838636  .90190146  .96340224
 r8  .91696743  .95456751  .92843793  .88465285  .89936638
 r9  .90889663  .93957942  .91578903  .91070369  .90409696
r10  .88152578  .93352143  .92117261  .89344572  .93379132
r11  .94128104  .94979551  .88802576  .90920454  .94776854
r12  .98963776   .9436568  .94183538  .89448601  .98053606
r13   .9890268  .95505598  .92410598  .89808515   .9654266
r14  .97916654  .92077325  .95289945  .83771801  .96452346
r15  .95969275  .93558309  .98227608  .85861366  .98866983
r16   .9564121  .95273079          1  .83976709  .98640838
r17   .9263212  .95098222  .98315353  .82897806  .97236178
r18  .96380475  .99339601  .99112007  .83673284  .96734216
r19  .93214756   .9892982  .99710081  .83657257  .96524194
r20  .92704177          1  .98752697    .840676  .96292449
r21   .9181922  .98211587  .96542091  .81403764  .94933014
r22  .89683505  .96929849  .96396541  .82646991  .95418784
r23  .89567849   .9744663  .95970879  .83543102  .94077036
r24  .97790538  .97710633  .93589856   .8325902  .93537604
r25          1  .97717387  .94084741  .83366974  .94771623
r26  .96963299  .97864399   .9375304  .83301659  .98058815
r27  .98512509  .98541914  .95111151  .82273098  .98733189
r28  .97291157  .98527241  .93713958  .83048939  .97757965
r29  .96463046  .98555601  .92480512  .83575957  .97806024
r30  .97857776  .98547216   .9181192  .83375707   .9872912
r31  .94022924  .99932102  .90347215  .83434075  .96734477
r32  .93624259  .98734162  .88829033  .83562247  .97107828
r33    .935888  .98323383  .89002474   .8388123  .97282132
r34  .94972379  .97877628  .88931543  .83764901  .98147281
r35  .94227877   .9729062  .89389733  .83277332  .98514667
r36  .93290188  .97072354  .89915205  .82256063  .98734845
r37  .92793113  .97312987  .88881788  .82354643  .98287803
r38  .92374571  .97257836  .89075306  .83178934  .97981903
r39  .92138725  .96958508  .89875126  .82689697  .99140713
r40   .9270285  .97041147  .91303689  .82380599  .98657834
r41  .94891758  .97531873  .92620253  .82525914  .98537213
r42  .94594285   .9774906  .92205555  .83692778  .98200437
r43  .94119867  .97914768  .92535077  .83014407  .98183481
r44  .94922741  .97590293  .91777847  .81714741  .97583516
r45   .9556429  .97160832  .92717421  .81338762  .96798884
r46  .94749008   .9719681  .92130528  .81175387  .96510935
r47  .93098163  .97453717  .92793077  .81639806  .96560206
r48  .94409834  .97184296  .92220685  .82454819  .96859932
r49  .93395776  .97071187  .92164257  .82670081  .96161723
r50   .9317145  .97068156  .92179625  .81885461  .95574872

. matrix list e(W)

e(W)[50,5]
            c1         c2         c3         c4         c5
 r1  .67784327   .9061853  .66458309  .95714947  .86176844
 r2  .82633676  .85385374  .78118426  .82557172  .88954643
 r3  .62980765  .87805939  .91802044  .83871255  .95191217
 r4  .83830291  .92336418  .94811598  .86191108  .99598349
 r5  .82621858  .94387279  .85418101  .83866948  .97469082
 r6  .76872092  .96267856  .96760509  .81871255  .94555479
 r7  .77080953  .96930449  .93533128  .90037464   .9614946
 r8  .91629569  .94677987  .92594066  .88066947  .89764822
 r9  .90703923  .93796325  .91123935  .90625618  .90063643
r10  .87867137  .93029121  .91992274  .88305007   .9274604
r11  .93036963  .94736709  .88561072  .90389062  .94571276
r12  .98212214  .94099521  .93194095  .89406954  .97890203
r13  .98749141   .9532798  .91983982  .89747299  .96392461
r14  .97771295  .91396031  .95030279  .83371127  .96023587
r15  .95733652  .93235368  .97913283  .85559259  .98809935
r16  .95409988  .95181058  .99858177  .83884082   .9856184
r17  .92503577  .95008853  .97667212  .82591357  .97060018
r18  .96251099  .99129004  .98893969  .83630968  .96659867
r19  .92958332  .98371005  .99518238  .83608806   .9625896
r20  .92605893  .99770656  .98172477  .83974368  .96235752
r21  .91782737  .98051964  .96381563  .81227766  .94812266
r22  .89390343  .96766594  .96097583  .82409336  .95239989
r23  .89527051  .97186187  .95653467  .83424491  .93990167
r24  .97633787  .97605168  .93554526  .83205193  .93487398
r25  .99861887  .97466311  .94037266  .83226784  .94610205
r26    .967402  .97637061  .93503205  .83237762  .97795288
r27  .98378196  .98488757  .94715136  .82195218  .98567813
r28  .97283182  .98498653  .93686262  .82934702  .97669432
r29  .96349996  .98300101   .9233512  .83406276  .97611688
r30  .97825283  .98264185   .9172325  .83237033  .98652415
r31  .93977379  .99669696  .90144068  .83411692  .96666878
r32  .93526847  .98499306  .88787094  .83482092  .96833086
r33  .93559512  .98193958  .88966138  .83799235  .97266896
r34  .94780175   .9767247  .88870185  .83646735  .97954527
r35  .94208039  .97262629  .89317222  .83216543  .98391581
r36  .93271381  .97021278   .8984845  .82000477  .98696588
r37  .92775699  .97292176  .88784311  .82319711  .98230165
r38  .92342615  .97195885  .88946571  .83146293  .97798016
r39  .92070699  .96917871  .89739392  .82589348  .99086099
r40  .92648053  .96965105  .91219654  .82336322  .98622199
r41  .94825289  .97454151  .92560113  .82511776  .98465071
r42  .94499412  .97669725  .92185549  .83651972  .98010739
r43  .94105008  .97863174  .92468583  .83007086  .98152215
r44  .94849939  .97543798  .91665404  .81609604  .97547999
r45  .95526342   .9706657  .92648647  .81240487   .9677259
r46  .94689386  .97171312  .92047935  .81079483  .96508045
r47  .93075838  .97425315  .92695495  .81609355  .96464582
r48  .94296107   .9712346  .92216584  .82430055   .9680732
r49  .93353321  .96977138  .92084007  .82613301   .9610726
r50  .93153135  .97019754  .92160141  .81858379  .95452105

. matrix list e(R)

e(R)[50,5]
            c1         c2         c3         c4         c5
 r1  1.0077934  1.0025946  1.0079781  1.0447689  1.0366476
 r2   1.051215  1.0039857  1.0084618  1.0237972   1.010765
 r3  1.0114887  1.0050092  1.0073754  1.0264727  1.0247962
 r4  1.0064495  1.0120576  1.0202694  1.0162574  1.0040327
 r5  1.0094864  1.0084337  1.0044663  1.0138902  1.0019229
 r6  1.0072083  1.0022969  1.0025513  1.0157362  1.0005854
 r7   1.000813  1.0068124  1.0032663  1.0016958   1.001984
 r8  1.0007331  1.0082254   1.002697  1.0045231  1.0019141
 r9  1.0020478  1.0017231  1.0049928  1.0049076  1.0038423
r10  1.0032486  1.0034723  1.0013587  1.0117724  1.0068261
r11   1.011728  1.0025633   1.002727  1.0058789  1.0021738
r12  1.0076524  1.0028285   1.010617  1.0004658  1.0016692
r13  1.0015548  1.0018632  1.0046379  1.0006821  1.0015582
r14  1.0014867  1.0074543  1.0027325  1.0048059  1.0044651
r15  1.0024612  1.0034637  1.0032102   1.003531  1.0005773
r16  1.0024235  1.0009668  1.0014202  1.0011042  1.0008015
r17  1.0013896  1.0009406  1.0066362  1.0037104   1.001815
r18  1.0013442  1.0021245  1.0022048   1.000506  1.0007692
r19  1.0027585  1.0056807  1.0019277  1.0005795  1.0027554
r20  1.0010613  1.0022987  1.0059102  1.0011102  1.0005891
r21  1.0003975   1.001628  1.0016655  1.0021667  1.0012735
r22  1.0032796  1.0016871   1.003111  1.0028838  1.0018773
r23  1.0004557  1.0026798  1.0033184  1.0014218  1.0009242
r24  1.0016055  1.0010805  1.0003776  1.0006469   1.000537
r25   1.001383   1.002576  1.0005049  1.0016844  1.0017061
r26  1.0023062  1.0023284  1.0026719  1.0007677  1.0026947
r27  1.0013653  1.0005397  1.0041811  1.0009475  1.0016778
r28   1.000082  1.0002902  1.0002956  1.0013774  1.0009065
r29  1.0011733  1.0025992  1.0015746  1.0020344  1.0019909
r30  1.0003322  1.0028803  1.0009667   1.001666  1.0007775
r31  1.0004846  1.0026328  1.0022536  1.0002683  1.0006993
r32  1.0010415  1.0023843  1.0004723  1.0009601  1.0028373
r33   1.000313  1.0013181  1.0004084  1.0009785  1.0001566
r34  1.0020279  1.0021005  1.0006904  1.0014127  1.0019678
r35  1.0002106  1.0002878  1.0008118  1.0007305   1.001251
r36  1.0002016  1.0005264   1.000743  1.0031169  1.0003876
r37  1.0001877  1.0002139  1.0010979  1.0004243  1.0005868
r38  1.0003461  1.0006374  1.0014473  1.0003926  1.0018803
r39  1.0007388  1.0004193  1.0015125   1.001215  1.0005512
r40  1.0005915  1.0007842  1.0009212  1.0005378  1.0003613
r41   1.000701  1.0007975  1.0006497  1.0001713  1.0007327
r42  1.0010039  1.0008123   1.000217  1.0004878  1.0019355
r43  1.0001579  1.0005272  1.0007191  1.0000882  1.0003185
r44  1.0007675  1.0004767  1.0012267  1.0012883  1.0003641
r45  1.0003973  1.0009711  1.0007423  1.0012097  1.0002717
r46  1.0006297  1.0002624  1.0008973  1.0011828  1.0000299
r47  1.0002399  1.0002915  1.0010527  1.0003731  1.0009913
r48  1.0012061  1.0006264  1.0000445  1.0003004  1.0005435
r49  1.0004548  1.0009698  1.0008715  1.0006873  1.0005667
r50  1.0001966  1.0004989  1.0002114  1.0003308  1.0012862
As you can see this is somewhat unfinished and doesn't really hook into the post-estimation commands that we provide. Since writing the command Stata has added its own MCMC functionality so I think that if we were starting again today we would try to provide the same outputs and use the post-estimation tools that they provide. This would be a lot of work however and we don't currently have the resources to do so. If you use R then our equivalent command there (http://bristol.ac.uk/cmm/software/r2mlwin/) does support multiple chains.
Attachments
multichain.ado
(5.26 KiB) Not downloaded yet

Post Reply