------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\22_Using_th > e_Structured_MVN_framework_for_models.smcl log type: smcl opened on: 11 Oct 2024, 18:12:14 . **************************************************************************** . * 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 . * https://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 "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons, /// > level2(school: cons) /// > level1(student: cons) /// > nopause MLwiN 3.13 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) = 2.94 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.13 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) = 9.52 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.13 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) = 7.05 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.13 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) = 2.69 Number of iterations = 4 Log likelihood = -4678.6211 Deviance = 9357.2422 ------------------------------------------------------------------------------ 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.13 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) = 9.77 Deviance (dbar) = 9209.08 Deviance (thetabar) = 9149.07 Effective no. of pars (pd) = 60.01 Bayesian DIC = 9269.09 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .003176 .0441993 222 0.473 -.0833011 .0918918 standlrt | .5632163 .0125795 3765 0.000 .5384416 .5878025 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0974188 .0198754 3008 .0647162 .1414384 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5661739 .0124844 5069 .5421246 .5909032 ------------------------------------------------------------------------------ . . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smcmc) initsb(b) initsv(V) /// > nopause MLwiN 3.13 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) = 10.4 Deviance (dbar) = 9209.12 Deviance (thetabar) = 9149.12 Effective no. of pars (pd) = 60.00 Bayesian DIC = 9269.13 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0023248 .0403435 5069 0.480 -.0776933 .0833642 standlrt | .5632355 .0125745 4557 0.000 .5385682 .5878254 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0970709 .0198196 3296 .0648433 .1416881 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5661802 .0124803 5054 .5420764 .5909255 ------------------------------------------------------------------------------ . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(smvn) initsb(b) initsv(V) /// > nopause MLwiN 3.13 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) = 7.37 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.13 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) = 2.63 Number of iterations = 4 Log likelihood = -5742.241 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.13 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) = 7.4 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