------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\21_Using_St > ructured_MCMC.smcl log type: smcl opened on: 11 Oct 2024, 18:09:17 . **************************************************************************** . * MLwiN MCMC Manual . * . * 21 Using Structured MCMC . . . . . . . . . . . . . . . . . . . . . . .327 . * . * 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/ . **************************************************************************** . . * 21.1 SMCMC Theory . . . . . . . . . . . . . . . . . . . . . . . . . . .327 . . * 21.2 Fitting the model using MLwiN . . . . . . . . . . . . . . . . . . 330 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . quietly runmlwin normexam cons, /// > level2(school: cons) /// > level1(student: cons) /// > nopause . . 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.49 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 ------------------------------------------------------------------------------ . . mcmcsum [FP1]cons, fiveway . . runmlwin normexam cons, /// > 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) = 9.55 Deviance (dbar) = 10849.60 Deviance (thetabar) = 10789.74 Effective no. of pars (pd) = 59.85 Bayesian DIC = 10909.45 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0135842 .0552321 4890 0.408 -.1234418 .0923957 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1776045 .0364615 3279 .1187232 .2616111 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .8484661 .0190012 4912 .8114034 .8870222 ------------------------------------------------------------------------------ . . mcmcsum [FP1]cons, fiveway . . . . * 21.3 A random intercepts model . . . . . . . . . . . . . . . . . . . . 334 . . quietly runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > nopause . . matrix b = e(b) . . matrix V = e(V) . . 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 ------------------------------------------------------------------------------ . . mcmcsum, trajectories . . . . * 21.4 Examining the residual chains . . . . . . . . . . . . . . . . . . 335 . . runmlwin normexam cons standlrt, /// > level2(school: cons, residuals(u, savechains("schoolresiduals.dta", > replace))) /// > level1(student: cons) /// > mcmc(chain(5001) 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 = 5001 Thinning = 1 Run time (seconds) = 13.8 Deviance (dbar) = 9209.12 Deviance (thetabar) = 9149.12 Effective no. of pars (pd) = 60.01 Bayesian DIC = 9269.13 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0023099 .0403532 5065 0.481 -.0776876 .0833628 standlrt | .5632353 .0125733 4558 0.000 .5385698 .5878243 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0970731 .0198183 3293 .0648512 .1416873 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5661834 .0124811 5046 .5420772 .5909251 ------------------------------------------------------------------------------ . . use "schoolresiduals.dta", clear . . keep if school==1 (320,064 observations deleted) . . keep iteration value . . mcmcsum value, variables detail value ------------------------------------------------------------------------------ Percentiles Mean .3731477 0.5% .1364504 Thinned Chain Length 5001 MCSE of Mean .0012877 2.5% .1953753 Effective Sample Size 5347 Std. Dev. .0922985 5% .2197248 Raftery Lewis (2.5%) 3646 Mode .3710054 25% .3100522 Raftery Lewis (97.5%) 3929 P(mean) 0.000 Brooks Draper (mean) 1275 P(mode) 0.000 50% .3717966 P(median) 0.000 75% .4356988 95% .5253161 97.5% .5534704 99.5% .6157975 ------------------------------------------------------------------------------ . . mcmcsum value, variables fiveway . . . . * 21.5 Random slopes model theory . . . . . . . . . . . . . . . . . . . .336 . . * 21.6 Random Slopes model practice . . . . . . . . . . . . . . . . . . .338 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . quietly runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > level1(student: cons) /// > nopause . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > level1(student: cons) /// > mcmc(smcmc) 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) = 20.4 Deviance (dbar) = 9123.15 Deviance (thetabar) = 9031.73 Effective no. of pars (pd) = 91.43 Bayesian DIC = 9214.58 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.011359 .0409273 4990 0.387 -.0922897 .0693712 standlrt | .5567764 .0198757 4974 0.000 .5170799 .5953519 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0971345 .0201053 2750 .0644268 .1425288 cov(cons,standlrt) | .019273 .0073602 1788 .0064108 .0353531 var(standlrt) | .015227 .0048087 976 .0077267 .0264794 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5543915 .0124157 4544 .5303789 .5790667 ------------------------------------------------------------------------------ . . . mcmcsum [FP1]cons, fiveway . . mcmcsum [FP1]standlrt, fiveway . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .340 . . . . . . **************************************************************************** . exit end of do-file