R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ############################################################################ > # MLwiN User Manual > # > # 6 Contextual Effects . . . . . . . . . . . . . . . . . . . . . . . . .79 > # > # 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. > ############################################################################ > # R script to replicate all analyses using R2MLwiN > # > # Zhang, Z., Charlton, C., Parker, R, Leckie, G., and Browne, W.J. > # Centre for Multilevel Modelling, 2012 > # http://www.bristol.ac.uk/cmm/software/R2MLwiN/ > ############################################################################ > > library(R2MLwiN) R2MLwiN: A package to run models implemented in MLwiN from R Copyright 2013-2017 Zhengzheng Zhang, Christopher M. J. Charlton, Richard M. A. Parker, William J. Browne and George Leckie Support provided by the Economic and Social Research Council (ESRC) (Grants RES-149-25-1084, RES-576-25-0032 and ES/K007246/1) To cite R2MLwiN in publications use: Zhengzheng Zhang, Richard M. A. Parker, Christopher M. J. Charlton, George Leckie, William J. Browne (2016). R2MLwiN: A Package to Run MLwiN from within R. Journal of Statistical Software, 72(10), 1-43. doi:10.18637/jss.v072.i10 A BibTeX entry for LaTeX users is @Article{, title = {{R2MLwiN}: A Package to Run {MLwiN} from within {R}}, author = {Zhengzheng Zhang and Richard M. A. Parker and Christopher M. J. Charlton and George Leckie and William J. Browne}, journal = {Journal of Statistical Software}, year = {2016}, volume = {72}, number = {10}, pages = {1--43}, doi = {10.18637/jss.v072.i10}, } The MLwiN_path option is currently set to C:/Program Files/MLwiN v3.05/ To change this use: options(MLwiN_path="") > # MLwiN folder > mlwin <- getOption("MLwiN_path") > while (!file.access(mlwin, mode = 1) == 0) { + cat("Please specify the root MLwiN folder or the full path to the MLwiN executable:\n") + mlwin <- scan(what = character(0), sep = "\n") + mlwin <- gsub("\\", "/", mlwin, fixed = TRUE) + } > options(MLwiN_path = mlwin) > > > data(tutorial, package = "R2MLwiN") > > (mymodel1 <- runMLwiN(normexam ~ 1 + standlrt + (1 + standlrt | school) + (1 | student), data = tutorial)) /nogui option ignored ECHO 0 Echoing is ON BATC 1 Batch mode is ON MAXI 2 STAR iteration 0 iteration 1 Convergence not achieved TOLE 2 MAXI 20 NEXT iteration 2 iteration 3 Convergence achieved ECHO 0 Execution completed -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MLwiN (version: 3.05) multilevel model (Normal) N min mean max N_complete min_complete mean_complete max_complete school 65 2 62.44615 198 65 2 62.44615 198 Estimation algorithm: IGLS Elapsed time : 0.08s Number of obs: 4059 (from total 4059) The model converged after 4 iterations. Log likelihood: -4658.4 Deviance statistic: 9316.9 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + standlrt + (1 + standlrt | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.01151 0.03978 -0.29 0.7724 -0.08948 0.06647 standlrt 0.55673 0.01994 27.92 1.344e-171 *** 0.51765 0.59581 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 --------------------------------------------------------------------------------------------------- The random part estimates at the school level: Coef. Std. Err. var_Intercept 0.09044 0.01792 cov_Intercept_standlrt 0.01804 0.00672 var_standlrt 0.01454 0.00441 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.55366 0.01248 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > # 6.1 The impact of school gender on girls' achievement . . . . . . . . . 80 > > (mymodel2 <- runMLwiN(normexam ~ 1 + standlrt + sex + schgend + (1 + standlrt | school) + (1 | student), data = tutorial)) /nogui option ignored ECHO 0 Echoing is ON BATC 1 Batch mode is ON MAXI 2 STAR iteration 0 iteration 1 Convergence not achieved TOLE 2 MAXI 20 NEXT iteration 2 iteration 3 Convergence achieved ECHO 0 Execution completed -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MLwiN (version: 3.05) multilevel model (Normal) N min mean max N_complete min_complete mean_complete max_complete school 65 2 62.44615 198 65 2 62.44615 198 Estimation algorithm: IGLS Elapsed time : 0.07s Number of obs: 4059 (from total 4059) The model converged after 4 iterations. Log likelihood: -4640.6 Deviance statistic: 9281.1 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + standlrt + sex + schgend + (1 + standlrt | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.18882 0.05135 -3.68 0.000236 *** -0.28947 -0.08817 standlrt 0.55443 0.01994 27.81 3.524e-170 *** 0.51535 0.59350 sexgirl 0.16826 0.03382 4.98 6.524e-07 *** 0.10197 0.23455 schgendboysch 0.17987 0.09914 1.81 0.06964 . -0.01445 0.37418 schgendgirlsch 0.17482 0.07876 2.22 0.02645 * 0.02045 0.32920 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 --------------------------------------------------------------------------------------------------- The random part estimates at the school level: Coef. Std. Err. var_Intercept 0.07954 0.01597 cov_Intercept_standlrt 0.02010 0.00649 var_standlrt 0.01465 0.00441 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.55020 0.01240 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > (mymodel3 <- runMLwiN(normexam ~ 1 + standlrt + sex + schgend + schgend:standlrt + (1 + standlrt | school) + (1 | student), + estoptions = list(startval = list(FP.b = mymodel2@FP, FP.v = mymodel2@FP.cov, RP.b = mymodel2@RP, RP.v = mymodel2@RP.cov)), + data = tutorial)) /nogui option ignored ECHO 0 Echoing is ON BATC 1 Batch mode is ON MAXI 2 STAR iteration 0 iteration 1 Convergence not achieved JOIN -0.1888197756919 0.554426003109425 0.168263236565984 0.179866354527701 0.174823414870713 0 0 '_FP_b' JOIN 0.00263695206715226 0.000327189405164753 0.000397525122485252 -0.000536443899325872 -2.59998235295558e-05 0.00114390721926941 -0.00235894200080809 1.05843244581469e-05 0.000514352069485757 0.00982881428441125 -0.00182798821608579 2.9913826620959e-05 -0.000629118882567792 0.0018534057412019 0.00620365697206955 0 0 0 0 0 0 0 0 0 0 0 0 0 '_FP_v' JOIN 0.0795417396876042 0.0201008945830419 0.0146521072148694 0.550198312318614 '_RP_b' JOIN 0.00025492576940079 5.84348555277209e-05 4.20881182530158e-05 1.30846738582449e-05 1.64017292133771e-05 1.94577130672965e-05 -2.89663433583334e-06 -2.36190338196134e-07 -2.64287337754297e-06 0.000153837417993462 '_RP_v' TOLE 2 MAXI 20 NEXT iteration 2 iteration 3 Convergence achieved ECHO 0 Execution completed -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MLwiN (version: 3.05) multilevel model (Normal) N min mean max N_complete min_complete mean_complete max_complete school 65 2 62.44615 198 65 2 62.44615 198 Estimation algorithm: IGLS Elapsed time : 0.08s Number of obs: 4059 (from total 4059) The model converged after 4 iterations. Log likelihood: -4640.4 Deviance statistic: 9280.9 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + standlrt + sex + schgend + schgend:standlrt + (1 + standlrt | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.18102 0.05357 -3.38 0.0007276 *** -0.28602 -0.07602 standlrt 0.56390 0.02724 20.70 3.562e-95 *** 0.51050 0.61729 sexgirl 0.16764 0.03384 4.95 7.292e-07 *** 0.10131 0.23397 schgendboysch 0.16658 0.11039 1.51 0.1313 -0.04977 0.38294 schgendgirlsch 0.15687 0.08664 1.81 0.07022 . -0.01295 0.32669 standlrt:schgendboysch -0.01593 0.05756 -0.28 0.7819 -0.12876 0.09689 standlrt:schgendgirlsch -0.02242 0.04486 -0.50 0.6173 -0.11035 0.06551 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 --------------------------------------------------------------------------------------------------- The random part estimates at the school level: Coef. Std. Err. var_Intercept 0.07947 0.01598 cov_Intercept_standlrt 0.02004 0.00649 var_standlrt 0.01458 0.00441 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.55019 0.01240 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > > # 6.2 Contextual effects of school intake ability averages . . . . . . . .83 > > (mymodel4 <- runMLwiN(normexam ~ 1 + standlrt + sex + schgend + schav + (1 + standlrt | school) + (1 | student), data = tutorial)) /nogui option ignored ECHO 0 Echoing is ON BATC 1 Batch mode is ON MAXI 2 STAR iteration 0 iteration 1 Convergence not achieved TOLE 2 MAXI 20 NEXT iteration 2 iteration 3 Convergence achieved ECHO 0 Execution completed -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MLwiN (version: 3.05) multilevel model (Normal) N min mean max N_complete min_complete mean_complete max_complete school 65 2 62.44615 198 65 2 62.44615 198 Estimation algorithm: IGLS Elapsed time : 0.06s Number of obs: 4059 (from total 4059) The model converged after 4 iterations. Log likelihood: -4639.2 Deviance statistic: 9278.4 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + standlrt + sex + schgend + schav + (1 + standlrt | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.26481 0.08152 -3.25 0.001162 ** -0.42459 -0.10502 standlrt 0.55155 0.02005 27.51 1.515e-166 *** 0.51225 0.59085 sexgirl 0.16713 0.03382 4.94 7.751e-07 *** 0.10084 0.23342 schgendboysch 0.18697 0.09769 1.91 0.05564 . -0.00451 0.37844 schgendgirlsch 0.15699 0.07774 2.02 0.04344 * 0.00463 0.30936 schavmid 0.06694 0.08528 0.78 0.4325 -0.10021 0.23408 schavhigh 0.17437 0.09868 1.77 0.07722 . -0.01904 0.36777 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 --------------------------------------------------------------------------------------------------- The random part estimates at the school level: Coef. Std. Err. var_Intercept 0.07076 0.01441 cov_Intercept_standlrt 0.01609 0.00603 var_standlrt 0.01470 0.00443 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.55016 0.01240 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > (mymodel5 <- runMLwiN(normexam ~ 1 + standlrt + sex + schgend + schav + standlrt:schav + (1 + standlrt | school) + + (1 | student), data = tutorial)) /nogui option ignored ECHO 0 Echoing is ON BATC 1 Batch mode is ON MAXI 2 STAR iteration 0 iteration 1 Convergence not achieved TOLE 2 MAXI 20 NEXT iteration 2 iteration 3 Convergence achieved ECHO 0 Execution completed -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- MLwiN (version: 3.05) multilevel model (Normal) N min mean max N_complete min_complete mean_complete max_complete school 65 2 62.44615 198 65 2 62.44615 198 Estimation algorithm: IGLS Elapsed time : 0.07s Number of obs: 4059 (from total 4059) The model converged after 4 iterations. Log likelihood: -4634.2 Deviance statistic: 9268.5 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + standlrt + sex + schgend + schav + standlrt:schav + (1 + standlrt | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.34725 0.08780 -3.96 7.651e-05 *** -0.51933 -0.17517 standlrt 0.45503 0.04181 10.88 1.385e-27 *** 0.37308 0.53697 sexgirl 0.16760 0.03380 4.96 7.124e-07 *** 0.10135 0.23386 schgendboysch 0.18928 0.09769 1.94 0.05267 . -0.00218 0.38074 schgendgirlsch 0.16086 0.07772 2.07 0.03848 * 0.00853 0.31320 schavmid 0.14432 0.09421 1.53 0.1256 -0.04033 0.32898 schavhigh 0.29044 0.10576 2.75 0.00603 ** 0.08315 0.49773 standlrt:schavmid 0.09222 0.04865 1.90 0.05801 . -0.00313 0.18758 standlrt:schavhigh 0.18046 0.05493 3.29 0.001019 ** 0.07280 0.28812 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 --------------------------------------------------------------------------------------------------- The random part estimates at the school level: Coef. Std. Err. var_Intercept 0.06931 0.01414 cov_Intercept_standlrt 0.01359 0.00542 var_standlrt 0.01072 0.00369 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.55028 0.01240 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > pred <- predict(mymodel5, params = c("FP_schavhigh", "FP_standlrt:schavhigh"), se.fit = TRUE) > > hilodiff <- pred$fit > hilodiff_se <- pred$se.fit > > hilodiff_lo <- hilodiff - 1.96 * hilodiff_se > hilodiff_hi <- hilodiff + 1.96 * hilodiff_se > > highdata <- as.data.frame(cbind(mymodel5@data$schavhigh, mymodel5@data[["standlrt:schavhigh"]], hilodiff, hilodiff_lo, + hilodiff_hi)[order(mymodel5@data[["standlrt:schavhigh"]]), ]) > colnames(highdata) <- c("schavhigh", "standlrt:schavhigh", "hilodiff", "hilodiff_lo", "hilodiff_hi") > highdata <- highdata[highdata$schavhigh == 1, ] > > plot(highdata[["standlrt:schavhigh"]], highdata$hilodiff, type = "l") > > if (!require(lattice)) { + warning("package lattice required to run this example") + } else { + xyplot(hilodiff ~ `standlrt:schavhigh`, panel = function(x, y, subscripts) { + panel.xyplot(x, y, type = "l") + panel.xyplot(x, highdata$hilodiff_hi, type = "l", lty = 2) + panel.xyplot(x, highdata$hilodiff_lo, type = "l", lty = 2) + }, data = highdata) + } Loading required package: lattice > > # Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . 87 > > > > ############################################################################ > > proc.time() user system elapsed 3.79 0.50 5.46