------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\22_Using_th > e_Structured_MVN_framework_for_models.smcl log type: smcl opened on: 27 Mar 2020, 18:12:25 . **************************************************************************** . * MLwiN MCMC Manual . * . * 22 Using the Structured MVN framework for models . . . . . . . . . . .341 . * . * Browne, W. J. (2009). MCMC Estimation in MLwiN, v2.26. Centre for . * Multilevel Modelling, University of Bristol. . **************************************************************************** . * Stata do-file to replicate all analyses using runmlwin . * . * George Leckie and Chris Charlton, . * Centre for Multilevel Modelling, 2012 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * 22.1 MCMC theory for Structured MVN models . . . . . . . . . . . . . . 341 . . * 22.2 Using the SMVN framework in practice . . . . . . . . . . . . . . .344 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons, /// > 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.68 Number of iterations = 3 Log likelihood = -5505.324 Deviance = 11010.648 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0131668 .0536254 -0.25 0.806 -.1182706 .091937 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .168625 .0324466 .1050308 .2322193 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .8477613 .0189712 .8105785 .8849441 ------------------------------------------------------------------------------ . . matrix b = e(b) . . matrix V = e(V) . . runmlwin normexam cons, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(on) initsb(b) initsv(V) /// > nopause 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.39 Deviance (dbar) = 10849.61 Deviance (thetabar) = 10789.73 Effective no. of pars (pd) = 59.88 Bayesian DIC = 10909.49 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0147387 .0564972 189 0.386 -.1203866 .0960318 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1777477 .03642 3121 .119204 .26236 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .8484687 .0189967 4915 .8114711 .8871109 ------------------------------------------------------------------------------ . . runmlwin normexam cons, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smvn) initsb(b) initsv(V) /// > nopause 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) = 1.24 Deviance (dbar) = 11013.69 Deviance (thetabar) = 11010.85 Effective no. of pars (pd) = 2.85 Bayesian DIC = 11016.54 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0141489 .054987 1178 0.394 -.1249168 .0934382 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1839157 .0357121 1100 .1238466 .263877 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .8489798 .0191027 1176 .8117667 .8875237 ------------------------------------------------------------------------------ . . . . * 22.3 Model Comparison and structured MVN models . . . . . . . . . . . .349 . . 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.57 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 ------------------------------------------------------------------------------ . . matrix b = e(b) . . matrix V = e(V) . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(on) initsb(b) initsv(V) /// > nopause 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.41 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 ------------------------------------------------------------------------------ . . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smcmc) initsb(b) initsv(V) /// > nopause 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.45 Deviance (dbar) = 9208.86 Deviance (thetabar) = 9149.14 Effective no. of pars (pd) = 59.72 Bayesian DIC = 9268.58 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0034357 .0412205 4875 0.469 -.0788388 .085473 standlrt | .5637347 .0124572 5098 0.000 .5393521 .5881602 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0972182 .0204681 3355 .0639784 .1441007 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5660725 .0126791 4611 .5423679 .5915801 ------------------------------------------------------------------------------ . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smvn) initsb(b) initsv(V) /// > nopause 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) = 1.4 Deviance (dbar) = 9361.46 Deviance (thetabar) = 9357.47 Effective no. of pars (pd) = 3.99 Bayesian DIC = 9365.44 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0035122 .0438953 1207 0.468 -.0817808 .0904767 standlrt | .5626216 .0125229 1229 0.000 .5374463 .5865612 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1014595 .0212115 1047 .0672679 .1510381 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5660962 .0124956 1186 .5417725 .5906198 ------------------------------------------------------------------------------ . . . . * 22.4 Assessing the need for the level 2 variance . . . . . . . . . . . 350 . . set seed 12345 . . gen temp = invnorm(uniform()) . . runmlwin temp 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.56 Number of iterations = 4 Log likelihood = -5742.2411 Deviance = 11484.482 ------------------------------------------------------------------------------ temp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0148164 .0165127 -0.90 0.370 -.0471807 .0175478 standlrt | .0163283 .0158012 1.03 0.301 -.0146415 .047298 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0015615 .0028843 -.0040916 .0072147 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .9900692 .0221285 .9466981 1.03344 ------------------------------------------------------------------------------ . // Note: We have called this variable temp instead of c11 as calling it c11 . // results in an error in MLwiN as c1-c1500 are column names in MLwiN. . . runmlwin temp cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smvn) initsprevious /// > nopause 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) = 1.47 Deviance (dbar) = 11488.65 Deviance (thetabar) = 11484.76 Effective no. of pars (pd) = 3.90 Bayesian DIC = 11492.55 ------------------------------------------------------------------------------ temp | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0143781 .0174715 1271 0.200 -.0483054 .0208876 standlrt | .0159592 .0155272 1219 0.152 -.0144582 .0468059 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0032353 .003549 901 -.002402 .0115179 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .9906093 .0227697 1108 .9466143 1.036186 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .0032353 0.5% -.0031083 Thinned Chain Length 5000 MCSE of Mean .0001191 2.5% -.002402 Effective Sample Size 901 Std. Dev. .003549 5% -.0017207 Raftery Lewis (2.5%) 13487 Mode 0 25% .0007629 Raftery Lewis (97.5%) 18543 P(mean) 0.175 Brooks Draper (mean) 108890 P(mode) 0.825 50% .0027762 P(median) 0.175 75% .0053071 95% .0096446 97.5% .0115179 99.5% .0150909 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .355 . . . . . . **************************************************************************** . exit end of do-file