------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\14_Adjustin > g_for_Measurement_Errors_in_Predictor_Variables.smcl log type: smcl opened on: 27 Mar 2020, 17:59:38 . **************************************************************************** . * MLwiN MCMC Manual . * . * 14 Adjusting for Measurement Errors in Predictor Variables . . . . . .199 . * . * 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/ . **************************************************************************** . . * 14.1 Effects of measurement error on predictors . . . . . . . . . . . .200 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons standlrt, /// > level1(student: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.60 Number of iterations = 2 Log likelihood = -4880.2547 Deviance = 9760.5094 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.0011911 .0126392 -0.09 0.925 -.0259635 .0235812 standlrt | .5950568 .012727 46.76 0.000 .5701124 .6200012 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6484188 .0143933 .6202084 .6766292 ------------------------------------------------------------------------------ . . sum standlrt Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- standlrt | 4,059 .0018103 .9932241 -2.934953 3.015952 . . set seed 12345 . . generate errors = sqrt(.2)*invnormal(uniform()) . . generate obslrt = standlrt + errors . . runmlwin normexam cons errors, /// > level1(student: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.53 Number of iterations = 2 Log likelihood = -5753.2334 Deviance = 11506.467 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .0003024 .0156739 0.02 0.985 -.0304178 .0310226 errors | .0599091 .0351864 1.70 0.089 -.0090551 .1288732 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .996931 .0221294 .9535581 1.040304 ------------------------------------------------------------------------------ . . runmlwin normexam cons obslrt, /// > level1(student: cons) /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 0.54 Number of iterations = 2 Log likelihood = -5031.8424 Deviance = 10063.685 ------------------------------------------------------------------------------ normexam | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | .0024514 .0131203 0.19 0.852 -.0232639 .0281666 obslrt | .4992614 .0119805 41.67 0.000 .47578 .5227427 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6987052 .0155096 .6683071 .7291034 ------------------------------------------------------------------------------ . . runmlwin normexam cons obslrt, /// > level1(student: cons) /// > mcmc(me(obslrt, variances(.2))) initsprevious /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 5.69 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0035763 .0132946 3800 0.402 -.0219841 .029773 obslrt | .5994104 .0146516 2708 0.000 .5714111 .6278752 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6396957 .015777 3154 .6095901 .6707336 ------------------------------------------------------------------------------ . // Note: MLwiN does not calculate the DIC for measurement error models and so . // the the DIC is not displayed in the runmlwin output. This issue applies . // to all the models in this chapter. . . . * 14.2 Measurement error modelling in multilevel models . . . . . . . . .205 . . . quietly runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > level1(student: cons) /// > nopause . . runmlwin normexam cons standlrt, /// > level2(school: cons standlrt) /// > level1(student: cons) /// > mcmc(on) initsprevious /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 65 2 62.4 198 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 3.1 Deviance (dbar) = 9122.67 Deviance (thetabar) = 9031.18 Effective no. of pars (pd) = 91.50 Bayesian DIC = 9214.17 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0132462 .0398381 243 0.358 -.0890089 .0733577 standlrt | .5568666 .020332 769 0.000 .515988 .5963049 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0970636 .0200401 2964 .06544 .1425988 cov(cons,standlrt) | .0195519 .0073726 1709 .0064736 .0359522 var(standlrt) | .0154917 .0048418 1029 .0080367 .0268087 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5543189 .0124713 4659 .5302743 .5795808 ------------------------------------------------------------------------------ . . quietly runmlwin normexam cons obslrt, /// > level2(school: cons obslrt) /// > level1(student: cons) /// > nopause . . matrix b = e(b) . . matrix V = e(V) . . runmlwin normexam cons obslrt, /// > level2(school: cons obslrt) /// > level1(student: cons) /// > mcmc(on) initsb(b) initsv(V) /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 65 2 62.4 198 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 3.13 Deviance (dbar) = 9421.31 Deviance (thetabar) = 9331.96 Effective no. of pars (pd) = 89.35 Bayesian DIC = 9510.66 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0100644 .0419201 237 0.394 -.0902504 .0815664 obslrt | .4655349 .0182408 853 0.000 .4291214 .5005122 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1075183 .0220663 2985 .0725261 .1575582 cov(cons,obslrt) | .0182442 .0068332 1664 .0062909 .0335194 var(obslrt) | .0116634 .0038208 874 .0057859 .0205562 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5966398 .013422 4656 .57091 .6239284 ------------------------------------------------------------------------------ . . runmlwin normexam cons obslrt, /// > level2(school: cons obslrt) /// > level1(student: cons) /// > mcmc(me(obslrt, variances(.2))) initsb(b) initsv(V) /// > nopause MLwiN 3.05 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ school | 65 2 62.4 198 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 8.16 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0122014 .0437061 200 0.390 -.094234 .0760216 obslrt | .5582847 .0243416 452 0.000 .5116396 .6093998 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1076406 .0227316 2994 .0711578 .1588089 cov(cons,obslrt) | .0238448 .0089281 1888 .0085614 .0440043 var(obslrt) | .0206058 .0063763 935 .0105738 .0354876 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5361459 .013942 2871 .5092783 .5630482 ------------------------------------------------------------------------------ . . . . * 14.3 Measurement errors in binomial models . . . . . . . . . . . . . . 208 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/bang1.dta", clear . . runmlwin use cons age, /// > level2(district:) /// > level1(woman:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > nopause MLwiN 3.05 multilevel model Number of obs = 1934 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 2 32.2 118 ----------------------------------------------------------- Run time (seconds) = 0.63 Number of iterations = 4 ------------------------------------------------------------------------------ use | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.4374049 .0465911 -9.39 0.000 -.5287218 -.3460881 age | .0065665 .0051583 1.27 0.203 -.0035436 .0166766 ------------------------------------------------------------------------------ . . sum age Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- age | 1,934 .0020481 9.013413 -13.56 19.44 . . set seed 12345 . . generate obsage = age + sqrt(25)*invnormal(uniform()) . . runmlwin use cons obsage, /// > level2(district:) /// > level1(woman:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > nopause MLwiN 3.05 multilevel model Number of obs = 1934 Binomial logit response model (hierarchical) Estimation algorithm: IGLS, MQL1 ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 2 32.2 118 ----------------------------------------------------------- Run time (seconds) = 0.55 Number of iterations = 4 ------------------------------------------------------------------------------ use | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- cons | -.4368638 .0465717 -9.38 0.000 -.5281427 -.3455849 obsage | .0024949 .0045861 0.54 0.586 -.0064936 .0114834 ------------------------------------------------------------------------------ . . runmlwin use cons obsage, /// > level2(district:) /// > level1(woman:) /// > discrete(distribution(binomial) link(logit) denominator(cons)) /// > mcmc(me(obsage, variances(25))) initsprevious /// > nopause MLwiN 3.05 multilevel model Number of obs = 1934 Binomial logit response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ district | 60 2 32.2 118 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 8.19 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ use | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.4382539 .0469166 1233 0.000 -.5280212 -.3475082 obsage | .0035351 .0061984 715 0.290 -.0084177 .0161677 ------------------------------------------------------------------------------ . . . . * 14.4 Measurement errors in more than one variable and . * misclassifications . . . . . . . . . . . . . . . . . . . . . . . .211 . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .212 . . . . . . **************************************************************************** . exit end of do-file