------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\24_Paramete > r_expansion.smcl log type: smcl opened on: 11 Oct 2024, 18:26:54 . **************************************************************************** . * MLwiN MCMC Manual . * . * 24 Parameter expansion . . . . . . . . . . . . . . . . . . . . . . . .381 . * . * 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/ . **************************************************************************** . . * 24.1 What is Parameter Expansion? . . . . . . . . . . . . . . . . . . .381 . . * 24.2 The tutorial example . . . . . . . . . . . . . . . . . . . . . . .383 . . 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) = 3.04 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.75 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 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .0974188 0.5% .0570548 Thinned Chain Length 5000 MCSE of Mean .0003554 2.5% .0647162 Effective Sample Size 3008 Std. Dev. .0198754 5% .0686262 Raftery Lewis (2.5%) 4198 Mode .0934908 25% .0834696 Raftery Lewis (97.5%) 3803 P(mean) 0.000 Brooks Draper (mean) 9706 P(mode) 0.000 50% .0955318 P(median) 0.000 75% .108884 95% .1331365 97.5% .1414384 99.5% .1598625 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . . runmlwin normexam cons standlrt, /// > level2(school: cons, parexpansion) /// > 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) = 10.6 Deviance (dbar) = 9209.05 Deviance (thetabar) = 9148.85 Effective no. of pars (pd) = 60.20 Bayesian DIC = 9269.25 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0030782 .0423254 192 0.473 -.0783237 .0870155 standlrt | .5630708 .0127489 3805 0.000 .5378865 .5873822 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0998017 .0205788 2871 .0670627 .1458018 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5664552 .0125856 4655 .5421363 .5920212 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .0998017 0.5% .0599134 Thinned Chain Length 5000 MCSE of Mean .000359 2.5% .0670627 Effective Sample Size 2871 Std. Dev. .0205788 5% .0707256 Raftery Lewis (2.5%) 4062 Mode .0936443 25% .0850699 Raftery Lewis (97.5%) 3803 P(mean) 0.000 Brooks Draper (mean) 9904 P(mode) 0.000 50% .097073 P(median) 0.000 75% .1120166 95% .1374973 97.5% .1458018 99.5% .1665512 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . . . . * 24.3 Binary responses - Voting example . . . . . . . . . . . . . . . . 386 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/bes83.dta", clear . . runmlwin votecons cons defence unemp taxes privat, /// > level2(area: cons) /// > level1(voter:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > nopause MLwiN 3.13 multilevel model Number of obs = 800 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 110 1 7.3 16 ----------------------------------------------------------- Run time (seconds) = 3.18 Number of iterations = 6 ------------------------------------------------------------------------------ votecons | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.3552158 .0917617 -3.87 0.000 -.5350656 -.1753661 defence | .0893889 .0181955 4.91 0.000 .0537263 .1250515 unemp | .067076 .0134056 5.00 0.000 .0408016 .0933504 taxes | .0445018 .0191789 2.32 0.020 .0069118 .0820918 privat | .1382851 .0176275 7.84 0.000 .1037358 .1728345 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .1323441 .111845 -.0868681 .3515564 ------------------------------------------------------------------------------ . . matrix b = e(b) . . matrix V = e(V) . . runmlwin votecons cons defence unemp taxes privat, /// > level2(area: cons) /// > level1(voter:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > mcmc(on) initsb(b) initsv(V) /// > nopause MLwiN 3.13 multilevel model Number of obs = 800 Binomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 110 1 7.3 16 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 16 Deviance (dbar) = 867.39 Deviance (thetabar) = 845.74 Effective no. of pars (pd) = 21.66 Bayesian DIC = 889.05 ------------------------------------------------------------------------------ votecons | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.3654746 .0943153 810 0.000 -.5457957 -.1813685 defence | .0920307 .0185029 968 0.000 .055517 .1285456 unemp | .0696328 .0137619 1014 0.000 .0434006 .0974678 taxes | .0464123 .019693 1039 0.015 .006449 .0837387 privat | .1429049 .0184198 975 0.000 .1060572 .1789377 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .1428529 .1158866 28 .0042903 .4338606 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .1428529 0.5% .0032072 Thinned Chain Length 5000 MCSE of Mean .0102823 2.5% .0042903 Effective Sample Size 28 Std. Dev. .1158866 5% .0057393 Raftery Lewis (2.5%) 89829 Mode 0 25% .0552181 Raftery Lewis (97.5%) 75362 P(mean) 0.000 Brooks Draper (mean) 81229 P(mode) 1.000 50% .1198902 P(median) 0.000 75% .2028327 95% .3740599 97.5% .4338606 99.5% .5677614 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . // Note: The ACF appears to decay far less rapidly than in the manual. This . // is simply because the y-axis min in the manual is not zero. . . runmlwin votecons cons defence unemp taxes privat, /// > level2(area: cons, parexpansion) /// > level1(voter:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > mcmc(on) initsb(b) initsv(V) /// > nopause MLwiN 3.13 multilevel model Number of obs = 800 Binomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 110 1 7.3 16 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 19.1 Deviance (dbar) = 862.89 Deviance (thetabar) = 836.40 Effective no. of pars (pd) = 26.49 Bayesian DIC = 889.38 ------------------------------------------------------------------------------ votecons | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.3739992 .1020522 548 0.000 -.5852809 -.1735945 defence | .0933742 .0191242 1056 0.000 .0560072 .1319248 unemp | .0704762 .0139972 1030 0.000 .0442712 .0988752 taxes | .0452933 .0198114 903 0.010 .0067104 .0852814 privat | .1452582 .0184429 999 0.000 .1084074 .1806551 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .1966972 .1426941 200 .0058794 .5475349 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .1966972 0.5% .0001977 Thinned Chain Length 5000 MCSE of Mean .0074599 2.5% .0058794 Effective Sample Size 200 Std. Dev. .1426941 5% .0153824 Raftery Lewis (2.5%) 42835 Mode .0675364 25% .0904307 Raftery Lewis (97.5%) 21927 P(mean) 0.000 Brooks Draper (mean) 42757 P(mode) 0.000 50% .1764558 P(median) 0.000 75% .2705243 95% .460187 97.5% .547535 99.5% .7254679 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . . . . * 24.4 The choice of prior distribution . . . . . . . . . . . . . . . . .390 . . runmlwin votecons cons defence unemp taxes privat, /// > level2(area: cons) /// > level1(voter:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > mcmc(rppriors(uniform)) initsb(b) initsv(V) /// > nopause MLwiN 3.13 multilevel model Number of obs = 800 Binomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 110 1 7.3 16 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 14.3 Deviance (dbar) = 855.59 Deviance (thetabar) = 822.18 Effective no. of pars (pd) = 33.41 Bayesian DIC = 889.01 ------------------------------------------------------------------------------ votecons | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.380685 .1067521 576 0.000 -.5940461 -.1693329 defence | .094892 .0192105 965 0.000 .0589361 .1336075 unemp | .0706254 .0141228 895 0.000 .0431121 .0991991 taxes | .0464161 .0193412 1178 0.008 .008158 .0847816 privat | .1469198 .018428 1091 0.000 .1104003 .1841221 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .2937165 .16964 63 .0597007 .7216039 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), detail [RP2]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .2937165 0.5% .0390359 Thinned Chain Length 5000 MCSE of Mean .0116117 2.5% .0597007 Effective Sample Size 63 Std. Dev. .16964 5% .0768603 Raftery Lewis (2.5%) 106030 Mode .2310197 25% .1741275 Raftery Lewis (97.5%) 30028 P(mean) 0.000 Brooks Draper (mean) 103590 P(mode) 0.000 50% .2616522 P(median) 0.000 75% .3784746 95% .624557 97.5% .7216039 99.5% .909936 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons), fiveway . . . . * 24.5 Parameter expansion and WinBUGS . . . . . . . . . . . . . . . . . 391 . . runmlwin votecons cons defence unemp taxes privat, /// > level2(area: cons, parexpansion) /// > level1(voter:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > mcmc(savewinbugs( /// > model("votecons_model.txt", replace) /// > inits("votecons_inits.txt", replace) /// > data("votecons_data.txt", replace) /// > )) initsb(b) initsv(V) /// > nopause MLwiN 3.13 multilevel model Number of obs = 800 Binomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 110 1 7.3 16 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 18.8 Deviance (dbar) = 862.89 Deviance (thetabar) = 836.40 Effective no. of pars (pd) = 26.49 Bayesian DIC = 889.38 ------------------------------------------------------------------------------ votecons | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.3739992 .1020522 548 0.000 -.5852809 -.1735945 defence | .0933742 .0191242 1056 0.000 .0560072 .1319248 unemp | .0704762 .0139972 1030 0.000 .0442712 .0988752 taxes | .0452933 .0198114 903 0.010 .0067104 .0852814 privat | .1452582 .0184429 999 0.000 .1084074 .1806551 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .1966972 .1426941 200 .0058794 .5475349 ------------------------------------------------------------------------------ . . type "votecons_model.txt" # WINBUGS 1.4 code generated from MLwiN program #----MODEL Definition---------------- model { # Level 1 definition for(i in 1:N) { votecons[i] ~ dbin(p[i],denom[i]) logit(p[i]) <- beta[1] * cons[i] + beta[2] * defence[i] + beta[3] * unemp[i] + beta[4] * taxes[i] + beta[5] * privat[i] + alpha2 * u2[area[i]] * cons[i] } # Higher level definitions for (j in 1:n2) { u2[j] ~ dnorm(0,tau.u2) v2[j] <- u2[j]*alpha2 } # Priors for fixed effects for (k in 1:5) { beta[k] ~ dflat() } alpha2 ~ dflat() # Priors for random terms tau.u2 ~ dgamma(0.001,0.001) sigma2.u2 <- 1/tau.u2 sigma2.v2 <- sigma2.u2*alpha2*alpha2 } . . /* There is a known MLwiN bug here which will be fixed in version 2.29 > wbscript, /// > model("`c(pwd)'\votecons_model.txt") /// > data("`c(pwd)'\votecons_data.txt") /// > inits("`c(pwd)'\votecons_inits.txt") /// > log("`c(pwd)'\votecons_log.txt") /// > coda("`c(pwd)'\out") /// > set(beta sigma2.v2 sigma2.u2 alpha2) /// > burn(4000) update(5000) quit /// > saving("`c(pwd)'\votecons_script.txt", replace) > > > wbrun, /// > script("`c(pwd)'\votecons_script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") > > wbcoda, root("`c(pwd)'\out") clear > > mcmcsum alpha2, variables > > mcmcsum alpha2, variables fiveway > > mcmcsum sigma2_v2, variables > > mcmcsum sigma2_v2, variables fiveway > */ . . . * 24.6 Parameter expansion and random slopes . . . . . . . . . . . . . . 396 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > 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.33 Number of iterations = 4 Log likelihood = -4658.435 Deviance = 9316.87 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0115051 .039783 -0.29 0.772 -.0894783 .066468 standlrt | .5567305 .019937 27.92 0.000 .5176547 .5958062 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0904446 .017924 .0553142 .1255749 cov(cons,standlrt) | .0180414 .0067229 .0048649 .031218 var(standlrt) | .0145361 .0044139 .0058851 .0231872 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5536575 .0124818 .5291937 .5781214 ------------------------------------------------------------------------------ . . matrix b = e(b) . . matrix V = e(V) . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > 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) = 11.8 Deviance (dbar) = 9123.21 Deviance (thetabar) = 9031.71 Effective no. of pars (pd) = 91.49 Bayesian DIC = 9214.70 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0125681 .040883 249 0.381 -.0905471 .0686477 standlrt | .5564547 .0208367 706 0.000 .5150133 .597012 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0971118 .0200117 2667 .0646451 .1426135 cov(cons,standlrt) | .0193325 .0073905 1722 .0065965 .0353707 var(standlrt) | .0152639 .0048458 957 .0077234 .0266211 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5543991 .0124193 4550 .5305235 .5790426 ------------------------------------------------------------------------------ . . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt, parexpansion) /// > 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) = 13 Deviance (dbar) = 9122.83 Deviance (thetabar) = 9030.79 Effective no. of pars (pd) = 92.04 Bayesian DIC = 9214.87 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.011282 .0421549 230 0.399 -.0986968 .0694205 standlrt | .5563635 .0200373 895 0.000 .5166189 .5951573 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0976579 .0206113 2843 .0638728 .1434661 cov(cons,standlrt) | .0190646 .0072893 1767 .0064272 .0351253 var(standlrt) | .0155059 .0049649 1055 .0076529 .0269344 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5544234 .012642 4718 .5301883 .5794183 ------------------------------------------------------------------------------ . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .399 . . . . . . **************************************************************************** . exit end of do-file