------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\19_Mixed_Re > sponse_Models_and_Correlated_Residuals.smcl log type: smcl opened on: 11 Oct 2024, 17:46:54 . **************************************************************************** . * MLwiN MCMC Manual . * . * 19 Mixed Response Models and Correlated Residuals . . . . . . . . . . 287 . * . * 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/ . **************************************************************************** . . * 19.1 Mixed response models . . . . . . . . . . . . . . . . . . . . . . 287 . . * 19.2 The JSP mixed response example . . . . . . . . . . . . . . . . . .289 . use "https://www.bristol.ac.uk/cmm/media/runmlwin/jspmix1.dta", clear . . describe Contains data from https://www.bristol.ac.uk/cmm/media/runmlwin/jspmix1.dta Observations: 1,119 Variables: 9 21 Oct 2011 12:19 ------------------------------------------------------------------------------- Variable Storage Display Value name type format label Variable label ------------------------------------------------------------------------------- school byte %9.0g id int %9.0g sex byte %9.0g fluent byte %9.0g ravens byte %9.0g english byte %9.0g behaviour byte %9.0g cons byte %9.0g denomb byte %9.0g ------------------------------------------------------------------------------- Sorted by: . . tabstat english, statistics(count mean) by(behaviour) columns(statistics) Summary for variables: english Group variable: behaviour behaviour | N Mean ----------+-------------------- 0 | 248 28.86694 1 | 871 45.06429 ----------+-------------------- Total | 1119 41.47453 ------------------------------- . . corr sex fluent ravens english behaviour (obs=1,119) | sex fluent ravens english behavi~r -------------+--------------------------------------------- sex | 1.0000 fluent | -0.0229 1.0000 ravens | 0.0341 0.1705 1.0000 english | -0.1479 0.2054 0.5042 1.0000 behaviour | -0.1272 -0.0038 0.2181 0.3122 1.0000 . . . * 19.3 Setting up a single level mixed response model . . . . . . . . . .291 . . runmlwin /// > (english cons sex ravens fluent, eq(1)) /// > (behaviour cons sex ravens, eq(2)), /// > level1(id: (cons, eq(1))) /// > discrete(distribution(normal binomial) link(probit) denom(cons denomb > )) /// > nosort nopause MLwiN 3.13 multilevel model Number of obs = 1119 Multivariate response model (hierarchical) Estimation algorithm: IGLS, MQL1 Run time (seconds) = 3.63 Number of iterations = 5 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- english | cons_1 | -11.69107 3.181135 -3.68 0.000 -17.92598 -5.456165 sex_1 | -6.972447 1.082897 -6.44 0.000 -9.094886 -4.850009 ravens_1 | 1.753013 .0914267 19.17 0.000 1.57382 1.932206 fluent_1 | 6.732304 1.317369 5.11 0.000 4.150309 9.314299 -------------+---------------------------------------------------------------- behaviour | cons_2 | -.3487978 .1805604 -1.93 0.053 -.7026897 .005094 sex_2 | -.4052486 .0869023 -4.66 0.000 -.5755741 -.2349232 ravens_2 | .0547394 .0072338 7.57 0.000 .0405614 .0689174 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: id | var(cons_1) | 327.45 13.82417 300.3551 354.5449 cov(cons_1,bcons_2) | 4.209009 .5261126 3.177847 5.24017 var(bcons_2) | 1 0 1 1 ------------------------------------------------------------------------------ . . runmlwin /// > (english cons sex ravens fluent, eq(1)) /// > (behaviour cons sex ravens, eq(2)), /// > level1(id: (cons, eq(1))) /// > discrete(distribution(normal binomial) link(probit) denom(cons denomb > )) /// > mcmc(on) initsprevious nosort nopause MLwiN 3.13 multilevel model Number of obs = 1119 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 15.2 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- english | cons_1 | -11.86464 2.940387 23 0.000 -17.29748 -6.528897 sex_1 | -6.865483 1.053371 441 0.000 -8.893375 -4.86474 ravens_1 | 1.73938 .0820531 38 0.000 1.575873 1.895852 fluent_1 | 6.973888 1.210514 31 0.000 4.528842 9.253601 -------------+---------------------------------------------------------------- behaviour | cons_2 | -.4265475 .1802346 14 0.022 -.7137227 -.009405 sex_2 | -.3939681 .0917415 175 0.000 -.5713868 -.1986262 ravens_2 | .057836 .007121 14 0.000 .0402755 .0696956 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: id | var(cons_1) | 329.3744 14.29315 558 302.2684 358.0792 cov(cons_1,bcons_2) | 6.258986 .7860669 350 4.715842 7.710665 var(bcons_2) | 1 0 0 1 1 ------------------------------------------------------------------------------ . // Note: MLwiN does not calculate the DIC for mixed response models and so . // the the DIC is not displayed in the runmlwin output. This issue applies . // to all the models in this chapter. . . . . * 19.4 Multilevel mixed response model . . . . . . . . . . . . . . . . . 294 . quietly runmlwin /// > (english cons sex ravens fluent, eq(1)) /// > (behaviour cons sex ravens, eq(2)), /// > level2(school: (cons, eq(1)) (cons, eq(2))) /// > level1(id: (cons, eq(1))) /// > discrete(distribution(normal binomial) link(probit) denom(cons denomb > )) /// > nopause . . runmlwin /// > (english cons sex ravens fluent, eq(1)) /// > (behaviour cons sex ravens, eq(2)), /// > level2(school: (cons, eq(1)) (cons, eq(2))) /// > level1(id: (cons, eq(1))) /// > discrete(distribution(normal binomial) link(probit) denom(cons denomb > )) /// > mcmc(on) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 1119 Multivariate response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 47 7 23.8 76 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 17.7 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- english | cons_1 | -9.646805 2.566667 32 0.000 -14.51511 -4.694863 sex_1 | -6.224229 1.052756 348 0.000 -8.25456 -4.034818 ravens_1 | 1.666646 .0828613 25 0.000 1.477238 1.8209 fluent_1 | 6.480349 1.104849 30 0.000 4.281117 8.650821 -------------+---------------------------------------------------------------- behaviour | cons_2 | -.3806277 .1906486 12 0.022 -.7473546 -.0131854 sex_2 | -.4165973 .0867885 147 0.000 -.589917 -.2529856 ravens_2 | .0579353 .0074675 12 0.000 .0441352 .0720903 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons_1) | 40.7712 11.32744 938 22.23223 66.67616 cov(cons_1,cons_2) | .0485251 .445813 262 -.8395687 .9412721 var(cons_2) | .0674301 .0312988 227 .0234038 .1450272 -----------------------------+------------------------------------------------ Level 1: id | var(cons_1) | 291.5427 12.38059 688 268.2156 316.1032 cov(cons_1,bcons_2) | 6.178525 .7278787 343 4.825332 7.642593 var(bcons_2) | 1 0 0 1 1 ------------------------------------------------------------------------------ . . . . * 19.5 Rats dataset . . . . . . . . . . . . . . . . . . . . . . . . . . .295 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/rats.dta", clear . . describe Contains data from https://www.bristol.ac.uk/cmm/media/runmlwin/rats.dta Observations: 30 Variables: 7 21 Oct 2011 12:19 ------------------------------------------------------------------------------- Variable Storage Display Value name type format label Variable label ------------------------------------------------------------------------------- y8 int %9.0g y15 int %9.0g y22 int %9.0g y29 int %9.0g y36 int %9.0g cons byte %9.0g rat byte %9.0g ------------------------------------------------------------------------------- Sorted by: . . quietly runmlwin /// > (y8 cons, eq(1)) /// > (y15 cons, eq(2)) /// > (y22 cons, eq(3)) /// > (y29 cons, eq(4)) /// > (y36 cons, eq(5)), /// > level1(rat: /// > (cons, eq(1)) /// > (cons, eq(2)) /// > (cons, eq(3)) /// > (cons, eq(4)) /// > (cons, eq(5)) /// > ) /// > nopause . . matrix b = e(b) . . matrix V = e(V) . . runmlwin /// > (y8 cons, eq(1)) /// > (y15 cons, eq(2)) /// > (y22 cons, eq(3)) /// > (y29 cons, eq(4)) /// > (y36 cons, eq(5)), /// > level1(rat: /// > (cons, eq(1)) /// > (cons, eq(2)) /// > (cons, eq(3)) /// > (cons, eq(4)) /// > (cons, eq(5)) /// > ) /// > mcmc(on) initsb(b) initsv(V) nopause MLwiN 3.13 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 10.8 Deviance (dbar) = 1008.74 Deviance (thetabar) = 993.33 Effective no. of pars (pd) = 15.41 Bayesian DIC = 1024.16 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1764 2.204411 4873 0.000 147.7601 156.442 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.7728 2.495441 4930 0.000 196.9172 206.71 -------------+---------------------------------------------------------------- y22 | cons_3 | 245.0416 3.055069 4969 0.000 239.067 251.0459 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.5211 3.827316 5130 0.000 282.0675 297.0837 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.7966 3.921327 5182 0.000 317.0229 332.4792 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 150.4478 41.0208 4790 89.57631 246.1945 cov(cons_1,cons_2) | 156.5675 44.79773 4752 90.96581 263.5454 var(cons_2) | 193.7399 53.01746 4713 115.8575 320.5834 cov(cons_1,cons_3) | 171.0224 52.19445 4902 94.71162 299.0589 cov(cons_2,cons_3) | 217.1817 62.29544 4824 127.688 365.7124 var(cons_3) | 286.1788 79.10161 4980 173.8806 475.9282 cov(cons_1,cons_4) | 187.9201 62.35577 4723 96.60231 339.4304 cov(cons_2,cons_4) | 247.8544 74.96247 4692 139.4115 425.1858 cov(cons_3,cons_4) | 338.201 96.26942 4894 202.1155 561.684 var(cons_4) | 444.5679 123.7007 4857 271.561 730.9316 cov(cons_1,cons_5) | 161.9335 59.94487 4920 71.26897 304.3383 cov(cons_2,cons_5) | 209.723 70.90267 4838 106.0412 380.1934 cov(cons_3,cons_5) | 311.5816 93.17126 5011 180.6354 535.3899 cov(cons_4,cons_5) | 415.6738 120.1837 5052 246.4468 701.6114 var(cons_5) | 459.0951 126.6608 5173 277.1902 761.0235 ------------------------------------------------------------------------------ . . mcmcsum [RP1]var(cons_1), detail [RP1]var(cons_1) ------------------------------------------------------------------------------ Percentiles Mean 150.4478 0.5% 79.06881 Thinned Chain Length 5000 MCSE of Mean .6288341 2.5% 89.57631 Effective Sample Size 4790 Std. Dev. 41.0208 5% 96.38676 Raftery Lewis (2.5%) 3803 Mode 137.1177 25% 121.8088 Raftery Lewis (97.5%) 3930 P(mean) 0.000 Brooks Draper (mean) 304 P(mode) 0.000 50% 143.7761 P(median) 0.000 75% 172.5158 95% 225.9916 97.5% 246.1945 99.5% 303.9969 ------------------------------------------------------------------------------ . . mcmcsum [RP1]var(cons_1), fiveway . . . . * 19.6 Fitting an autoregressive structure to the variance matrix . . . .298 . . runmlwin, corr MLwiN 3.13 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 10.8 Deviance (dbar) = 1008.74 Deviance (thetabar) = 993.33 Effective no. of pars (pd) = 15.41 Bayesian DIC = 1024.16 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1764 2.204411 4873 0.000 147.7601 156.442 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.7728 2.495441 4930 0.000 196.9172 206.71 -------------+---------------------------------------------------------------- y22 | cons_3 | 245.0416 3.055069 4969 0.000 239.067 251.0459 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.5211 3.827316 5130 0.000 282.0675 297.0837 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.7966 3.921327 5182 0.000 317.0229 332.4792 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 150.4478 41.0208 4790 89.57631 246.1945 corr(cons_1,cons_2) | .9146164 .0310549 5077 .8414204 .9602545 var(cons_2) | 193.7399 53.01746 4713 115.8575 320.5834 corr(cons_1,cons_3) | .8198536 .0609671 4852 .6745109 .9140396 corr(cons_2,cons_3) | .9200191 .0288267 4473 .849945 .9633556 var(cons_3) | 286.1788 79.10161 4980 173.8806 475.9282 corr(cons_1,cons_4) | .720996 .0895355 4736 .5141787 .8611787 corr(cons_2,cons_4) | .8405248 .0552746 4628 .7113869 .9233808 corr(cons_3,cons_4) | .9466457 .0197467 4920 .9003506 .9748721 var(cons_4) | 444.5679 123.7007 4857 271.561 730.9316 corr(cons_1,cons_5) | .6100032 .1154145 4823 .3498263 .798125 corr(cons_2,cons_5) | .697545 .094913 4606 .4723414 .8469788 corr(cons_3,cons_5) | .8560707 .0497454 4567 .7387792 .9306174 corr(cons_4,cons_5) | .9178142 .0292734 4445 .8496379 .961162 var(cons_5) | 459.0951 126.6608 5173 277.1902 761.0235 ------------------------------------------------------------------------------ . // Note: These correlations differ slightly from those presented in the . // manual. This is because those displayed in the manual are calculated . // based on the estimates of the variance and covariance parameters, while . // those presented here are based on full chains for the variance and . // covariance parameters. The method used to produce the correlations . // presented here is the more appropriate method. We would, however, . // usually expect the two methods to give similar results. . . runmlwin /// > (y8 cons, eq(1)) /// > (y15 cons, eq(2)) /// > (y22 cons, eq(3)) /// > (y29 cons, eq(4)) /// > (y36 cons, eq(5)), /// > level1(rat: /// > (cons, eq(1)) /// > (cons, eq(2)) /// > (cons, eq(3)) /// > (cons, eq(4)) /// > (cons, eq(5)) /// > ) /// > mcmc(chain(50000) refresh(500) corresiduals(arindepvars)) /// > initsb(b) initsv(V) corr /// > nopause MLwiN 3.13 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 47.7 Deviance (dbar) = 1015.42 Deviance (thetabar) = 1006.01 Effective no. of pars (pd) = 9.42 Bayesian DIC = 1024.84 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1695 2.484324 50143 0.000 147.2569 157.0946 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.7648 2.819057 50222 0.000 196.1986 207.3101 -------------+---------------------------------------------------------------- y22 | cons_3 | 245.0378 3.35727 49785 0.000 238.4248 251.6736 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.5056 4.169446 49727 0.000 281.2745 297.7357 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.8067 4.233443 49266 0.000 316.4409 333.1868 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 184.9999 64.63044 249 99.2708 349.1438 corr(cons_1,cons_2) | .9400507 .0187963 326 .8986986 .9722228 var(cons_2) | 238.4504 83.02028 218 128.0316 456.414 corr(cons_1,cons_3) | .8840486 .0351391 321 .8076592 .9452171 corr(cons_2,cons_3) | .9400507 .0187963 326 .8986986 .9722228 var(cons_3) | 338.6676 116.6998 219 180.0265 648.2073 corr(cons_1,cons_4) | .8317109 .0493005 317 .7258423 .9189616 corr(cons_2,cons_4) | .8840486 .0351391 321 .8076592 .9452171 corr(cons_3,cons_4) | .9400507 .0187963 326 .8986986 .9722228 var(cons_4) | 520.3938 179.253 225 277.6516 1008.49 corr(cons_1,cons_5) | .7827766 .0615229 312 .6523134 .8934353 corr(cons_2,cons_5) | .8317109 .0493005 317 .7258423 .9189616 corr(cons_3,cons_5) | .8840486 .0351391 321 .8076592 .9452171 corr(cons_4,cons_5) | .9400507 .0187963 326 .8986986 .9722228 var(cons_5) | 537.4012 180.6482 258 292.3495 1017.609 ------------------------------------------------------------------------------ . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .301 . . . . . . **************************************************************************** . exit end of do-file