------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\10_Multinom > ial_Logistic_Models_for_Unordered_Categorical_Responses.smcl log type: smcl opened on: 27 Mar 2020, 17:42:17 . ***************************************************************************** > *** . * MLwiN User Manual . * . * 10 Multinomial Logistic Models for Unordered Categorical Responses > 145 . * . * Rasbash, J., Steele, F., Browne, W. J. and Goldstein, H. (2012). A User > 's . * Guide to 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/ . ***************************************************************************** > *** . . * 10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . > 145 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/bang.dta", clear . . 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 . . . . * 10.2 Single-level multinomial logistic regression . . . . . . . . . . . . . > 146 . . . . * 10.3 Fitting a single-level multinomial logistic model in MLwiN . . . . . . > 147 . . tabulate lc use4, row +----------------+ | Key | |----------------| | frequency | | row percentage | +----------------+ Number of | living | children | at time of | survey (0 | = None, 1 | = 1 child, | Contraceptive use status and method (1 = 2 = 2 | Sterilization, 2 = Modern reversible me childr | use4_1 use4_2 use4_3 use4_4 | Total -----------+--------------------------------------------+---------- lc0 | 12 134 44 584 | 774 | 1.55 17.31 5.68 75.45 | 100.00 -----------+--------------------------------------------+---------- lc1 | 52 137 45 283 | 517 | 10.06 26.50 8.70 54.74 | 100.00 -----------+--------------------------------------------+---------- lc2 | 69 107 51 234 | 461 | 14.97 23.21 11.06 50.76 | 100.00 -----------+--------------------------------------------+---------- lc3plus | 169 177 142 627 | 1,115 | 15.16 15.87 12.74 56.23 | 100.00 -----------+--------------------------------------------+---------- Total | 302 555 282 1,728 | 2,867 | 10.53 19.36 9.84 60.27 | 100.00 . . label define use4 1 "ster" 2 "mod" 3 "trad" 4 "none", modify . . label values use4 use4 . . generate lc1 = (lc==1) . . generate lc2 = (lc==2) . . generate lc3plus = (lc==3) . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level1(woman) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) /// > basecategory(4)) /// > nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ---------------------------------- Contrast | Log-odds -------------+-------------------- 1 | 1 vs. 4 2 | 2 vs. 4 3 | 3 vs. 4 ---------------------------------- Run time (seconds) = 2.02 Number of iterations = 10 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -3.884982 .2909288 -13.35 0.000 -4.455192 -3.314772 lc1_1 | 2.191199 .3255861 6.73 0.000 1.553062 2.829336 lc2_1 | 2.664648 .3188518 8.36 0.000 2.03971 3.289586 lc3plus_1 | 2.574363 .3026711 8.51 0.000 1.981138 3.167587 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.472055 .0949997 -15.50 0.000 -1.658251 -1.285859 lc1_2 | .7469174 .1376688 5.43 0.000 .4770916 1.016743 lc2_2 | .6903578 .1455586 4.74 0.000 .4050682 .9756474 lc3plus_2 | .2076819 .1254473 1.66 0.098 -.0381902 .453554 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.585701 .1552284 -16.66 0.000 -2.889943 -2.281459 lc1_3 | .7473466 .2200436 3.40 0.001 .3160692 1.178624 lc2_3 | 1.063133 .2147492 4.95 0.000 .6422324 1.484034 lc3plus_3 | 1.101027 .179334 6.14 0.000 .7495383 1.452515 ------------------------------------------------------------------------------ . // We might need to add equation labels for the fixed part equations in the . // model output. For example "Contrast 1", "Contrast 2" and so on. . . display "Pr(y = 1) = " exp([FP1]cons_1)/ /// > (1 + exp([FP1]cons_1) + exp([FP2]cons_2) + exp([FP3]cons_3)) Pr(y = 1) = .01550404 . . display "Pr(y = 2) = " exp([FP2]cons_2)/ /// > (1 + exp([FP1]cons_1) + exp([FP2]cons_2) + exp([FP3]cons_3)) Pr(y = 2) = .17312741 . . display "Pr(y = 3) = " exp([FP3]cons_3)/ /// > (1 + exp([FP1]cons_1) + exp([FP2]cons_2) + exp([FP3]cons_3)) Pr(y = 3) = .056848 . . display "Pr(y = 4) = " 1/ /// > (1 + exp([FP1]cons_1) + exp([FP2]cons_2) + exp([FP3]cons_3)) Pr(y = 4) = .75452055 . . . . * 10.4 A two-level random intercept multinomial logistic regression model 154 . . . . * 10.5 Fitting a two-level random intercept model . . . . . . . . . . . . . . > 155 . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level2(district: cons) /// > level1(woman) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) /// > basecategory(4)) /// > nopause MLwiN 3.05 multilevel model Number of obs = 2867 Unordered multinomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ----------------------------------------------------------- | 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) = 1.64 Number of iterations = 10 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- Contrast 1 | cons_1 | -3.985474 .3137802 -12.70 0.000 -4.600472 -3.370476 lc1_1 | 2.150926 .3391146 6.34 0.000 1.486274 2.815579 lc2_1 | 2.689987 .3312584 8.12 0.000 2.040733 3.339242 lc3plus_1 | 2.658317 .314548 8.45 0.000 2.041814 3.27482 -------------+---------------------------------------------------------------- Contrast 2 | cons_2 | -1.588393 .123751 -12.84 0.000 -1.830941 -1.345846 lc1_2 | .706367 .1435436 4.92 0.000 .4250266 .9877074 lc2_2 | .6866729 .1518692 4.52 0.000 .3890148 .9843311 lc3plus_2 | .2447694 .1307283 1.87 0.061 -.0114533 .5009921 -------------+---------------------------------------------------------------- Contrast 3 | cons_3 | -2.577769 .1696013 -15.20 0.000 -2.910182 -2.245357 lc1_3 | .7263376 .2172709 3.34 0.001 .3004945 1.152181 lc2_3 | 1.061379 .2126313 4.99 0.000 .6446293 1.478129 lc3plus_3 | 1.125481 .1776695 6.33 0.000 .7772551 1.473707 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 2: district | var(cons_1) | .3494722 .1123334 .1293027 .5696417 cov(cons_1,cons_2) | .1105161 .0695678 -.0258342 .2468665 var(cons_2) | .2887424 .0840008 .1241039 .453381 cov(cons_1,cons_3) | .027815 .0726465 -.1145695 .1701995 cov(cons_2,cons_3) | -.0408545 .0636466 -.1655995 .0838905 var(cons_3) | .2602588 .0939646 .0760915 .4444261 ------------------------------------------------------------------------------ . . runmlwin use4 cons lc1 lc2 lc3plus, /// > level2(district: cons, residuals(u)) /// > level1(woman) /// > discrete(distribution(multinomial) link(mlogit) denominator(cons) /// > basecategory(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.82 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 ------------------------------------------------------------------------------ . // Need to use previous model's estimates as starting values for this model . . display %4.3f [RP2]cov(cons_1\cons_2)/sqrt([RP2]var(cons_1)*[RP2]var(cons_2)) 0.687 . . display %4.3f [RP2]cov(cons_1\cons_3)/sqrt([RP2]var(cons_1)*[RP2]var(cons_3)) 0.596 . . display %4.3f [RP2]cov(cons_2\cons_3)/sqrt([RP2]var(cons_2)*[RP2]var(cons_3)) 0.393 . . egen pickone = tag(district) . . egen u0rank = rank(u0) if pickone==1 (2807 missing values generated) . . egen u1rank = rank(u1) if pickone==1 (2807 missing values generated) . . egen u2rank = rank(u2) if pickone==1 (2807 missing values generated) . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) . . serrbar u1 u1se u1rank if pickone==1, scale(1.96) yline(0) . . serrbar u2 u2se u2rank if pickone==1, scale(1.96) yline(0) . . serrbar u0 u0se u0rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u0 u0rank if district==56, mcolor(maroon) msize(3)) > /// > (scatter u0 u0rank if district==11, mcolor(green) msize(3)) / > // > ) legend(off) . . serrbar u1 u1se u1rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u1 u1rank if district==56, mcolor(maroon) msize(3)) > /// > (scatter u1 u1rank if district==11, mcolor(green) msize(3)) / > // > ) legend(off) . . serrbar u2 u2se u2rank if pickone==1, scale(1.96) yline(0) /// > addplot( /// > (scatter u2 u2rank if district==56, mcolor(maroon) msize(3)) > /// > (scatter u2 u2rank if district==11, mcolor(green) msize(3)) / > // > ) legend(off) . . . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . . . . > 159 . . . . ***************************************************************************** > *** . exit end of do-file