Details

Beginning R


Beginning R

The Statistical Programming Language
1. Aufl.

von: Mark Gardener

22,99 €

Verlag: Wiley
Format: EPUB
Veröffentl.: 24.05.2012
ISBN/EAN: 9781118239377
Sprache: englisch
Anzahl Seiten: 512

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<b>Conquer the complexities of this open source statistical language</b> <p>R is fast becoming the de facto standard for statistical computing and analysis in science, business, engineering, and related fields. This book examines this complex language using simple statistical examples, showing how R operates in a user-friendly context. Both students and workers in fields that require extensive statistical analysis will find this book helpful as they learn to use R for simple summary statistics, hypothesis testing, creating graphs, regression, and much more. It covers formula notation, complex statistics, manipulating data and extracting components, and rudimentary programming.</p> <ul> <li>R, the open source statistical language increasingly used to handle statistics and produces publication-quality graphs, is notoriously complex</li> <li>This book makes R easier to understand through the use of simple statistical examples, teaching the necessary elements in the context in which R is actually used</li> <li>Covers getting started with R and using it for simple summary statistics, hypothesis testing, and graphs</li> <li>Shows how to use R for formula notation, complex statistics, manipulating data, extracting components, and regression</li> <li>Provides beginning programming instruction for those who want to write their own scripts</li> </ul> <p><i>Beginning R</i> offers anyone who needs to perform statistical analysis the information necessary to use R with confidence.</p>
Introduction xxi <p><b>Chapter 1: Introducing R: What It Is and How to Get It 1</b></p> <p>Getting the Hang of R 2</p> <p>The R Website 3</p> <p>Downloading and Installing R from CRAN 3</p> <p>Installing R on Your Windows Computer 4</p> <p>Installing R on Your Macintosh Computer 7</p> <p>Installing R on Your Linux Computer 7</p> <p>Running the R Program 8</p> <p>Finding Your Way with R 10</p> <p>Getting Help via the CRAN Website and the Internet 10</p> <p>The Help Command in R 10</p> <p>Help for Windows Users 11</p> <p>Help for Macintosh Users 11</p> <p>Help for Linux Users 13</p> <p>Help For All Users 13</p> <p>Anatomy of a Help Item in R 14</p> <p>Command Packages 16</p> <p>Standard Command Packages 16</p> <p>What Extra Packages Can Do for You 16</p> <p>How to Get Extra Packages of R Commands 18</p> <p>How to Install Extra Packages for Windows Users 18</p> <p>How to Install Extra Packages for Macintosh Users 18</p> <p>How to Install Extra Packages for Linux Users 19</p> <p>Running and Manipulating Packages 20</p> <p>Loading Packages 21</p> <p>Windows-Specific Package Commands 21</p> <p>Macintosh-Specific Package Commands 21</p> <p>Removing or Unloading Packages 22</p> <p>Summary 22</p> <p><b>Chapter 2: Starting Out: Becoming Familiar with R 25</b></p> <p>Some Simple Math 26</p> <p>Use R Like a Calculator 26</p> <p>Storing the Results of Calculations 29</p> <p>Reading and Getting Data into R 30</p> <p>Using the combine Command for Making Data 30</p> <p>Entering Numerical Items as Data 30</p> <p>Entering Text Items as Data 31</p> <p>Using the scan Command for Making Data 32</p> <p>Entering Text as Data 33</p> <p>Using the Clipboard to Make Data 33</p> <p>Reading a File of Data from a Disk 35</p> <p>Reading Bigger Data Files 37</p> <p>The read.csv() Command 37</p> <p>Alternative Commands for Reading Data in R 39</p> <p>Missing Values in Data Files 40</p> <p>Viewing Named Objects 41</p> <p>Viewing Previously Loaded Named-Objects 42</p> <p>Viewing All Objects 42</p> <p>Viewing Only Matching Names 42</p> <p>Removing Objects from R 44</p> <p>Types of Data Items 45</p> <p>Number Data 45</p> <p>Text Items 45</p> <p>Converting Between Number and Text Data 46</p> <p>The Structure of Data Items 47</p> <p>Vector Items 48</p> <p>Data Frames 48</p> <p>Matrix Objects 49</p> <p>List Objects 49</p> <p>Examining Data Structure 49</p> <p>Working with History Commands 51</p> <p>Using History Files 52</p> <p>Viewing the Previous Command History 52</p> <p>Saving and Recalling Lists of Commands 52</p> <p>Alternative History Commands in Macintosh OS 52</p> <p>Editing History Files 53</p> <p>Saving Your Work in R 54</p> <p>Saving the Workspace on Exit 54</p> <p>Saving Data Files to Disk 54</p> <p>Save Named Objects 54</p> <p>Save Everything 55</p> <p>Reading Data Files from Disk 56</p> <p>Saving Data to Disk as Text Files 57</p> <p>Writing Vector Objects to Disk 58</p> <p>Writing Matrix and Data Frame Objects to Disk 58</p> <p>Writing List Objects to Disk 59</p> <p>Converting List Objects to Data Frames 60</p> <p>Summary 61</p> <p><b>Chapter 3: Starting Out: Working With Objects 65</b></p> <p>Manipulating Objects 65</p> <p>Manipulating Vectors 66</p> <p>Selecting and Displaying Parts of a Vector 66</p> <p>Sorting and Rearranging a Vector 68</p> <p>Returning Logical Values from a Vector 70</p> <p>Manipulating Matrix and Data Frames 70</p> <p>Selecting and Displaying Parts of a Matrix or Data Frame 71</p> <p>Sorting and Rearranging a Matrix or Data Frame 74</p> <p>Manipulating Lists 76</p> <p>Viewing Objects within Objects 77</p> <p>Looking Inside Complicated Data Objects 77</p> <p>Opening Complicated Data Objects 78</p> <p>Quick Looks at Complicated Data Objects 80</p> <p>Viewing and Setting Names 82</p> <p>Rotating Data Tables 86</p> <p>Constructing Data Objects 86</p> <p>Making Lists 87</p> <p>Making Data Frames 88</p> <p>Making Matrix Objects 89</p> <p>Re-ordering Data Frames and Matrix Objects 92</p> <p>Forms of Data Objects: Testing and Converting 96</p> <p>Testing to See What Type of Object You Have 96</p> <p>Converting from One Object Form to Another 97</p> <p>Convert a Matrix to a Data Frame 97</p> <p>Convert a Data Frame into a Matrix 98</p> <p>Convert a Data Frame into a List 99</p> <p>Convert a Matrix into a List 100</p> <p>Convert a List to Something Else 100</p> <p>Summary 104</p> <p><b>Chapter 4: Data: Descriptive Statistics and Tabulation 107</b></p> <p>Summary Commands 108</p> <p>Summarizing Samples 110</p> <p>Summary Statistics for Vectors 110</p> <p>Summary Commands With Single Value Results 110</p> <p>Summary Commands With Multiple Results 113</p> <p>Cumulative Statistics 115</p> <p>Simple Cumulative Commands 115</p> <p>Complex Cumulative Commands 117</p> <p>Summary Statistics for Data Frames 118</p> <p>Generic Summary Commands for Data Frames 119</p> <p>Special Row and Column Summary Commands 119</p> <p>The apply() Command for Summaries on Rows or Columns 120</p> <p>Summary Statistics for Matrix Objects 120</p> <p>Summary Statistics for Lists 121</p> <p>Summary Tables 122</p> <p>Making Contingency Tables 123</p> <p>Creating Contingency Tables from Vectors 123</p> <p>Creating Contingency Tables from Complicated Data 123</p> <p>Creating Custom Contingency Tables 126</p> <p>Creating Contingency Tables from Matrix Objects 128</p> <p>Selecting Parts of a Table Object 130</p> <p>Converting an Object into a Table 132</p> <p>Testing for Table Objects 133</p> <p>Complex (Flat) Tables 134</p> <p>Making “Flat” Contingency Tables 134</p> <p>Making Selective “Flat” Contingency Tables 138</p> <p>Testing “Flat” Table Objects 139</p> <p>Summary Commands for Tables 139</p> <p>Cross Tabulation 142</p> <p>Testing Cross-Table (xtabs) Objects 144</p> <p>A Better Class Test 144</p> <p>Recreating Original Data from a Contingency Table 145</p> <p>Switching Class 146</p> <p>Summary 147</p> <p><b>Chapter 5: Data: Distrib ution 151</b></p> <p>Looking at the Distribution of Data 151</p> <p>Stem and Leaf Plot 152</p> <p>Histograms 154</p> <p>Density Function 158</p> <p>Using the Density Function to Draw a Graph 159</p> <p>Adding Density Lines to Existing Graphs 160</p> <p>Types of Data Distribution 161</p> <p>The Normal Distribution 161</p> <p>Other Distributions 164</p> <p>Random Number Generation and Control 166</p> <p>Random Numbers and Sampling 168</p> <p>The Shapiro-Wilk Test for Normality 171</p> <p>The Kolmogorov-Smirnov Test 172</p> <p>Quantile-Quantile Plots 174</p> <p>A Basic Normal Quantile-Quantile Plot 174</p> <p>Adding a Straight Line to a QQ Plot 174</p> <p>Plotting the Distribution of One Sample Against Another 175</p> <p>Summary 177</p> <p><b>Chapter 6: Si mple Hypothesis Testing 181</b></p> <p>Using the Student’s t-test 181</p> <p>Two-Sample t-Test with Unequal Variance 182</p> <p>Two-Sample t-Test with Equal Variance 183</p> <p>One-Sample t-Testing 183</p> <p>Using Directional Hypotheses 183</p> <p>Formula Syntax and Subsetting Samples in the t-Test 184</p> <p>The Wilcoxon U-Test (Mann-Whitney) 188</p> <p>Two-Sample U-Test 189</p> <p>One-Sample U-Test 189</p> <p>Using Directional Hypotheses 189</p> <p>Formula Syntax and Subsetting Samples in the U-test 190</p> <p>Paired t- and U-Tests 193</p> <p>Correlation and Covariance 196</p> <p>Simple Correlation 197</p> <p>Covariance 199</p> <p>Significance Testing in Correlation Tests 199</p> <p>Formula Syntax 200</p> <p>Tests for Association 203</p> <p>Multiple Categories: Chi-Squared Tests 204</p> <p>Monte Carlo Simulation 205</p> <p>Yates’ Correction for 2 n 2 Tables 206</p> <p>Single Category: Goodness of Fit Tests 206</p> <p>Summary 210</p> <p><b>Chapter 7: Introduction to Graphical Analysis 215</b></p> <p>Box-whisker Plots 215</p> <p>Basic Boxplots 216</p> <p>Customizing Boxplots 217</p> <p>Horizontal Boxplots 218</p> <p>Scatter Plots 222</p> <p>Basic Scatter Plots 222</p> <p>Adding Axis Labels 223</p> <p>Plotting Symbols 223</p> <p>Setting Axis Limits 224</p> <p>Using Formula Syntax 225</p> <p>Adding Lines of Best-Fit to Scatter Plots 225</p> <p>Pairs Plots (Multiple Correlation Plots) 229</p> <p>Line Charts 232</p> <p>Line Charts Using Numeric Data 232</p> <p>Line Charts Using Categorical Data 233</p> <p>Pie Charts 236</p> <p>Cleveland Dot Charts 239</p> <p>Bar Charts 245</p> <p>Single-Category Bar Charts 245</p> <p>Multiple Category Bar Charts 250</p> <p>Stacked Bar Charts 250</p> <p>Grouped Bar Charts 250</p> <p>Horizontal Bars 253</p> <p>Bar Charts from Summary Data 253</p> <p>Copy Graphics to Other Applications 256</p> <p>Use Copy/Paste to Copy Graphs 257</p> <p>Save a Graphic to Disk 257</p> <p>Windows 257</p> <p>Macintosh 258</p> <p>Linux 258</p> <p>Summary 259</p> <p><b>Chapter 8: Formula Notation and Complex Statistic s 263</b></p> <p>Examples of Using Formula Syntax for Basic Tests 264</p> <p>Formula Notation in Graphics 266</p> <p>Analysis of Variance (ANOVA) 268</p> <p>One-Way ANOVA 268</p> <p>Stacking the Data before Running Analysis of Variance 269</p> <p>Running aov() Commands 270</p> <p>Simple Post-hoc Testing 271</p> <p>Extracting Means from aov() Models 271</p> <p>Two-Way ANOVA 273</p> <p>More about Post-hoc Testing 275</p> <p>Graphical Summary of ANOVA 277</p> <p>Graphical Summary of Post-hoc Testing 278</p> <p>Extracting Means and Summary Statistics 281</p> <p>Model Tables 281</p> <p>Table Commands 283</p> <p>Interaction Plots 283</p> <p>More Complex ANOVA Models 289</p> <p>Other Options for aov() 290</p> <p>Replications and Balance 290</p> <p>Summary 292</p> <p><b>Chapter 9: Manipulating Data and Extracting Components 295</b></p> <p>Creating Data for Complex Analysis 295</p> <p>Data Frames 296</p> <p>Matrix Objects 299</p> <p>Creating and Setting Factor Data 300</p> <p>Making Replicate Treatment Factors 304</p> <p>Adding Rows or Columns 306</p> <p>Summarizing Data 312</p> <p>Simple Column and Row Summaries 312</p> <p>Complex Summary Functions 313</p> <p>The rowsum() Command 314</p> <p>The apply() Command 315</p> <p>Using tapply() to Summarize Using a Grouping Variable 316</p> <p>The aggregate() Command 319</p> <p>Summary 323</p> <p><b>Chapter 10: Regression (Li near Modeling) 327</b></p> <p>Simple Linear Regression 328</p> <p>Linear Model Results Objects 329</p> <p>Coefficients 330</p> <p>Fitted Values 330</p> <p>Residuals 330</p> <p>Formula 331</p> <p>Best-Fit Line 331</p> <p>Similarity between lm() and aov() 334</p> <p>Multiple Regression 335</p> <p>Formulae and Linear Models 335</p> <p>Model Building 337</p> <p>Adding Terms with Forward Stepwise Regression 337</p> <p>Removing Terms with Backwards Deletion 339</p> <p>Comparing Models 341</p> <p>Curvilinear Regression 343</p> <p>Logarithmic Regression 344</p> <p>Polynomial Regression 345</p> <p>Plotting Linear Models and Curve Fitting 347</p> <p>Best-Fit Lines 348</p> <p>Adding Line of Best-Fit with abline() 348</p> <p>Calculating Lines with fitted() 348</p> <p>Producing Smooth Curves using spline() 350</p> <p>Confidence Intervals on Fitted Lines 351</p> <p>Summarizing Regression Models 356</p> <p>Diagnostic Plots 356</p> <p>Summary of Fit 357</p> <p>Summary 359</p> <p><b>Chapter 11: More About Graphs 363</b></p> <p>Adding Elements to Existing Plots 364</p> <p>Error Bars 364</p> <p>Using the segments() Command for Error Bars 364</p> <p>Using the arrows() Command to Add Error Bars 368</p> <p>Adding Legends to Graphs 368</p> <p>Color Palettes 370</p> <p>Placing a Legend on an Existing Plot 371</p> <p>Adding Text to Graphs 372</p> <p>Making Superscript and Subscript Axis Titles 373</p> <p>Orienting the Axis Labels 375</p> <p>Making Extra Space in the Margin for Labels 375</p> <p>Setting Text and Label Sizes 375</p> <p>Adding Text to the Plot Area 376</p> <p>Adding Text in the Plot Margins 378</p> <p>Creating Mathematical Expressions 379</p> <p>Adding Points to an Existing Graph 382</p> <p>Adding Various Sorts of Lines to Graphs 386</p> <p>Adding Straight Lines as Gridlines or Best-Fit Lines 386</p> <p>Making Curved Lines to Add to Graphs 388</p> <p>Plotting Mathematical Expressions 390</p> <p>Adding Short Segments of Lines to an Existing Plot 393</p> <p>Adding Arrows to an Existing Graph 394</p> <p>Matrix Plots (Multiple Series on One Graph) 396</p> <p>Multiple Plots in One Window 399</p> <p>Splitting the Plot Window into Equal Sections 399</p> <p>Splitting the Plot Window into Unequal Sections 402</p> <p>Exporting Graphs 405</p> <p>Using Copy and Paste to Move a Graph 406</p> <p>Saving a Graph to a File 406</p> <p>Windows 406</p> <p>Macintosh 406</p> <p>Linux 406</p> <p>Using the Device Driver to Save a Graph to Disk 407</p> <p>PNG Device Driver 407</p> <p>PDF Device Driver 407</p> <p>Copying a Graph from Screen to Disk File 408</p> <p>Making a New Graph Directly to a Disk File 408</p> <p>Summary 410</p> <p><b>Chapter 12: Writing Your Own Scripts: Beginning to Program 415</b></p> <p>Copy and Paste Scripts 416</p> <p>Make Your Own Help File as Plaintext 416</p> <p>Using Annotations with the # Character 417</p> <p>Creating Simple Functions 417</p> <p>One-Line Functions 417</p> <p>Using Default Values in Functions 418</p> <p>Simple Customized Functions with Multiple Lines 419</p> <p>Storing Customized Functions 420</p> <p>Making Source Code 421</p> <p>Displaying the Results of Customized Functions and Scripts 421</p> <p>Displaying Messages as Part of Script Output 422</p> <p>Simple Screen Text 422</p> <p>Display a Message and Wait for User Intervention 424</p> <p>Summary 428</p> <p>Appendix: Answers to Exerci ses 433</p> <p>Index 461</p>
<p>Dr. Mark Gardener is an ecologist, lecturer, and writer working in the UK. He is currently self-employed and runs courses in ecology, data analysis, and R for a variety of organizations.</p>
<p>Gain better insight into your data using the power of R</p> <p>While R is very flexible and powerful, it is unlike most of the computer programs you have used. In order to unlock its full potential, this book delves into the language, making it accessible so you can tackle even the most complex of data analysis tasks. Simple data examples are integrated throughout so you can explore the capabilities and versatility of R. Along the way, you'll also learn how to carry out a range of commonly used statistical methods, including Analysis of Variance and Linear Regression. By the end, you'll be able to effectively and efficiently analyze your data and present the results.</p> <p>Beginning R:</p> <ul> <li> <p>Discusses how to implement some basic statistical methods such as the t-test, correlation, and tests of association</p> </li> <li> <p>Explains how to turn your graphs from merely adequate to simply stunning</p> </li> <li> <p>Provides you with the ability to define complex analytical situations</p> </li> <li> <p>Demonstrates ways to make and rearrange your data for easier analysis</p> </li> <li> <p>Covers how to carry out basic regression as well as complex model building and curvilinear regression</p> </li> <li> <p>Shows how to produce customized functions and simple scripts that can automate your workflow</p> </li> </ul> <p>wrox.com</p> <p>Programmer Forums</p> <p>Join our Programmer to Programmer forums to ask and answer programming questions about this book, join discussions on the hottest topics in the industry, and connect with fellow programmers from around the world.</p> <p>Code Downloads</p> <p>Take advantage of free code samples from this book, as well as code samples from hundreds of other books, all ready to use.</p> <p>Read More</p> <p>Find articles, ebooks, sample chapters and tables of contents for hundreds of books, and more reference resources on programming topics that matter to you.</p> <p>Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that guides you through all the techniques involved.</p> <p>Visit the Beginning R website at www.wrox.com/go/beginningr</p>

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €