------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\19_Mixed_Re > sponse_Models_and_Correlated_Residuals.smcl log type: smcl opened on: 27 Mar 2020, 18:02:39 . **************************************************************************** . * 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 . * http://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * 19.1 Mixed response models . . . . . . . . . . . . . . . . . . . . . . 287 . . * 19.2 The JSP mixed response example . . . . . . . . . . . . . . . . . .289 . use "http://www.bristol.ac.uk/cmm/media/runmlwin/jspmix1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/jspmix1.dta obs: 1,119 vars: 9 21 Oct 2011 12:19 ------------------------------------------------------------------------------- storage display value variable 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 by categories of: 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.05 multilevel model Number of obs = 1119 Multivariate response model (hierarchical) Estimation algorithm: IGLS, MQL1 Run time (seconds) = 0.80 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.05 multilevel model Number of obs = 1119 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 4.79 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.05 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) = 5.65 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- english | cons_1 | -9.713466 2.827676 26 0.000 -14.22356 -3.870696 sex_1 | -6.189866 1.020994 436 0.000 -8.211348 -4.154795 ravens_1 | 1.679999 .0956529 34 0.000 1.50448 1.858492 fluent_1 | 6.338173 1.192497 38 0.000 3.889948 8.559428 -------------+---------------------------------------------------------------- behaviour | cons_2 | -.3921895 .2036074 10 0.025 -.7980049 .0000668 sex_2 | -.4140879 .0856654 204 0.000 -.584815 -.2577346 ravens_2 | .0581239 .0080774 8 0.000 .041952 .0732394 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons_1) | 40.62932 11.21616 1150 23.3229 66.19045 cov(cons_1,cons_2) | .0200158 .4047209 374 -.7502345 .8824169 var(cons_2) | .062687 .0323482 134 .021243 .1446406 -----------------------------+------------------------------------------------ Level 1: id | var(cons_1) | 291.9025 12.35924 737 269.8581 317.831 cov(cons_1,bcons_2) | 6.244346 .7446958 310 4.82972 7.70829 var(bcons_2) | 1 0 0 1 1 ------------------------------------------------------------------------------ . . . . * 19.5 Rats dataset . . . . . . . . . . . . . . . . . . . . . . . . . . .295 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/rats.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/rats.dta obs: 30 vars: 7 21 Oct 2011 12:19 ------------------------------------------------------------------------------- storage display value variable 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.05 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 2.9 Deviance (dbar) = 1008.80 Deviance (thetabar) = 993.35 Effective no. of pars (pd) = 15.45 Bayesian DIC = 1024.25 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1524 2.208992 5087 0.000 147.7354 156.4514 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.7487 2.510519 5079 0.000 196.7146 206.707 -------------+---------------------------------------------------------------- y22 | cons_3 | 244.98 3.029146 5090 0.000 238.8649 250.8977 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.4206 3.793733 5216 0.000 281.9253 296.8125 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.7005 3.864147 5158 0.000 317.2203 332.3868 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 150.5448 41.72183 4917 89.02023 252.8208 cov(cons_1,cons_2) | 156.7688 45.79379 4678 90.00509 268.729 var(cons_2) | 194.0009 54.63939 4536 115.2226 328.337 cov(cons_1,cons_3) | 170.6135 53.13132 4731 93.99026 301.8252 cov(cons_2,cons_3) | 216.6722 63.83473 4622 124.6707 375.763 var(cons_3) | 284.8072 80.50734 4715 169.5511 482.6697 cov(cons_1,cons_4) | 187.4116 63.34569 4663 94.61906 342.4995 cov(cons_2,cons_4) | 247.1761 76.64447 4711 136.5331 438.547 cov(cons_3,cons_4) | 336.7323 97.72963 4795 195.2631 576.7634 var(cons_4) | 443.2681 125.166 4924 262.9208 743.8671 cov(cons_1,cons_5) | 161.0055 60.74064 4807 67.94944 309.0129 cov(cons_2,cons_5) | 208.3804 72.34393 4798 102.6079 385.9168 cov(cons_3,cons_5) | 309.5714 94.67569 4756 171.9433 537.565 cov(cons_4,cons_5) | 413.9161 121.6241 4819 238.5933 698.0395 var(cons_5) | 457.0557 128.4029 4749 275.649 756.3711 ------------------------------------------------------------------------------ . . mcmcsum [RP1]var(cons_1), detail [RP1]var(cons_1) ------------------------------------------------------------------------------ Percentiles Mean 150.5448 0.5% 77.83432 Thinned Chain Length 5000 MCSE of Mean .6104361 2.5% 89.02023 Effective Sample Size 4917 Std. Dev. 41.72183 5% 95.88755 Raftery Lewis (2.5%) 3741 Mode 136.5369 25% 120.9374 Raftery Lewis (97.5%) 3680 P(mean) 0.000 Brooks Draper (mean) 287 P(mode) 0.000 50% 143.6924 P(median) 0.000 75% 171.4833 95% 229.3543 97.5% 252.8208 99.5% 303.1461 ------------------------------------------------------------------------------ . . mcmcsum [RP1]var(cons_1), fiveway . . . . * 19.6 Fitting an autoregressive structure to the variance matrix . . . .298 . . runmlwin, corr MLwiN 3.05 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 2.9 Deviance (dbar) = 1008.80 Deviance (thetabar) = 993.35 Effective no. of pars (pd) = 15.45 Bayesian DIC = 1024.25 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1524 2.208992 5087 0.000 147.7354 156.4514 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.7487 2.510519 5079 0.000 196.7146 206.707 -------------+---------------------------------------------------------------- y22 | cons_3 | 244.98 3.029146 5090 0.000 238.8649 250.8977 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.4206 3.793733 5216 0.000 281.9253 296.8125 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.7005 3.864147 5158 0.000 317.2203 332.3868 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 150.5448 41.72183 4917 89.02023 252.8208 corr(cons_1,cons_2) | .9146766 .0307903 4382 .8431107 .9596643 var(cons_2) | 194.0009 54.63939 4536 115.2226 328.337 corr(cons_1,cons_3) | .8192837 .0617218 4634 .6692283 .912826 corr(cons_2,cons_3) | .9192118 .0298779 4687 .8455406 .9629651 var(cons_3) | 284.8072 80.50734 4715 169.5511 482.6697 corr(cons_1,cons_4) | .7193668 .0897948 4509 .5124113 .8607211 corr(cons_2,cons_4) | .8383934 .056667 4645 .7025362 .9241514 corr(cons_3,cons_4) | .946 .0199762 4522 .8983083 .9755726 var(cons_4) | 443.2681 125.166 4924 262.9208 743.8671 corr(cons_1,cons_5) | .6072154 .1165848 4814 .3401199 .7990369 corr(cons_2,cons_5) | .6933965 .0970805 4950 .4652985 .8474215 corr(cons_3,cons_5) | .8539778 .0514752 4548 .7340332 .9310327 corr(cons_4,cons_5) | .9171058 .0302174 4625 .8454213 .9609179 var(cons_5) | 457.0557 128.4029 4749 275.649 756.3711 ------------------------------------------------------------------------------ . // 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.05 multilevel model Number of obs = 30 Multivariate response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 18.8 Deviance (dbar) = 1015.49 Deviance (thetabar) = 1006.07 Effective no. of pars (pd) = 9.43 Bayesian DIC = 1024.92 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- y8 | cons_1 | 152.1794 2.48877 51375 0.000 147.2693 157.1017 -------------+---------------------------------------------------------------- y15 | cons_2 | 201.782 2.829319 51039 0.000 196.2085 207.3919 -------------+---------------------------------------------------------------- y22 | cons_3 | 245.0477 3.378312 50532 0.000 238.3885 251.7427 -------------+---------------------------------------------------------------- y29 | cons_4 | 289.5249 4.19428 49813 0.000 281.2738 297.8598 -------------+---------------------------------------------------------------- y36 | cons_5 | 324.8249 4.270304 49362 0.000 316.3743 333.2889 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: rat | var(cons_1) | 184.3137 59.43623 233 100.8494 334.8009 corr(cons_1,cons_2) | .9404326 .0184437 305 .8999382 .9709291 var(cons_2) | 237.9948 77.86156 200 129.7229 436.485 corr(cons_1,cons_3) | .8847536 .0344719 300 .8098887 .9427033 corr(cons_2,cons_3) | .9404326 .0184437 305 .8999382 .9709291 var(cons_3) | 339.3825 113.1472 190 184.2081 633.0259 corr(cons_1,cons_4) | .8326868 .048354 296 .7288498 .9152981 corr(cons_2,cons_4) | .8847536 .0344719 300 .8098887 .9427033 corr(cons_3,cons_4) | .9404326 .0184437 305 .8999382 .9709291 var(cons_4) | 523.4675 175.7512 202 285.6372 975.1991 corr(cons_1,cons_5) | .7839772 .0603293 291 .6559198 .8886896 corr(cons_2,cons_5) | .8326868 .048354 296 .7288498 .9152981 corr(cons_3,cons_5) | .8847536 .0344719 300 .8098887 .9427033 corr(cons_4,cons_5) | .9404326 .0184437 305 .8999382 .9709291 var(cons_5) | 540.75 177.8134 237 297.568 999.6031 ------------------------------------------------------------------------------ . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .301 . . . . . . **************************************************************************** . exit end of do-file