------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\12_Unordere > d_Categorical_Responses.smcl log type: smcl opened on: 27 Mar 2020, 17:55:03 . **************************************************************************** . * MLwiN MCMC Manual . * . * 12 Unordered Categorical Responses . . . . . . . . . . . . . . . . . .167 . * . * 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/ . **************************************************************************** . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/bang.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/bang.dta obs: 2,867 vars: 12 12 Mar 2014 22:22 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- woman float %9.0g Identifying code for each woman (level 1 unit) district float %9.0g Identifying code for each district (level 2 unit) use float %9.0g Contraceptive use status at a time of survey (1 = using contraception, 2 = not u use4 float %9.0g use4 Contraceptive use status and method (1 = Sterilization, 2 = Modern reversible me lc float %9.0g lc Number of living children at time of survey (0 = None, 1 = 1 child, 2 = 2 childr age float %9.0g Age of woman at time of survey (in years), centred on the sample mean of 30 year urban float %9.0g Type of region of residence (1 = Urban, 0 = Rural) educ float %9.0g educ Womans level of education (1 = None, 2 = Lower primary, 3 = Upper primary, 4 = S hindu float %9.0g Womans religion (1 = Hindu, 0 = Muslim) d_lit float %9.0g Proportion of women in district who are literate d_pray float %9.0g Proportion of Muslim women in district who pray every day (a measure of religios cons float %9.0g constant vector ------------------------------------------------------------------------------- Sorted by: . . tabulate use4 Contracepti | ve use | status and | method (1 = | Sterilizati | on, 2 = | Modern | reversible | me | Freq. Percent Cum. ------------+----------------------------------- use4_1 | 302 10.53 10.53 use4_2 | 555 19.36 29.89 use4_3 | 282 9.84 39.73 use4_4 | 1,728 60.27 100.00 ------------+----------------------------------- Total | 2,867 100.00 . . . . * 12.1 Fitting a first single-level multinomial model . . . . . . . . . .169 . . label define use4 1 "ster" 2 "mod" 3 "trad" 4 "none", modify . . label values use4 use4 . . quietly runmlwin use4 cons, /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4)) /// > nopause . . runmlwin use4 cons, /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4)) /// > mcmc(on) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: MCMC ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 7.03 Deviance (dbar) = 6242.82 Deviance (thetabar) = 6239.81 Effective no. of pars (pd) = 3.02 Bayesian DIC = 6245.84 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -1.748509 .0631694 1049 0.000 -1.876236 -1.626482 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.138784 .0489615 1115 0.000 -1.234721 -1.040707 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -1.816065 .0641057 1153 0.000 -1.941197 -1.690176 ------------------------------------------------------------------------------ . . display "Pr(y = 1) = " exp([FP1]cons_1)/(1 + exp([FP1]cons_1) + exp([FP2]cons > _2) + exp([FP3]cons_3)) Pr(y = 1) = .10503504 . . display "Pr(y = 2) = " exp([FP2]cons_2)/(1 + exp([FP1]cons_1) + exp([FP2]cons > _2) + exp([FP3]cons_3)) Pr(y = 2) = .19325675 . . display "Pr(y = 3) = " exp([FP3]cons_3)/(1 + exp([FP1]cons_1) + exp([FP2]cons > _2) + exp([FP3]cons_3)) Pr(y = 3) = .09817366 . . . . * 12.2 Adding predictor variables . . . . . . . . . . . . . . . . . . . .173 . . generate lc1 = (lc==1) . . generate lc2 = (lc==2) . . generate lc3plus = (lc==3) . . quietly runmlwin use4 cons lc1 lc2 lc3plus, /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4)) /// > nopause . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4)) /// > mcmc(on) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: MCMC ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 18.4 Deviance (dbar) = 6039.59 Deviance (thetabar) = 6027.84 Effective no. of pars (pd) = 11.75 Bayesian DIC = 6051.34 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -3.897742 .2849606 40 0.000 -4.401571 -3.360731 lc1_1 | 2.196797 .3246128 48 0.000 1.563572 2.788485 lc2_1 | 2.676579 .3176124 47 0.000 2.055553 3.259204 lc3plus_1 | 2.581761 .2962074 42 0.000 2.013787 3.104774 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.468546 .0993965 103 0.000 -1.675931 -1.277654 lc1_2 | .7401686 .1445398 198 0.000 .4415598 1.026463 lc2_2 | .681165 .1577654 205 0.000 .373595 1.003115 lc3plus_2 | .1956799 .1313905 135 0.069 -.0463739 .4645209 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.57291 .1461545 113 0.000 -2.864579 -2.303376 lc1_3 | .7196813 .2141236 188 0.000 .2920618 1.138882 lc2_3 | 1.043703 .2135633 227 0.000 .6272799 1.459986 lc3plus_3 | 1.083388 .1674781 133 0.000 .7605178 1.4126 ------------------------------------------------------------------------------ . // Note: These estinmates differ slightly from those presented in the . // manual. This is likely to be because the parameters have low ESS. . . display "Pr(y = 3) = " exp([FP3]cons_3)/(1 + exp([FP1]cons_1) + exp([FP2]cons > _2) + exp([FP3]cons_3)) Pr(y = 3) = .05751408 . . display "Pr(y = 3) = " exp([FP3]cons_3 + [FP3]lc2_3)/( /// > 1 /// > + exp([FP1]cons_1 + [FP1]lc2_1) /// > + exp([FP2]cons_2 + [FP2]lc2_2) /// > + exp([FP3]cons_3 + [FP3]lc2_3) /// > ) Pr(y = 3) = .11019236 . . . . * 12.3 Interval estimates for conditional probabilities . . . . . . . . .175 . . preserve . . mcmcsum, getchains . . generate pred1 = exp(FP3_cons_3)/(1 + exp(FP1_cons_1) + exp(FP2_cons_ > 2) + exp(FP3_cons_3)) . . mcmcsum pred1, variables detail pred1 ------------------------------------------------------------------------------ Percentiles Mean .0579403 0.5% .0405376 Thinned Chain Length 5000 MCSE of Mean .000602 2.5% .0438596 Effective Sample Size 118 Std. Dev. .0078866 5% .045319 Raftery Lewis (2.5%) 30882 Mode .0568622 25% .0521719 Raftery Lewis (97.5%) 28152 P(mean) 0.000 Brooks Draper (mean) 27840 P(mode) 0.000 50% .0575219 P(median) 0.000 75% .0631978 95% .0711756 97.5% .0735539 99.5% .0811793 ------------------------------------------------------------------------------ . . mcmcsum pred1, variables fiveway . . generate pred2 = exp(FP3_cons_3 + FP3_lc2_3)/( /// > 1 /// > + exp(FP1_cons_1 + FP1_lc2_1) /// > + exp(FP2_cons_2 + FP2_lc2_2) /// > + exp(FP3_cons_3 + FP3_lc2_3) /// > ) . . mcmcsum pred2, variables detail pred2 ------------------------------------------------------------------------------ Percentiles Mean .1107532 0.5% .0775767 Thinned Chain Length 5000 MCSE of Mean .0003859 2.5% .0846945 Effective Sample Size 1355 Std. Dev. .0141981 5% .0887056 Raftery Lewis (2.5%) 9497 Mode .1098385 25% .1009345 Raftery Lewis (97.5%) 9497 P(mean) 0.000 Brooks Draper (mean) 115 P(mode) 0.000 50% .1103717 P(median) 0.000 75% .1197964 95% .1350157 97.5% .1406584 99.5% .1503346 ------------------------------------------------------------------------------ . . mcmcsum pred2, variables fiveway . . restore . . . . * 12.4 Adding district level random effects . . . . . . . . . . . . . . .177 . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level2(district: cons) /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4) pql2) /// > nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: IGLS, PQL2 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 3 47.8 173 ----------------------------------------------------------- ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Run time (seconds) = 2.79 Number of iterations = 12 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -4.229931 .3188144 -13.27 0.000 -4.854796 -3.605066 lc1_1 | 2.225284 .3360691 6.62 0.000 1.566601 2.883968 lc2_1 | 2.827055 .3291096 8.59 0.000 2.182012 3.472098 lc3plus_1 | 2.796275 .312623 8.94 0.000 2.183545 3.409005 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.749175 .132537 -13.20 0.000 -2.008943 -1.489408 lc1_2 | .7767676 .1425218 5.45 0.000 .4974301 1.056105 lc2_2 | .8066867 .1500877 5.37 0.000 .5125202 1.100853 lc3plus_2 | .338661 .1296401 2.61 0.009 .0845711 .5927509 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.724347 .1787014 -15.25 0.000 -3.074595 -2.374099 lc1_3 | .7477972 .2259528 3.31 0.001 .3049379 1.190657 lc2_3 | 1.152377 .2193549 5.25 0.000 .7224496 1.582305 lc3plus_3 | 1.192561 .1837908 6.49 0.000 .8323381 1.552785 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: district | var(cons_1) | .5435652 .155461 .2388671 .8482632 cov(cons_1,cons_2) | .3182957 .0999377 .1224215 .51417 var(cons_2) | .3951255 .1071843 .1850481 .6052029 cov(cons_1,cons_3) | .2527503 .0987631 .0591782 .4463224 cov(cons_2,cons_3) | .1421735 .0794187 -.0134842 .2978313 var(cons_3) | .3314103 .1121805 .1115406 .5512799 ------------------------------------------------------------------------------ . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level2(district: cons) /// > level1(woman:) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) bas > ecategory(4)) /// > mcmc(on) initsprevious /// > nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 3 47.8 173 ----------------------------------------------------------- ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 26 Deviance (dbar) = 5731.46 Deviance (thetabar) = 5625.65 Effective no. of pars (pd) = 105.81 Bayesian DIC = 5837.27 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -4.293144 .3492054 24 0.000 -4.966027 -3.626727 lc1_1 | 2.3565 .3770289 25 0.000 1.632585 3.059089 lc2_1 | 2.921829 .3666105 26 0.000 2.189112 3.608921 lc3plus_1 | 2.865661 .356059 24 0.000 2.13936 3.519755 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.731262 .1335327 97 0.000 -1.991882 -1.481063 lc1_2 | .7925716 .1527648 232 0.000 .4776904 1.096285 lc2_2 | .7903608 .1563193 365 0.000 .4817096 1.093325 lc3plus_2 | .3204136 .1340109 167 0.008 .0586805 .5856249 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.736236 .173057 89 0.000 -3.083353 -2.392503 lc1_3 | .8042364 .2234095 199 0.000 .3533741 1.260015 lc2_3 | 1.170955 .2168812 174 0.000 .7406655 1.58986 lc3plus_3 | 1.216824 .1825645 113 0.000 .8438071 1.555939 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: district | var(cons_1) | .6030189 .1898287 303 .3197914 1.06581 cov(cons_1,cons_2) | .3578824 .1218844 405 .1600972 .6372123 var(cons_2) | .4441285 .1237009 490 .2528002 .7361202 cov(cons_1,cons_3) | .2951923 .1210736 292 .0992775 .5669336 cov(cons_2,cons_3) | .1643346 .0930736 407 -.0050004 .3673066 var(cons_3) | .3860301 .1268921 274 .1885399 .6818123 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons_1), detail [RP2]var(cons_1) ------------------------------------------------------------------------------ Percentiles Mean .6030189 0.5% .2591327 Thinned Chain Length 5000 MCSE of Mean .0055428 2.5% .3197914 Effective Sample Size 303 Std. Dev. .1898287 5% .3489368 Raftery Lewis (2.5%) 21364 Mode .5506 25% .4706774 Raftery Lewis (97.5%) 18747 P(mean) 0.000 Brooks Draper (mean) 23605 P(mode) 0.000 50% .5753058 P(median) 0.000 75% .7052604 95% .9547272 97.5% 1.06581 99.5% 1.313386 ------------------------------------------------------------------------------ . . mcmcsum [RP2]var(cons_1), fiveway . . runmlwin, corr MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 3 47.8 173 ----------------------------------------------------------- ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 26 Deviance (dbar) = 5731.46 Deviance (thetabar) = 5625.65 Effective no. of pars (pd) = 105.81 Bayesian DIC = 5837.27 ------------------------------------------------------------------------------ | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -4.293144 .3492054 24 0.000 -4.966027 -3.626727 lc1_1 | 2.3565 .3770289 25 0.000 1.632585 3.059089 lc2_1 | 2.921829 .3666105 26 0.000 2.189112 3.608921 lc3plus_1 | 2.865661 .356059 24 0.000 2.13936 3.519755 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.731262 .1335327 97 0.000 -1.991882 -1.481063 lc1_2 | .7925716 .1527648 232 0.000 .4776904 1.096285 lc2_2 | .7903608 .1563193 365 0.000 .4817096 1.093325 lc3plus_2 | .3204136 .1340109 167 0.008 .0586805 .5856249 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.736236 .173057 89 0.000 -3.083353 -2.392503 lc1_3 | .8042364 .2234095 199 0.000 .3533741 1.260015 lc2_3 | 1.170955 .2168812 174 0.000 .7406655 1.58986 lc3plus_3 | 1.216824 .1825645 113 0.000 .8438071 1.555939 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: district | var(cons_1) | .6030189 .1898287 303 .3197914 1.06581 corr(cons_1,cons_2) | .6924411 .1185274 404 .4193966 .8734696 var(cons_2) | .4441285 .1237009 490 .2528002 .7361202 corr(cons_1,cons_3) | .6110921 .1523112 296 .2632704 .8497201 corr(cons_2,cons_3) | .3967106 .183439 367 -.011849 .7117801 var(cons_3) | .3860301 .1268921 274 .1885399 .6818123 ------------------------------------------------------------------------------ . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .180 . . . . . . **************************************************************************** . exit end of do-file