Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
1 Introduction 1
1.1 The History of S and S-Plus . . . . . . . . . . . . . . . 2
1.2 S-Plus on Different Operating Systems . . . . . . . . . 4
1.3 Notational Conventions . . . . . . . . . . . . . . . . . . . 6
2 Graphical User Interface 9
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 SystemOverview . . . . . . . . . . . . . . . . . . . . . . 10
2.2.1 Using aMouse . . . . . . . . . . . . . . . . . . . . 11
2.2.2 Object Explorer . . . . . . . . . . . . . . . . . . . 11
2.2.3 CommandsWindow . . . . . . . . . . . . . . . . 11
2.2.4 Toolbars . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.5 Graph Sheets . . . . . . . . . . . . . . . . . . . . 12
2.2.6 ScriptWindow . . . . . . . . . . . . . . . . . . . 12
2.3 Getting Started with the Interface . . . . . . . . . . . . . 13
2.3.1 Importing Data . . . . . . . . . . . . . . . . . . . 13
2.3.2 Graphs . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.3 Data and Statistics . . . . . . . . . . . . . . . . . 15
2.3.4 Customizing the Toolbars . . . . . . . . . . . . . 15
2.3.5 Chapters . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Detailed Use of the GUI Interface . . . . . . . . . . . . . 18
2.5 Object Explorer . . . . . . . . . . . . . . . . . . . . . . . 18
2.6 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.7 Data Export . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.8 Working Directory . . . . . . . . . . . . . . . . . . . . . 23
2.9 Data Import . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.10 Data Summaries . . . . . . . . . . . . . . . . . . . . . . . 27
2.11 Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.12 Trellis Graphs . . . . . . . . . . . . . . . . . . . . . . . . 36
2.13 Linear Regression . . . . . . . . . . . . . . . . . . . . . . 38
2.14 PowerPoint (Windows Only) . . . . . . . . . . . . . . . . 42
2.15 Excel (Windows Only) . . . . . . . . . . . . . . . . . . . 44
2.16 ScriptWindow. . . . . . . . . . . . . . . . . . . . . . . . 45
2.17 UNIX/Linux GUI . . . . . . . . . . . . . . . . . . . . . . 47
2.18 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.19 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.20 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3 A First Session 73
3.1 General Information . . . . . . . . . . . . . . . . . . . . . 73
3.1.1 Starting and Quitting . . . . . . . . . . . . . . . . 74
3.1.2 The Help System . . . . . . . . . . . . . . . . . . 75
3.1.3 Before Beginning . . . . . . . . . . . . . . . . . . 75
3.2 Simple Structures . . . . . . . . . . . . . . . . . . . . . . 76
3.2.1 Arithmetic Operators . . . . . . . . . . . . . . . . 76
3.2.2 Assignments . . . . . . . . . . . . . . . . . . . . . 77
3.2.3 The Concatenate Command: c . . . . . . . . . . . 79
3.2.4 The Sequence Command: seq . . . . . . . . . . . 80
3.2.5 The Replicate Command: rep . . . . . . . . . . . 81
3.3 Mathematical Operations . . . . . . . . . . . . . . . . . 82
3.4 Use of Brackets . . . . . . . . . . . . . . . . . . . . . . . 84
3.5 Logical Values . . . . . . . . . . . . . . . . . . . . . . . . 85
3.6 Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
3.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.8 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4 A Second Session 95
4.1 Constructing and Manipulating Data . . . . . . . . . . . 95
4.1.1 Matrices . . . . . . . . . . . . . . . . . . . . . . . 96
4.1.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . 101
4.1.3 Data Frames . . . . . . . . . . . . . . . . . . . . . 104
4.1.4 Lists . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.2 Introduction to Functions . . . . . . . . . . . . . . . . . 108
4.3 Introduction toMissing Values . . . . . . . . . . . . . . . 109
4.4 Merging Data . . . . . . . . . . . . . . . . . . . . . . . . 110
4.5 Putting It All Together . . . . . . . . . . . . . . . . . . . 111
4.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
4.7 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
5 Graphics 125
5.1 Basic Graphics Commands . . . . . . . . . . . . . . . . . 125
5.2 Graphics Devices . . . . . . . . . . . . . . . . . . . . . . 126
5.2.1 Working withMultiple Graphics Devices . . . . . 128
5.3 Plotting Data . . . . . . . . . . . . . . . . . . . . . . . . 128
5.3.1 The plot Command . . . . . . . . . . . . . . . . 129
5.3.2 Modifying the Data Display . . . . . . . . . . . . 130
5.3.3 Modifying Figure Elements . . . . . . . . . . . . . 131
5.4 Adding Elements to Existing Plots . . . . . . . . . . . . 133
5.4.1 Functions to Add Elements to Graphs . . . . . . 133
5.4.2 More About abline . . . . . . . . . . . . . . . . 135
5.4.3 More on Adding Axes . . . . . . . . . . . . . . . 135
5.4.4 Adding Text to Graphs . . . . . . . . . . . . . . . 137
5.5 Setting Options . . . . . . . . . . . . . . . . . . . . . . . 138
5.6 Figure Layouts . . . . . . . . . . . . . . . . . . . . . . . 140
5.6.1 Layouts Using Trellis Graphs . . . . . . . . . . . 140
5.6.2 Matrices of Graphs . . . . . . . . . . . . . . . . . 140
5.6.3 Multiple-Screen Graphs . . . . . . . . . . . . . . . 141
5.6.4 Figures of Specified Size . . . . . . . . . . . . . . 142
5.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.8 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
6 Trellis Graphics 153
6.1 An Example . . . . . . . . . . . . . . . . . . . . . . . . . 154
6.2 Trellis Basics . . . . . . . . . . . . . . . . . . . . . . . . . 156
6.2.1 Trellis Syntax . . . . . . . . . . . . . . . . . . . . 156
6.2.2 Trellis Functions . . . . . . . . . . . . . . . . . . 157
6.2.3 Displaying and Storing Graphs . . . . . . . . . . 157
6.3 Output Devices . . . . . . . . . . . . . . . . . . . . . . . 158
6.4 Customizing Trellis Graphs . . . . . . . . . . . . . . . . . 160
6.4.1 Setting Options . . . . . . . . . . . . . . . . . . . 160
6.4.2 Arranging the Layout of a Trellis Graph . . . . . 161
6.4.3 Ordering of Graphs . . . . . . . . . . . . . . . . . 163
6.4.4 Axis Customization . . . . . . . . . . . . . . . . . 164
6.4.5 Modifying Panel Strips . . . . . . . . . . . . . . . 165
6.4.6 Arranging Several Graphs on a Single Page . . . 165
6.4.7 Updating Existing Trellis Graphs . . . . . . . . . 167
6.4.8 Writing Panel Functions . . . . . . . . . . . . . . 168
6.5 Further Trellis Hints . . . . . . . . . . . . . . . . . . . . 171
6.5.1 Useful General Trellis Settings . . . . . . . . . . . 172
6.5.2 Graphing Individual Profiles . . . . . . . . . . . . 173
6.5.3 Preparing Data to Use for Trellis . . . . . . . . . 174
6.5.4 The subset Option . . . . . . . . . . . . . . . . . 175
6.5.5 Adding a Key . . . . . . . . . . . . . . . . . . . . 175
6.5.6 The subscripts Option in Panel Functions . . . . 177
6.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.7 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
7 Exploring Data 193
7.1 Descriptive Data Exploration . . . . . . . . . . . . . . . 193
7.2 Graphical Exploration . . . . . . . . . . . . . . . . . . . 204
7.2.1 Interactive Dynamic Graphics . . . . . . . . . . . 219
7.2.2 Old-Style Graphics . . . . . . . . . . . . . . . . . 219
7.3 Distributions and Related Functions . . . . . . . . . . . 220
7.4 Confirmatory Statistics and Hypothesis Testing . . . . . 225
7.5 Missing and Infinite Values . . . . . . . . . . . . . . . . . 231
7.5.1 Testing forMissing Values . . . . . . . . . . . . . 232
7.5.2 Supplying Data with Missing Values to Functions 232
7.5.3 Missing Values in Graphs . . . . . . . . . . . . . 233
7.5.4 Infinite Values . . . . . . . . . . . . . . . . . . . . 233
7.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
7.7 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
8 Statistical Modeling 251
8.1 Introductory Examples . . . . . . . . . . . . . . . . . . . 251
8.1.1 Regression . . . . . . . . . . . . . . . . . . . . . . 251
8.1.2 Regression Diagnostics . . . . . . . . . . . . . . . 253
8.2 Statistical Models . . . . . . . . . . . . . . . . . . . . . . 255
8.3 Model Syntax . . . . . . . . . . . . . . . . . . . . . . . . 256
8.4 Regression . . . . . . . . . . . . . . . . . . . . . . . . . . 257
8.4.1 Linear Regression and Modeling Techniques . . . 258
8.4.2 ANOVA . . . . . . . . . . . . . . . . . . . . . . . 261
8.4.3 Logistic Regression . . . . . . . . . . . . . . . . . 263
8.4.4 Survival Data Analysis . . . . . . . . . . . . . . . 265
8.4.5 Endnote . . . . . . . . . . . . . . . . . . . . . . . 267
8.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
8.6 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
9 Programming 285
9.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
9.1.1 Adding and Deleting List Elements . . . . . . . . 287
9.1.2 Naming List Elements . . . . . . . . . . . . . . . 288
9.1.3 Applying the Same Function to List Elements . . 290
9.1.4 Unlisting a List . . . . . . . . . . . . . . . . . . . 294
9.1.5 Generating a List by Using split . . . . . . . . . 294
9.2 Writing Functions . . . . . . . . . . . . . . . . . . . . . . 294
9.2.1 Documenting Functions . . . . . . . . . . . . . . 297
9.2.2 Scope of Variables . . . . . . . . . . . . . . . . . . 297
9.2.3 Parameters and Defaults . . . . . . . . . . . . . 298
9.2.4 Passing an Unspecified Number
of Parameters to a Function . . . . . . . . . . . . 300
9.2.5 Testing for Existence of an Argument . . . . . . . 301
9.2.6 ReturningWarnings and Errors . . . . . . . . . . 301
9.2.7 Using Function Arguments in Graphics Labels . . 302
9.3 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
9.3.1 The for Loop . . . . . . . . . . . . . . . . . . . . 303
9.3.2 The while Loop . . . . . . . . . . . . . . . . . . . 304
9.3.3 The repeat Loop . . . . . . . . . . . . . . . . . . 305
9.3.4 Vectorizing a Loop . . . . . . . . . . . . . . . . . 305
9.3.5 Large Loops . . . . . . . . . . . . . . . . . . . . . 307
9.4 Debugging: Searching for Errors . . . . . . . . . . . . . . 308
9.4.1 Syntax Errors . . . . . . . . . . . . . . . . . . . . 309
9.4.2 Invalid Arguments . . . . . . . . . . . . . . . . . 310
9.4.3 Execution or Run-Time Errors . . . . . . . . . . . 310
9.4.4 Logical Errors . . . . . . . . . . . . . . . . . . . . 311
9.5 Output Using the cat Function . . . . . . . . . . . . . . 314
9.6 The paste Function . . . . . . . . . . . . . . . . . . . . . 316
9.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
9.8 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
10 Object-Oriented Programming 323
10.1 Creating Classes and Objects . . . . . . . . . . . . . . . 325
10.2 CreatingMethods . . . . . . . . . . . . . . . . . . . . . . 328
10.3 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 333
10.4 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
10.5 Summary and Overview . . . . . . . . . . . . . . . . . . 334
10.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
10.7 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
11 Input and Output 349
11.1 Reading S-Plus Commands from a File:
The source Function . . . . . . . . . . . . . . . . . . . . 349
11.2 Data Import/Export: Easiest Method . . . . . . . . . . . 350
11.3 Data Import/Export: General Method . . . . . . . . . . 352
11.4 Data Import/Export: Basic Method . . . . . . . . . . . . 353
11.5 Reading Data from the Terminal . . . . . . . . . . . . . 354
11.6 Editing Data . . . . . . . . . . . . . . . . . . . . . . . . . 355
11.7 Transferring Data . . . . . . . . . . . . . . . . . . . . . . 356
11.8 Recording a Session . . . . . . . . . . . . . . . . . . . . . 356
11.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
11.10 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
12 Tips and Tricks 363
12.1 Useful Techniques . . . . . . . . . . . . . . . . . . . . . . 363
12.1.1 Housekeeping: Cleaning Up Directories . . . . . . 363
12.1.2 Storing and Restoring Graphical Parameters . . . 364
12.1.3 Naming of Objects . . . . . . . . . . . . . . . . . 364
12.1.4 Repeating Commands . . . . . . . . . . . . . . . 365
12.2 Programming Environment and Techniques . . . . . . . 366
12.2.1 The Process of Developing a Function . . . . . . 366
12.2.2 Setting up an Editor and Running the Code
in S-Plus . . . . . . . . . . . . . . . . . . . . . . 366
12.2.3 Treating Data Frames as Lists . . . . . . . . . . . 368
12.2.4 Working with Graph Sheets . . . . . . . . . . . . 369
12.2.5 Incorporating and Accessing C and Fortran Programs
. . . . . . . . . . . . . . . . . . . . . . . . 371
12.2.6 Batch Jobs . . . . . . . . . . . . . . . . . . . . . . 374
12.2.7 Libraries . . . . . . . . . . . . . . . . . . . . . . . 376
12.3 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
12.3.1 Creating Factors and Ordered Factors . . . . . . 378
12.3.2 Internal Representation of Factors . . . . . . . . . 380
12.3.3 Where Levels Play a Role . . . . . . . . . . . . . 381
12.3.4 Where Factors Can Lead Their Own Lives . . . . 382
12.3.5 How Factors Come Into Life . . . . . . . . . . . . 384
12.3.6 Adding and Dropping Factor Levels . . . . . . . . 385
12.4 Including Graphs in Text Processors . . . . . . . . . . . 386
12.4.1 Generating Graphs for Windows Applications . . 387
12.4.2 Generating PostScript Graphs . . . . . . . . . . . 388
12.4.3 PostScript Graphs in LATEX . . . . . . . . . . . . 389
12.4.4 If You Don’t Have a PostScript Printer . . . . . . 390
12.4.5 Greek Letters in Graphs . . . . . . . . . . . . . . 390
12.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
12.6 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
13 S-Plus Internals 401
13.1 How S-Plus Works Under UNIX . . . . . . . . . . . . . 401
13.1.1 TheWorking Chapter . . . . . . . . . . . . . . . 402
13.1.2 Customization on Start-Up and Exit . . . . . . . 402
13.2 How S-PlusWorks UnderWindows . . . . . . . . . . . 404
13.2.1 Command Line Options . . . . . . . . . . . . . . 404
13.2.2 Start-up and Exit Functions . . . . . . . . . . . . 405
13.2.3 How the ScriptWindow works . . . . . . . . . . . 406
13.3 StoringMechanism . . . . . . . . . . . . . . . . . . . . . 407
13.4 Levels of Calls . . . . . . . . . . . . . . . . . . . . . . . . 408
13.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
13.6 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
14 Information Sources on and Around S-Plus 413
14.1 Insightful . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
14.2 S-News: Exchanging Information with Other Users . . . 414
14.3 The StatLib Server . . . . . . . . . . . . . . . . . . . . . 414
14.4 What Next? . . . . . . . . . . . . . . . . . . . . . . . . . 415
15 R 417
15.1 Development . . . . . . . . . . . . . . . . . . . . . . . . . 418
15.2 Some Similarities Between R and S . . . . . . . . . . . . 418
15.3 Some Differences Between R and S . . . . . . . . . . . . 418
15.3.1 Language . . . . . . . . . . . . . . . . . . . . . . 419
15.3.2 Libraries . . . . . . . . . . . . . . . . . . . . . . . 420
15.3.3 Trellis-Type Graphs . . . . . . . . . . . . . . . . . 420
15.3.4 Colors and Lines . . . . . . . . . . . . . . . . . . 421
15.3.5 Data Import and Export Formats . . . . . . . . . 421
15.3.6 Memory Handling . . . . . . . . . . . . . . . . . . 421
15.3.7 Mathematical Formulae in Graphs . . . . . . . . 421
15.3.8 Graphical User Interfaces . . . . . . . . . . . . . . 421
15.3.9 Start-UpMechanism . . . . . . . . . . . . . . . . 422
15.3.10Windows Integration . . . . . . . . . . . . . . . . 422
15.3.11 Support . . . . . . . . . . . . . . . . . . . . . . . 422
15.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
16 Bibliography 425
16.1 Print Bibliography . . . . . . . . . . . . . . . . . . . . . 425
16.2 On-Line Bibliography . . . . . . . . . . . . . . . . . . . . 427
16.2.1 S-Plus Related Sources . . . . . . . . . . . . . . 427
16.2.2 TEX-Related Sources . . . . . . . . . . . . . . . . 429
16.2.3 Other Sources . . . . . . . . . . . . . . . . . . . . 429
鉴于会给论坛带来版权纠纷问题,特给出链接地址:
http://www.bloomyear.com/bbs/?u=14559
http://www.bloomyear.com/bbs/read.php?tid-43505.html
免费:
http://www.pinggu.org/bbs/dispbbs.asp?boardID=69&ID=153511&page=1