------------------------------------------------------------------------------- name: log: Q:\C-modelling\runmlwin\website\logfiles\2020-03-27\16\17_Modellin > g_Spatial_Data.smcl log type: smcl opened on: 27 Mar 2020, 18:00:56 . **************************************************************************** . * MLwiN MCMC Manual . * . * 17 Modelling Spatial Data . . . . . . . . . . . . . . . . . . . . . . 247 . * . * 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/ . **************************************************************************** . . * 17.1 Scottish lip cancer dataset . . . . . . . . . . . . . . . . . . . 247 . . use "http://www.bristol.ac.uk/cmm/media/runmlwin/lips1.dta", clear . . describe Contains data from http://www.bristol.ac.uk/cmm/media/runmlwin/lips1.dta obs: 56 vars: 41 21 Oct 2011 12:19 ------------------------------------------------------------------------------- storage display value variable name type format label variable label ------------------------------------------------------------------------------- area byte %9.0g cons byte %9.0g obs byte %9.0g exp float %9.0g perc_aff byte %9.0g offs float %9.0g pcons byte %9.0g denom byte %9.0g neigh1 byte %9.0g neigh2 byte %9.0g neigh3 byte %9.0g neigh4 byte %9.0g neigh5 byte %9.0g neigh6 byte %9.0g neigh7 byte %9.0g neigh8 byte %9.0g neigh9 byte %9.0g neigh10 byte %9.0g neigh11 byte %9.0g weight1 float %9.0g weight2 float %9.0g weight3 float %9.0g weight4 float %9.0g weight5 float %9.0g weight6 float %9.0g weight7 float %9.0g weight8 float %9.0g weight9 float %9.0g weight10 float %9.0g weight11 float %9.0g wcar1 byte %9.0g wcar2 byte %9.0g wcar3 byte %9.0g wcar4 byte %9.0g wcar5 byte %9.0g wcar6 byte %9.0g wcar7 byte %9.0g wcar8 byte %9.0g wcar9 byte %9.0g wcar10 byte %9.0g wcar11 byte %9.0g ------------------------------------------------------------------------------- Sorted by: . . . . * 17.2 Fixed effects models . . . . . . . . . . . . . . . . . . . . . . .248 . . sort neigh1 area area . . quietly runmlwin obs cons, /// > level3(neigh1:) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > nopause . . runmlwin obs cons, /// > level3(neigh1:) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(on) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ neigh1 | 29 1 1.9 5 area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = .872 Deviance (dbar) = 589.72 Deviance (thetabar) = 588.71 Effective no. of pars (pd) = 1.01 Bayesian DIC = 590.73 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.0032802 .0435525 1181 0.475 -.0880437 .0826515 ------------------------------------------------------------------------------ . . . quietly runmlwin obs cons perc_aff, /// > level3(neigh1:) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) nopause . . runmlwin obs cons perc_aff, /// > level3(neigh1:) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(on) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ neigh1 | 29 1 1.9 5 area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 5000 Thinning = 1 Run time (seconds) = 1.03 Deviance (dbar) = 448.52 Deviance (thetabar) = 446.60 Effective no. of pars (pd) = 1.92 Bayesian DIC = 450.44 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.5463922 .066866 343 0.000 -.6755929 -.4131872 perc_aff | .0738226 .0057366 358 0.000 .062562 .0846667 ------------------------------------------------------------------------------ . . . . * 17.3 Random effects models . . . . . . . . . . . . . . . . . . . . . . 251 . . sort area . . quietly runmlwin obs cons perc_aff, /// > level3(neigh1:) /// > level2(area: cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) nopause . . runmlwin obs cons perc_aff, /// > level3(neigh1:) /// > level2(area:cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(chain(50000) refresh(500)) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (hierarchical) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ neigh1 | 29 1 1.9 5 area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 4.92 Deviance (dbar) = 270.35 Deviance (thetabar) = 230.55 Effective no. of pars (pd) = 39.80 Bayesian DIC = 310.15 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.493404 .173943 328 0.003 -.846928 -.1602624 perc_aff | .0679677 .015423 321 0.001 .0381518 .0981349 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .3869469 .114232 6125 .2104474 .6549768 ------------------------------------------------------------------------------ . . . . * 17.4 A spatial multiple-membership (MM) model . . . . . . . . . . . . .252 . . sort neigh1 area . . quietly runmlwin obs cons perc_aff, /// > level3(neigh1: cons) /// > level2(area: cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) nopause . . runmlwin obs cons perc_aff, /// > level3(neigh1: cons, mmids(neigh1-neigh11) mmweights(weight1-weight11 > )) /// > level2(area:cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(chain(50000) refresh(500)) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ neigh1 | 29 1 1.9 5 area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 7.18 Deviance (dbar) = 270.14 Deviance (thetabar) = 237.40 Effective no. of pars (pd) = 32.74 Bayesian DIC = 302.88 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -.2923987 .2009037 396 0.071 -.6661253 .1295116 perc_aff | .0485072 .0142945 511 0.001 .0193801 .0757081 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: neigh1 | var(cons) | 1.208712 .4661583 1241 .4945217 2.304851 -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .0524236 .0551727 188 .0009633 .1942406 ------------------------------------------------------------------------------ . . . . * 17.5 Other spatial models . . . . . . . . . . . . . . . . . . . . . . .255 . . * 17.6 Fitting a CAR model in MLwiN . . . . . . . . . . . . . . . . . . .255 . . sort area area area . . quietly runmlwin obs perc_aff, /// > level3(area: cons) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) nopause . . . runmlwin obs perc_aff, /// > level3(area: cons, carids(neigh1-neigh11) carweights(wcar1-wcar11) re > siduals(v)) /// > level2(area:) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(chain(50000) refresh(500) savewinbugs( /// > model("car_model.txt", replace) /// > inits("car_inits.txt", replace) /// > data("car_data.txt", replace) /// > )) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 4.32 Deviance (dbar) = 268.84 Deviance (thetabar) = 240.49 Effective no. of pars (pd) = 28.35 Bayesian DIC = 297.20 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- perc_aff | .036134 .0128063 500 0.004 .0106787 .0613298 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: area | var(cons) | .5324557 .1912046 3684 .2506471 .9930311 ------------------------------------------------------------------------------ . . preserve . . keep neigh? area v0_? . . reshape long neigh v0_, i(area) j(order) (note: j = 1 2 3 4 5 6 7 8 9) Data wide -> long ----------------------------------------------------------------------------- Number of obs. 56 -> 504 Number of variables 19 -> 4 j variable (9 values) -> order xij variables: neigh1 neigh2 ... neigh9 -> neigh v0_1 v0_2 ... v0_9 -> v0_ ----------------------------------------------------------------------------- . . drop area order . . rename v0_ v0 . . drop if v0==. (242 observations deleted) . . duplicates drop Duplicates in terms of all variables (206 observations deleted) . . sort v0 . . sum v0 Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- v0 | 56 -.2120542 .5849907 -1.031124 .9234105 . . restore . . /* There is a known MLwiN bug here which will be fixed in version 2.29 > wbscript , /// > model("`c(pwd)'\car_model.txt") /// > data("`c(pwd)'\car_data.txt") /// > inits("`c(pwd)'\car_inits.txt") /// > coda("`c(pwd)'\out") /// > set(beta_1 carmean sigma2_u3) /// > burn(500) update(50000) /// > saving("`c(pwd)'\script.txt", replace) > > > wbrun, script("`c(pwd)'\script.txt") /// > winbugs("C:\WinBUGS14\winbugs14.exe") > > wbcoda, root("`c(pwd)'\out") clear > > mcmcsum beta_1 carmean sigma2_u3, variables > > */ . . . . * 17.7 Including exchangeable random effects . . . . . . . . . . . . . . 259 . . quietly runmlwin obs cons perc_aff, /// > level3(area: cons) /// > level2(area: cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) nopause . . runmlwin obs cons perc_aff, /// > level3(area: cons, carids(neigh1-neigh11) carweights(wcar1-wcar11)) / > // > level2(area: cons) /// > level1(area:) /// > discrete(distribution(poisson) link(log) offset(offs)) /// > mcmc(chain(50000) refresh(500)) initsprevious nopause MLwiN 3.05 multilevel model Number of obs = 56 Poisson response model (cross-classified) Estimation algorithm: MCMC ----------------------------------------------------------- | No. of Observations per Group Level Variable | Groups Minimum Average Maximum ----------------+------------------------------------------ area | 56 1 1.0 1 ----------------------------------------------------------- Burnin = 500 Chain = 50000 Thinning = 1 Run time (seconds) = 7.36 Deviance (dbar) = 267.87 Deviance (thetabar) = 238.30 Effective no. of pars (pd) = 29.57 Bayesian DIC = 297.44 ------------------------------------------------------------------------------ obs | Mean Std. Dev. ESS P [95% Cred. Interval] -------------+---------------------------------------------------------------- cons | -5.945357 1.837258 27 0.000 -10.51395 -2.771848 perc_aff | .0367191 .0129534 635 0.003 .0108994 .0616886 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects Parameters | Mean Std. Dev. ESS [95% Cred. Int] -----------------------------+------------------------------------------------ Level 3: area | var(cons) | .4758265 .1874747 1463 .1842375 .9140724 -----------------------------+------------------------------------------------ Level 2: area | var(cons) | .0262077 .0349809 179 .0007064 .1273319 ------------------------------------------------------------------------------ . . . . * 17.8 Further reading on spatial modelling . . . . . . . . . . . . . . .260 . . * Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . .261 . . . . . . **************************************************************************** . exit end of do-file