Table of Contents
1 Introduction .............................................................................................................................. 5
2 An Introduction to R ................................................................................................................ 6
2.1 Overview ........................................................................................................................... 6
2.1.1 Related software and documentation .......................................................................... 6
2.1.2 R and statistics ............................................................................................................ 6
2.1.3 Obtaining R and the multilevel package ............................................................. 6
2.1.4 Data permanency and removing objects ..................................................................... 7
2.1.5 Running R for Different Projects ................................................................................ 7
2.1.6 Recall and correction of previous commands ............................................................. 8
2.1.7 Getting help with functions and features .................................................................... 8
2.1.8 R commands, case sensitivity, etc............................................................................... 8
2.2 Simple manipulations; numbers and vectors ..................................................................... 9
2.2.1 Vectors and assignment .............................................................................................. 9
2.2.2 Missing values .......................................................................................................... 10
2.3 Dataframes ....................................................................................................................... 10
2.3.1 Introduction to dataframes ........................................................................................ 10
2.3.2 Making dataframes.................................................................................................... 11
2.3.3 Using attach() and detach() ........................................................................ 11
2.3.4 Managing the search path ......................................................................................... 12
2.4 Reading data from files .................................................................................................... 13
2.4.1 Reading Spreadsheet (EXCEL) data ......................................................................... 13
2.4.2 The extremely useful "clipboard" option ........................................................... 14
2.4.3 The foreign package and SPSS files .................................................................... 15
2.4.4 Using file.choose to bring up a GUI to read data ............................................ 17
2.4.5 Checking your dataframes with str , summary, and head .................................. 18
2.4.6 Loading data from packages ..................................................................................... 18
2.4.7 Exporting data to spreadsheets using write() and write.table() ............... 19
2.5 More on using matrix brackets on dataframes ................................................................. 20
2.6 Identifying Statistical models in R .................................................................................. 21
2.6.1 Examples ................................................................................................................... 21
2.6.2 Linear models............................................................................................................ 21
2.6.3 Generic functions for extracting model information ................................................ 22
2.7 Graphical procedures ....................................................................................................... 22
2.7.1 The plot() function ............................................................................................... 23
2.7.2 Displaying multivariate data ..................................................................................... 23
2.7.3 Advanced Graphics and the lattice package ...................................................... 24
3 Multilevel Analyses................................................................................................................ 25
3.1 Attaching the multilevel and nlme packages ......................................................... 25
3.2 Helpful multilevel data manipulation functions .............................................................. 26
3.2.1 The merge Function ................................................................................................ 26
3.2.2 The aggregate function ....................................................................................... 27
3.3 Within-Group Agreement and Reliability ....................................................................... 29
3.3.1 Agreement: rwg, rwg(j), and r*wg(j) ............................................................................... 30
3.3.2 The awg Index ............................................................................................................ 32
Multilevel Models in R 4
3.3.3 Significance testing of rwg and rwg(j) using rwg.sim and rwg.j.sim ................. 33
3.3.4 Average Deviation (AD) Agreement using ad.m .................................................... 37
3.3.5 Significance testing of AD using ad.m.sim .......................................................... 38
3.3.6 Agreement: Random Group Resampling ................................................................. 39
3.3.7 Reliability: ICC(1) and ICC(2) ................................................................................ 43
3.3.8 Visualizing an ICC(1) with graph.ran.mean .................................................... 44
3.4 Regression and Contextual OLS Models ......................................................................... 45
3.4.1 Contextual Effect Example ....................................................................................... 46
3.5 Correlation Decomposition and the Covariance Theorem .............................................. 47
3.5.1 The waba and cordif functions ............................................................................ 48
3.5.2 Random Group Resampling of Covariance Theorem (rgr.waba) ........................ 49
3.6 Multilevel Random Coefficient modeling ....................................................................... 50
3.6.1 Steps in multilevel modeling .................................................................................... 51
3.6.2 Plotting an interaction with interaction.plot ............................................... 64
3.6.3 Some Notes on Centering ......................................................................................... 65
4 Growth Modeling ................................................................................................................... 66
4.1 Methodological challenges .............................................................................................. 67
4.2 Data Structure and the make.univ Function ............................................................... 68
4.3 Growth Modeling Illustration .......................................................................................... 70
4.3.1 Step 1: Examine the DV .......................................................................................... 71
4.3.2 Step 2: Model Time .................................................................................................. 71
4.3.3 Step 3: Model Slope Variability .............................................................................. 72
4.3.4 Step 4: Modeling Error Structures ........................................................................... 73
4.3.5 Step 5: Predicting Intercept Variation...................................................................... 75
4.3.6 Step 6: Predicting Slope Variation ........................................................................... 77
4.4 Empirical Bayes estimates ............................................................................................... 78
5 A brief introduction to lme4 ................................................................................................... 81
5.1 Dichotomous outcome variables ..................................................................................... 81
5.2 Crossed and partially crossed models .............................................................................. 83
5.3 Predicted values in lme4: simple.predict .............................................................. 83
6 Miscellaneous Functions ........................................................................................................ 83
6.1 Scale reliability: cronbach and item.total ........................................................... 83
6.2 Random Group Resampling for OLS Regression Models .............................................. 84
6.3 Estimate multiple ICC values: mult.icc .................................................................... 84
6.4 Estimating bias in nested regression models: simbias ............................................... 84
6.5 Detecting mediation effects: sobel ............................................................................... 84
7 Conclusion .............................................................................................................................. 84
8 References .............................................................................................................................. 84