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 > # > # 3 Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 > # > # 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) > > > # 3.1 What are multilevel residuals? . . . . . . . . . . . . . . . . . . .37 > > data(tutorial, package = "R2MLwiN") > > (mymodel1 <- runMLwiN(normexam ~ 1 + (1 | school) + (1 | student), data = tutorial, estoptions = list(resi.store = TRUE))) /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 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 3 iterations. Log likelihood: -5505.3 Deviance statistic: 11010.6 --------------------------------------------------------------------------------------------------- The model formula: normexam ~ 1 + (1 | school) + (1 | student) Level 2: school Level 1: student --------------------------------------------------------------------------------------------------- The fixed part estimates: Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval] Intercept -0.01317 0.05363 -0.25 0.806 -0.11827 0.09194 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.16863 0.03245 --------------------------------------------------------------------------------------------------- The random part estimates at the student level: Coef. Std. Err. var_Intercept 0.84776 0.01897 -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > > > # 3.2 Calculating residuals in MLwiN . . . . . . . . . . . . . . . . . . .40 > > residuals <- mymodel1@residual$lev_2_resi_est_Intercept > residualsCI <- 1.96 * sqrt(mymodel1@residual$lev_2_resi_var_Intercept) > residualsRank <- rank(residuals) > rankno <- order(residualsRank) > > caterpillar(y = residuals[rankno], x = 1:65, qtlow = (residuals - residualsCI)[rankno], + qtup = (residuals + residualsCI)[rankno], xlab = 'Rank', ylab = 'Intercept') > > # 3.3 Normal plots . . . . . . . . . . . . . . . . . . . . . . . . . . . .43 > > e0 <- mymodel1@residual$lev_1_resi_est_Intercept > > e0std <- (e0 - mean(e0))/sd(e0) > > e0rank <- rank(e0) > > e0uniform <- (e0rank - 0.5)/length(e0rank) > > e0nscore <- qnorm(e0uniform) > > plot(e0nscore, e0std, asp = 1) > > > u0 <- mymodel1@residual$lev_2_resi_est_Intercept > > u0std <- (u0 - mean(u0))/sd(u0) > > u0rank <- rank(u0) > > u0uniform <- (u0rank - 0.5)/length(u0rank) > > u0nscore <- qnorm(u0uniform) > > plot(u0nscore, u0std, asp = 1) > > # Chapter learning outcomes . . . . . . . . . . . . . . . . . . . . . . . 45 > > > ############################################################################ > > proc.time() user system elapsed 3.15 0.39 3.85