Multilevel Modeling in R
This is an introduction to how R can be used to perform a wide variety of multilevel analyses. “Multilevel analysis” is a term used to describe a set of analyses also referred to as random coefficient models or mixed-effects models (see Bryk & Raudenbush, 1992; Kreft & De leeuw, 1998; Snijders & Bosker, 1999). Random coefficient models (RCM) are well-suited to multilevel analyses; nonetheless, a number of multilevel analytic techniques existed before RCM emerged as the tool of choice and it is valuable to understand how these techniques are both similar to and different from RCM. In addition, RCM analyses are often augmented by work in related areas such as work in within-group agreement and group-mean reliability. Consequently, this document covers a wide range of inter-related topics related to multilevel analyses including:
• Within-group agreement and reliability
• Contextual OLS models
• Covariance theorem decomposition
• Random Coefficient Models or Mixed Effects Models
• Random Group Resampling
A Brief Introduction to R, the multilevel package and the nlme package
1 Introduction
2 An Introduction to R
3 Multilevel Analyses
4 Growth Modeling
5 Miscellaneous Functions
6 Conclusion
R for Stata Users
Who This Book Is For
This book is, of course, for people who already know Stata. It may also be
useful to R users wishing to learn Stata. However, we explain none of the
Stata programs, only the R ones and how the packages differ, so it is not ideal
for that purpose.
This book is based on R for SAS and SPSS Users [34]. However, there is
quite a bit of additional material covered here, and, of course, the comparative
coverage is completely different.
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Installing and Updating R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 Running R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4 Help and Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5 Programming Language Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6 Data Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7 Selecting Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
8 Selecting Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
9 Selecting Variables and Observations . . . . . . . . . . . . . . . . . . . . . . . 157
10 Data Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
11 Enhancing Your Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
12 Generating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
13 Managing Your Files and Workspace . . . . . . . . . . . . . . . . . . . . . . . 291
14 Graphics Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
15 Traditional Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
16 Graphics with ggplot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
17 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
18 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497