This is a broad introduction to the R statistical computing environment in the context of applied regression analysis. It is a thoroughly updated edition of John Fox's bestselling text An R and S-Plus Companion to Applied Regression (SAGE, 2002). The Second Edition is intended as a companion to any course on modern applied regression analysis. The authors provide a step-by-step guide to using the high-quality free statistical software R, an emphasis on integrating statistical computing in R with the practice of data analysis, coverage of generalized linear models, enhanced coverage of R graphics and programming, and substantial web-based support materials. An accompanying website for the book can be found at http:/socserv.mcmaster.ca/jfox/Books/Companion/index.html provides: R scripts for examples by chapter Data files used in the book The car package (Companion to Applied Regression), an accompanying software for regression diagnostics and other regression-related tasks Other resources to help students get the most out of the text
Preface
1 Getting Started With R 1
1.1 R Basics 1
1.1.1 Interacting With the Interpreter 2
1.1.2 R Functions 4
1.1.3 Vectors and Variables 7
1.1.4 Nonnumeric Vectors 10
1.1.5 Indexing Vectors 12
1.1.6 User-Defined Functions 14
1.1.7 Command Editing and Output Management 16
1.1.8 When Things Go Wrong 18
1.1.9 Getting Help and Information 19
1.1.10 Cleaning Up 21
1.1.11 Ending the R Session 22
1.2 An Extended Illustration: Duncan's Occupational-Prestige Regression 22
1.2.1 Reading the Data 23
1.2.2 Examining the Data 24
1.2.3 Regression Analysis 29
1.2.4 Regression Diagnostics 31
1.3 R Functions for Basic Statistics 37
1.4 Generic Functions and Their Methods 37
1.5 The R Commander Graphical User Interface 41
2 Reading and Manipulating Data 43
2.1 Data Input 44
2.1.1 Keyboard Input 44
2.1.2 File Input to a Data Frame 47
2.1.3 Importing Data 53
2.1.4 Accessing Data in R Packages 55