------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\7_Using_the > _WinBUGS_Interface_in_MLwiN.smcl log type: smcl opened on: 11 Oct 2024, 17:01:35 . **************************************************************************** . * MLwiN MCMC Manual . * . * 7 Using the WinBUGS Interface in MLwiN . . . . . . . . . . . . . . . .83 . * . * 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/ . **************************************************************************** . . * 7.1 Variance components models in WinBUGS . . . . . . . . . . . . . . . 84 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . 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.65 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 ------------------------------------------------------------------------------ . . runmlwin normexam cons standlrt, /// > level2(school: cons) /// > level1(student: cons) /// > mcmc(savewinbugs( /// > model("tutorial_model.txt", replace) /// > inits("tutorial_inits.txt", replace) /// > data("tutorial_data.txt", replace) /// > )) /// > 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) = 10.3 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 ------------------------------------------------------------------------------ . . wbscript , /// > model("`c(pwd)'\tutorial_model.txt") /// > data("`c(pwd)'\tutorial_data.txt") /// > inits("`c(pwd)'\tutorial_inits.txt") /// > coda("`c(pwd)'\out") /// > set(beta sigma2.u2 sigma2) /// > burn(500) update(5000) /// > saving("`c(pwd)'\script.txt", replace) /// > quit display('log') check('Q:/C-modelling/runmlwin/tutorial_model.txt') data('Q:/C-modelling/runmlwin/tutorial_data.txt') compile(1) inits(1,'Q:/C-modelling/runmlwin/tutorial_inits.txt') gen.inits() update(500) set('beta') set('sigma2.u2') set('sigma2') update(5000) coda(*,'Q:/C-modelling/runmlwin/out') quit() . . wbrun, script("`c(pwd)'\script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") . . wbcoda, root("`c(pwd)'\out") clear . . mcmcsum beta_1 beta_2, variables ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- beta_1 | .0029794 .0399495 212 0.457 -.0746537 .0788275 beta_2 | .5634119 .0126394 4198 0.000 .5388 .5882 ------------------------------------------------------------------------------ . . mcmcsum sigma2_u2 sigma2, variables ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- sigma2_u2 | .096619 .0201893 2659 0.000 .0641495 .1426 sigma2 | .5661458 .0127044 4820 0.000 .5415975 .5905 ------------------------------------------------------------------------------ . . mcmcsum beta_2, fiveway variables . . . . . * 7.2 So why have a WinBUGS interface ? . . . . . . . . . . . . . . . . . 92 . . * 7.3 t distributed school residuals . . . . . . . . . . . . . . . . . . .92 . . view "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial1_model.txt" . . view "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial1_inits.txt" . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial1_model.txt" /// > "tutorial1_model.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial1_inits.txt" /// > "tutorial1_inits.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial1_data.txt" /// > "tutorial1_data.txt", replace . . wbscript , /// > model("`c(pwd)'\tutorial1_model.txt") /// > data("`c(pwd)'\tutorial1_data.txt") /// > inits("`c(pwd)'\tutorial1_inits.txt") /// > coda("`c(pwd)'\out") /// > set(df) /// > burn(500) update(5000) /// > saving("`c(pwd)'\script.txt", replace) /// > quit display('log') check('Q:/C-modelling/runmlwin/tutorial1_model.txt') data('Q:/C-modelling/runmlwin/tutorial1_data.txt') compile(1) inits(1,'Q:/C-modelling/runmlwin/tutorial1_inits.txt') gen.inits() update(500) set('df') update(5000) coda(*,'Q:/C-modelling/runmlwin/out') quit() . . wbrun, script("`c(pwd)'\script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") . . wbcoda, root("`c(pwd)'\out") clear . . mcmcsum df, trajectories variables . . mcmcsum df, variables ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- df | 91.89 59.93861 58 0.000 5.552625 194.8 ------------------------------------------------------------------------------ . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial2_model.txt" /// > "tutorial2_model.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial2_inits1.txt" /// > "tutorial2_inits1.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial2_inits2.txt" /// > "tutorial2_inits2.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial2_inits3.txt" /// > "tutorial2_inits3.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial2_data.txt" /// > "tutorial2_data.txt", replace . . wbscript , /// > model("`c(pwd)'\tutorial2_model.txt") /// > data("`c(pwd)'\tutorial2_data.txt") /// > chains(3) /// > inits("`c(pwd)'\tutorial2_inits.txt") /// > coda("`c(pwd)'\out") /// > set(df) /// > burn(2000) update(10000) /// > saving("`c(pwd)'\script.txt", replace) /// > quit display('log') check('Q:/C-modelling/runmlwin/tutorial2_model.txt') data('Q:/C-modelling/runmlwin/tutorial2_data.txt') compile(3) inits(1,'Q:/C-modelling/runmlwin/tutorial2_inits1.txt') inits(2,'Q:/C-modelling/runmlwin/tutorial2_inits2.txt') inits(3,'Q:/C-modelling/runmlwin/tutorial2_inits3.txt') gen.inits() update(2000) set('df') update(10000) coda(*,'Q:/C-modelling/runmlwin/out') quit() . . wbrun, script("`c(pwd)'\script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") . . wbcoda, root("`c(pwd)'\out") id(chain) chains(3) multichain clear . . twoway /// > (line df order if chain==1) /// > (line df order if chain==2) /// > (line df order if chain==3), legend(off) . . mcmcsum df, variables ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- df | 103.4442 55.88115 682 0.000 9.241975 195.2 ------------------------------------------------------------------------------ . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial3_model.txt" /// > "tutorial3_model.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial3_inits.txt" /// > "tutorial3_inits.txt", replace . . copy "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial3_data.txt" /// > "tutorial3_data.txt", replace . . wbscript , /// > model("`c(pwd)'\tutorial3_model.txt") /// > data("`c(pwd)'\tutorial3_data.txt") /// > inits("`c(pwd)'\tutorial3_inits.txt") /// > coda("`c(pwd)'\out") /// > set(beta sigma2.u2 sigma2) /// > burn(500) update(5000) /// > saving("`c(pwd)'\script.txt", replace) /// > quit display('log') check('Q:/C-modelling/runmlwin/tutorial3_model.txt') data('Q:/C-modelling/runmlwin/tutorial3_data.txt') compile(1) inits(1,'Q:/C-modelling/runmlwin/tutorial3_inits.txt') gen.inits() update(500) set('beta') set('sigma2.u2') set('sigma2') update(5000) coda(*,'Q:/C-modelling/runmlwin/out') quit() . . wbrun, script("`c(pwd)'\script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") . . wbcoda, root("`c(pwd)'\out") clear . . mcmcsum beta_1 beta_2 sigma2_u2 sigma2, variables ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- beta_1 | -.0010646 .0412453 259 0.492 -.0832207 .077842 beta_2 | .5633365 .0124021 4142 0.000 .5391 .5872 sigma2_u2 | .0765737 .0180549 2144 0.000 .047458 .1171 sigma2 | .5661645 .0127878 4489 0.000 .5420975 .5916 ------------------------------------------------------------------------------ . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . . 96 . . . . . . **************************************************************************** . exit end of do-file