------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2024-10-11\18\14_Adjustin > g_for_Measurement_Errors_in_Predictor_Variables.smcl log type: smcl opened on: 11 Oct 2024, 17:37:28 . **************************************************************************** . * 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 . * https://www.bristol.ac.uk/cmm/software/runmlwin/ . **************************************************************************** . . * 14.1 Effects of measurement error on predictors . . . . . . . . . . . .200 . . use "https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear . . runmlwin normexam cons standlrt, /// > level1(student: cons) /// > nopause MLwiN 3.13 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 2.40 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.13 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 2.69 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.13 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: IGLS Run time (seconds) = 2.91 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.13 multilevel model Number of obs = 4059 Normal response model (hierarchical) Estimation algorithm: MCMC Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 15.1 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | .0028188 .0132448 4413 0.421 -.023065 .028855 obslrt | .5995696 .0141621 2956 0.000 .5724587 .6271179 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .6394031 .0157959 3189 .6092296 .6713067 ------------------------------------------------------------------------------ . // 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.13 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) = 11.7 Deviance (dbar) = 9123.21 Deviance (thetabar) = 9031.71 Effective no. of pars (pd) = 91.49 Bayesian DIC = 9214.70 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0125681 .040883 249 0.381 -.0905471 .0686477 standlrt | .5564547 .0208367 706 0.000 .5150133 .597012 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .0971118 .0200117 2667 .0646451 .1426135 cov(cons,standlrt) | .0193325 .0073905 1722 .0065965 .0353707 var(standlrt) | .0152639 .0048458 957 .0077234 .0266211 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5543991 .0124193 4550 .5305235 .5790426 ------------------------------------------------------------------------------ . . 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.13 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) = 11.7 Deviance (dbar) = 9421.61 Deviance (thetabar) = 9332.15 Effective no. of pars (pd) = 89.46 Bayesian DIC = 9511.07 ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0095668 .0429144 247 0.412 -.0909746 .0756932 obslrt | .4650918 .0185926 767 0.000 .4278253 .5013138 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .107609 .0220156 2709 .0719235 .1577375 cov(cons,obslrt) | .0180039 .0068728 1645 .0058587 .0327024 var(obslrt) | .0115336 .0038221 842 .005615 .0205399 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5966916 .0133593 4551 .570919 .6230736 ------------------------------------------------------------------------------ . . runmlwin normexam cons obslrt, /// > level2(school: cons obslrt) /// > level1(student: cons) /// > mcmc(me(obslrt, variances(.2))) initsb(b) initsv(V) /// > nopause MLwiN 3.13 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) = 22.8 Deviance (dbar) = . Deviance (thetabar) = . Effective no. of pars (pd) = . Bayesian DIC = . ------------------------------------------------------------------------------ normexam | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0084625 .0427539 210 0.409 -.0880751 .0781907 obslrt | .5591957 .0223216 635 0.000 .515118 .6021848 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: school | var(cons) | .1075224 .0221239 2719 .0715518 .1571489 cov(cons,obslrt) | .0232816 .0087919 1714 .0083937 .0422967 var(obslrt) | .0203587 .006291 908 .0102639 .0348222 -----------------------------+------------------------------------------------ Level 1: student | var(cons) | .5361357 .0139522 2626 .5090376 .5644649 ------------------------------------------------------------------------------ . . . . * 14.3 Measurement errors in binomial models . . . . . . . . . . . . . . 208 . . use "https://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.13 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) = 2.91 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.13 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) = 2.71 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.13 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) = 23 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