------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\15_Cross_Cl > assified_Models.smcl log type: smcl opened on: 11 Oct 2024, 17:39:13 . **************************************************************************** . * MLwiN MCMC Manual . * . * 15 Cross Classified Models . . . . . . . . . . . . . . . . . . . . . .215 . * . * 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/ . **************************************************************************** . . * 15.1 Classifications and levels . . . . . . . . . . . . . . . . . . . .216 . . * 15.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217 . . * 15.3 The Fife educational dataset . . . . . . . . . . . . . . . . . . .217 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/xc1.dta", clear . . describe Contains data from https://www.bristol.ac.uk/cmm/media/runmlwin/xc1.dta Observations: 3,435 Variables: 11 21 Oct 2011 12:19 ------------------------------------------------------------------------------- Variable Storage Display Value name type format label Variable label ------------------------------------------------------------------------------- vrq int %9.0g attain byte %9.0g pid int %9.0g sex byte %9.0g sc byte %9.0g sid byte %9.0g fed byte %9.0g choice byte %9.0g med byte %9.0g cons byte %9.0g pupil byte %9.0g ------------------------------------------------------------------------------- Sorted by: . . list attain pid sid pupil in 1/10 +----------------------------+ | attain pid sid pupil | |----------------------------| 1. | 2 1 1 39 | 2. | 8 1 1 37 | 3. | 6 1 1 48 | 4. | 6 1 1 41 | 5. | 4 1 1 7 | |----------------------------| 6. | 2 1 1 50 | 7. | 9 1 1 17 | 8. | 6 1 1 8 | 9. | 10 5 1 46 | 10. | 2 5 1 44 | +----------------------------+ . . runmlwin attain cons, /// > level3(sid: cons) level2(pid:) /// > level1(pupil: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 303 1 11.3 72 ----------------------------------------------------------- Run time (seconds) = 2.66 Number of iterations = 3 Log likelihood = -8666.0243 Deviance = 17332.049 ------------------------------------------------------------------------------ attain | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 5.588558 .1573136 35.52 0.000 5.280229 5.896887 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .4148371 .1510997 .1186872 .7109871 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 8.986666 .2174585 8.560455 9.412877 ------------------------------------------------------------------------------ . . runmlwin attain cons, /// > level3(sid: cons) level2(pid:) /// > level1(pupil: cons) /// > mcmc(on) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 303 1 11.3 72 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 8.47 Deviance (dbar) = 17291.83 Deviance (thetabar) = 17273.63 Effective no. of pars (pd) = 18.20 Bayesian DIC = 17310.02 ------------------------------------------------------------------------------ attain | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | 5.586465 .1613754 309 0.000 5.282391 5.922693 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .4928488 .208338 2402 .2212031 1.030093 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 8.99649 .2180419 5451 8.565801 9.429998 ------------------------------------------------------------------------------ . . . . * 15.4 A Cross-classified model . . . . . . . . . . . . . . . . . . . . .220 . . runmlwin attain cons, /// > level3(sid: cons) level2(pid: cons) /// > level1(pupil: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 303 1 11.3 72 ----------------------------------------------------------- Run time (seconds) = 2.88 Number of iterations = 4 Log likelihood = -8579.2042 Deviance = 17158.408 ------------------------------------------------------------------------------ attain | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | 5.484828 .1541146 35.59 0.000 5.182769 5.786887 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .2687809 .1460812 -.0175329 .5550948 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | 1.100592 .1926005 .7231016 1.478082 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 8.096222 .2014243 7.701438 8.491007 ------------------------------------------------------------------------------ . . runmlwin attain cons, /// > level3(sid: cons, residuals(v)) /// > level2(pid: cons, residuals(u)) /// > level1(pupil: cons) /// > mcmc(cc on) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 148 1 23.2 72 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 11.9 Deviance (dbar) = 16940.80 Deviance (thetabar) = 16833.53 Effective no. of pars (pd) = 107.26 Bayesian DIC = 17048.06 ------------------------------------------------------------------------------ attain | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | 5.508514 .1919313 206 0.000 5.110681 5.881994 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .4200779 .2197727 1155 .1403941 .9762861 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | 1.144871 .2109528 1225 .7822415 1.599638 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 8.120436 .197473 3972 7.737964 8.519949 ------------------------------------------------------------------------------ . . mcmcsum [RP3]var(cons), detail [RP3]var(cons) ------------------------------------------------------------------------------ Percentiles Mean .4200779 0.5% .1003618 Thinned Chain Length 5000 MCSE of Mean .0050428 2.5% .1403941 Effective Sample Size 1155 Std. Dev. .2197727 5% .1623108 Raftery Lewis (2.5%) 7397 Mode .3439998 25% .269787 Raftery Lewis (97.5%) 4410 P(mean) 0.000 Brooks Draper (mean) 19538 P(mode) 0.000 50% .3732005 P(median) 0.000 75% .5141783 95% .8309478 97.5% .976286 99.5% 1.352075 ------------------------------------------------------------------------------ . . . . * 15.5 Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 . . egen pickone = tag(sid) . . egen v0rank = rank(v0) if pickone==1 (3,416 missing values generated) . . serrbar v0 v0se v0rank if pickone==1, scale(0) yline(0) . . list sid v0 if v0rank==1 & pickone==1 +----------------+ | sid v0 | |----------------| 3325. | 19 -1.39007 | +----------------+ . . drop pickone . . egen pickone = tag(pid) . . egen u0rank = rank(u0) if pickone==1 (3,287 missing values generated) . . serrbar u0 u0se u0rank if pickone==1, scale(0) yline(0) . . list pid u0 if u0rank==1 & pickone==1 +-----------------+ | pid u0 | |-----------------| 2545. | 139 -2.132843 | +-----------------+ . . drop v0* u0* pickone . . . . * 15.6 Adding predictors to the model . . . . . . . . . . . . . . . . . .225 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/xc1.dta", clear . . runmlwin attain cons vrq, /// > level3(sid: cons) level2(pid: cons) /// > level1(pupil: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 303 1 11.3 72 ----------------------------------------------------------- Run time (seconds) = 3.05 Number of iterations = 5 Log likelihood = -7427.3516 Deviance = 14854.703 ------------------------------------------------------------------------------ attain | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -10.05434 .2765236 -36.36 0.000 -10.59632 -9.512368 vrq | .1602103 .0027673 57.89 0.000 .1547864 .1656342 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .0075894 .021663 -.0348693 .050048 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .2648826 .060114 .1470613 .3827039 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.258025 .1053973 4.05145 4.4646 ------------------------------------------------------------------------------ . . runmlwin attain cons vrq, /// > level3(sid: cons) level2(pid: cons) /// > level1(pupil: cons) /// > mcmc(cc) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 148 1 23.2 72 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 12.6 Deviance (dbar) = 14724.88 Deviance (thetabar) = 14643.74 Effective no. of pars (pd) = 81.14 Bayesian DIC = 14806.02 ------------------------------------------------------------------------------ attain | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -10.02868 .2826271 3147 0.000 -10.5856 -9.487169 vrq | .1600665 .0028067 3470 0.000 .1546931 .1655475 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .0188295 .0222991 283 .0008784 .0823006 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .2775778 .0634457 814 .1706908 .4183626 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.26071 .1073969 4576 4.055581 4.472723 ------------------------------------------------------------------------------ . . runmlwin attain cons vrq sc fed med choice, /// > level3(sid: cons) level2(pid: cons) /// > level1(pupil: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 303 1 11.3 72 ----------------------------------------------------------- Run time (seconds) = 2.56 Number of iterations = 3 Log likelihood = -7377.2035 Deviance = 14754.407 ------------------------------------------------------------------------------ attain | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -9.7401 .2873173 -33.90 0.000 -10.30323 -9.176968 vrq | .1552553 .00278 55.85 0.000 .1498067 .160704 sc | .0276984 .00335 8.27 0.000 .0211326 .0342642 fed | .220777 .0925128 2.39 0.017 .0394553 .4020988 med | .2179099 .0867628 2.51 0.012 .047858 .3879618 choice | -.1189545 .0551383 -2.16 0.031 -.2270236 -.0108855 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | 0 0 0 0 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .2031402 .0480276 .1090079 .2972726 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.162167 .1028999 3.960487 4.363848 ------------------------------------------------------------------------------ . . runmlwin attain cons vrq sc fed med choice, /// > level3(sid: cons, residuals(v)) level2(pid: cons) /// > level1(pupil: cons) /// > mcmc(cc) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ sid | 19 92 180.8 290 pid | 148 1 23.2 72 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 13.1 Deviance (dbar) = 14650.71 Deviance (thetabar) = 14573.78 Effective no. of pars (pd) = 76.92 Bayesian DIC = 14727.63 ------------------------------------------------------------------------------ attain | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -9.717939 .2886991 3442 0.000 -10.27783 -9.159999 vrq | .1551094 .0027733 3895 0.000 .1496842 .1604899 sc | .0271288 .0033424 4070 0.000 .0206496 .0338125 fed | .2163849 .0915564 5173 0.008 .0384571 .3977609 med | .2195023 .08698 4733 0.005 .0501625 .3898596 choice | -.1200985 .0556301 4529 0.015 -.230301 -.0126298 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: sid | var(cons) | .0157202 .0180503 341 .0006169 .0657573 -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .2075005 .0514208 736 .1224138 .3215004 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.166411 .1037384 4273 3.970953 4.378893 ------------------------------------------------------------------------------ . . egen pickone = tag(sid) . . egen v0rank = rank(v0) if pickone==1 (3,416 missing values generated) . . serrbar v0 v0se v0rank if pickone==1, scale(0) yline(0) . . list sid v0 if v0rank==1 & pickone==1 +-----------------+ | sid v0 | |-----------------| 3325. | 19 -.1086284 | +-----------------+ . . gen school19 = (sid==19) . . sort pid pupil . . runmlwin attain cons vrq sc fed med choice school19, /// > level2(pid: cons) /// > level1(pupil: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: IGLS ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ pid | 148 1 23.2 72 ----------------------------------------------------------- Run time (seconds) = 3.00 Number of iterations = 3 Log likelihood = -7370.9297 Deviance = 14741.859 ------------------------------------------------------------------------------ attain | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -9.650131 .2888852 -33.40 0.000 -10.21634 -9.083926 vrq | .1547908 .0027836 55.61 0.000 .1493351 .1602465 sc | .0268615 .0033494 8.02 0.000 .0202968 .0334261 fed | .213288 .0923322 2.31 0.021 .0323202 .3942558 med | .224737 .0866031 2.60 0.009 .0549981 .394476 choice | -.1235296 .0548632 -2.25 0.024 -.2310594 -.0159997 school19 | -.6225944 .2457284 -2.53 0.011 -1.104213 -.1409756 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .1986834 .0464089 .1077237 .2896431 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.156813 .1021516 3.9566 4.357027 ------------------------------------------------------------------------------ . . runmlwin attain cons vrq sc fed med choice school19, /// > level2(pid: cons) /// > level1(pupil: cons) /// > mcmc(on) initsprevious nopause MLwiN 3.13 multilevel model Number of obs = 3435 Normal response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ pid | 148 1 23.2 72 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 13.4 Deviance (dbar) = 14650.48 Deviance (thetabar) = 14575.90 Effective no. of pars (pd) = 74.58 Bayesian DIC = 14725.07 ------------------------------------------------------------------------------ attain | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -9.650843 .2884154 3777 0.000 -10.21938 -9.091095 vrq | .154779 .0027822 4086 0.000 .1494459 .1602475 sc | .0268286 .0034023 4068 0.000 .0201734 .0336186 fed | .2162477 .0943412 4780 0.013 .0301058 .4009758 med | .2236038 .0882634 5091 0.006 .0484659 .394668 choice | -.1233371 .0547212 4256 0.013 -.2300849 -.0155371 school19 | -.6201495 .2440772 2375 0.006 -1.092106 -.1404474 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: pid | var(cons) | .2034456 .0498983 679 .1172442 .3147747 -----------------------------+------------------------------------------------ Level 1: pupil | var(cons) | 4.167899 .1021151 4180 3.974385 4.371827 ------------------------------------------------------------------------------ . . . . * 15.7 Current restrictions for cross-classified models . . . . . . . . .229 . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .230 . . . . . . **************************************************************************** . exit end of do-file