You are previewing Statistical Analysis with R Beginner's Guide.
O'Reilly logo
Statistical Analysis with R Beginner's Guide

Book Description

This guide uses an inventive role-playing approach to teaching the most effective data analysis techniques using R. Entertaining and involving, it comes with examples, screenshots, and code for fast learning.

  • An easy introduction for people who are new to R, with plenty of strong examples for you to work through

  • This book will take you on a journey to learn R as the strategist for an ancient Chinese kingdom!

  • A step by step guide to understand R, its benefits, and how to use it to maximize the impact of your data analysis

  • A practical guide to conduct and communicate your data analysis with R in the most effective manner

  • In Detail

    R is a data analysis tool, graphical environment, and programming language. Without any prior experience in programming or statistical software, this book will help you quickly become a knowledgeable user of R. Now is the time to take control of your data and start producing superior statistical analysis with R.

    This book will take you on a journey as the strategist for an ancient Chinese kingdom. Along the way, you will learn how to use R to arrive at practical solutions and how to effectively communicate your results. Ultimately, the fate of the kingdom depends on your ability to make informed, data-driven decisions with R.

    You have unexpectedly been thrust into the role of lead strategist for the kingdom. After you install your predecessor's mysterious data analysis tool, you will begin to explore its fundamental elements. Next, you will use R to import and organize your data. Then, you will use functions and statistical analysis to arrive at potential courses of action. Subsequently, you will design your own functions to assess the practical impacts of your predictions. Lastly, you will focus on communicating your results through the use of charts, plots, graphs, and custom built visualizations. The fate of the kingdom is in your hands. Your rapid development as a master R strategist is the key to future success.

    A step by step guide to organize, analyze, and visualize your data in R.

    Table of Contents

    1. Statistical Analysis with R
      1. Table of Contents
      2. Statistical Analysis with R
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Time for action - heading
          1. What just happened?
          2. Pop quiz - heading
          3. Have a go hero - heading
        6. Reader feedback
        7. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Uncovering the Strategist's Data Analysis Tool
        1. What is R?
        2. What are the benefits of using R?
        3. Why should I use R?
        4. Why should I read this book?
        5. What topics are covered in this book?
          1. Chapter 2 — Preparing R for Battle
          2. Chapter 3 — Exploring the Mysterious Data Analysis Tool
          3. Chapter 4 — Collecting and Organizing Information
          4. Chapter 5 — Assessing the Situation
          5. Chapter 6 — Planning the Attack
          6. Chapter 7 — Organizing the Battle Plans
          7. Chapter 8 — Briefing the Emperor
          8. Chapter 9 — Briefing the Generals
          9. Chapter 10 — Becoming a Master Strategist
        6. Summary
      8. 2. Preparing R for Battle
        1. Time for action - downloading and installing R
          1. Example: R 2.11.1 Mac OS X 10.5+ installation wizard demonstration
          2. What just happened?
        2. Time for action - issuing your first R command
          1. What just happened?
        3. Time for action - setting your R working directory
          1. What just happened?
          2. Pop quiz
          3. Have a go hero
        4. Summary
      9. 3. Exploring the Mysterious Data Analysis Tool
        1. Deciphering Zhuge Liang's magic square
        2. Time for action - solving the first 4x4 magic square
          1. What just happened?
          2. Lines
          3. Comments
          4. Calculations
          5. Output
          6. Visualizing the R console
          7. Pop quiz
          8. Have a go hero
        3. Summary
      10. 4. Collecting and Organizing Information
        1. Time for action - importing external data
          1. What just happened?
          2. read.csv(file)
          3. comma-separated values (csv) files
          4. Pop quiz
        2. Time for action - creating and calling variables
          1. What just happened?
          2. Pop quiz
          3. Have a go hero
        3. Time for action - accessing data within variables
          1. What just happened?
          2. variable$column notation
          3. attach(variable) function
          4. variable[row, column] notation
          5. Pop quiz
        4. Time for action - manipulating variable data
          1. What just happened?
          2. Performing a calculation on an entire dataset
          3. Performing a calculation on a row, column, or cell
          4. Using variable data in function arguments
          5. Saving a variable calculation into a new variable
          6. Pop quiz
          7. Have a go hero
        5. Time for action - managing the R workspace
          1. What just happened?
          2. Listing the contents of the R workspace
          3. Saving the contents of the R workspace
          4. Loading the contents of the R workspace
          5. Quitting R
          6. Distinguishing between the R console and workspace
          7. Saving the R console
          8. Pop quiz
          9. Have a go hero
        6. Summary
      11. 5. Assessing the Situation
        1. Time for action - making an initial inference from our data
          1. What just happened?
        2. Examining our data
        3. Time for action - creating a subset from a large dataset
          1. What just happened?
          2. Multi-argument functions
          3. Variable-argument functions
          4. Equivalency operators
          5. subset(data, ...)
          6. Pop quiz
          7. Have a go hero
        4. Time for action - deriving summary statistics
          1. What just happened?
          2. Means
          3. Standard deviations
          4. Ranges
          5. summary(object)
          6. Why use summary statistics?
          7. Pop quiz
          8. Have a go hero
        5. Time for action - quantifying categorical variables
          1. What just happened?
          2. as.numeric(data)
          3. Overwriting variables
          4. Pop quiz
          5. Have a go hero
        6. Time for action - correlating variables
          1. What just happened?
          2. Interpreting correlations
          3. cor(x, y)
          4. cor(data)
          5. NA values
          6. Pop quiz
          7. Have a go hero
        7. Regression
        8. Time for action - modelling with simple linear regression
          1. What just happened?
          2. lm(formula, data)
          3. Linear model output
          4. Linear model summary
          5. Interpreting a linear regression model
          6. Pop quiz
        9. Time for action - modelling with multiple linear regression
          1. What just happened?
          2. Interpreting the summary output
          3. Explaining model differences
          4. Pop quiz
          5. Have a go hero
        10. Time for action - modelling interactions
          1. What just happened?
          2. Interpreting interaction variables
          3. Pop quiz
          4. Have a go hero
        11. Time for action - comparing and choosing models
          1. What just happened?
            1. Interpreting the model summaries
            2. Interpreting the ANOVA results
          2. anova(object, ...)
          3. Pop quiz
          4. Have a go hero
        12. Summary
      12. 6. Planning the Attack
        1. Review of models
          1. Head to head
          2. Surround
          3. Ambush
          4. Fire
        2. Predicting outcomes using regression models
          1. Rating
          2. Successfully executed
          3. Number of Wei soldiers
          4. Duration of battle
          5. A word about assumptions
        3. Time for action - calculating outcomes from regression models
          1. What just happened?
        4. Time for action - creating custom functions
          1. What just happened?
          2. function()
          3. Extended lines
          4. Pop quiz
          5. Have a go hero
        5. Time for action - creating resource-focused custom functions
          1. What just happened?
          2. Have a go hero
        6. Logistical considerations
          1. Gold
          2. Provisions
          3. Equipment
          4. Soldiers
          5. Resource and cost summary
          6. Resource map
        7. Time for action - incorporating resource constraints into predictions
          1. What just happened?
          2. Gold cost function explanation
          3. Pop quiz
          4. Have a go hero
        8. Assessing viability
        9. Time for action - assessing the viability of potential strategies
          1. What just happened?
          2. Remember your assumptions
          3. Pop quiz
          4. Have a go hero - choosing a battle plan
        10. Summary
      13. 7. Organizing the Battle Plans
        1. Retracing and refining a complete analysis
        2. Time for action - first steps
          1. What just happened?
        3. Time for action - data setup
          1. What just happened?
          2. read.table(...)
          3. Pop quiz
        4. Time for action - data exploration
          1. What just happened?
          2. Pop quiz
        5. Time for action - model development
          1. What just happened?
          2. glm(...)
          3. AIC(object, ...)
          4. Pop quiz
        6. Time for action - model deployment
          1. What just happened?
          2. coef(object)
          3. Pop quiz
        7. Time for action - last steps
        8. The common steps to all R analyses
          1. Step 1: Set your working directory
            1. Comment your work
          2. Step 2: Import your data (or load an existing workspace)
          3. Step 3: Explore your data
          4. Step 4: Conduct your analysis
          5. Step 5: Save your workspace and console files
          6. Pop quiz
          7. Have a go hero
        9. Summary
      14. 8. Briefing the Emperor
        1. Charts, graphs, and plots in R
        2. Time for action - creating a bar chart
          1. What just happened?
          2. barplot(...)
          3. Vectors
          4. Graphic window
          5. Pop quiz
        3. Time for action - customizing graphics
          1. What just happened?
          2. Graphic customization arguments
            1. main, xlab, and ylab
            2. xlim and ylim
            3. Col
              1. Rainbow colors
              2. Specific colors
          3. legend(...)
          4. Pop quiz
        4. Time for action - creating a scatterplot
          1. What just happened?
          2. Single scatterplot
          3. Multiple scatterplots
          4. Pop quiz
        5. Time for action - creating a line chart
          1. What just happened?
          2. type
          3. Number-colon-number notation
          4. Pop quiz
        6. Time for action - creating a box plot
          1. What just happened?
          2. boxplot(...)
          3. Pop quiz
        7. Time for action - creating a histogram
          1. What just happened?
          2. hist(...)
          3. Pop quiz
        8. Time for action - creating a pie chart
        9. What just happened
        10. pie(...)
        11. Pop quiz
        12. Have a go hero
        13. Time for action - exporting graphics
          1. What just happened?
          2. Pop quiz
          3. Have a go hero
        14. Summary
      15. 9. Briefing the Generals
        1. More charts, graphs, and plots in R
        2. Time for action - customizing a bar chart
          1. What just happened?
          2. names
          3. width and space
          4. horiz
          5. beside
          6. density and angle
          7. legend(...) with density, angle, and cex
          8. Pop quiz
          9. Have a go hero
        3. Time for action - customizing a scatterplot
          1. What just happened?
          2. pch and cex
          3. points(...)
          4. legend(...)
          5. abline(...)
          6. Pop quiz
          7. Have a go hero
        4. Time for action - customizing a line chart
          1. What just happened?
          2. lwd
          3. lines(...)
          4. legend(...)
          5. Pop quiz
          6. Have a go hero
        5. Time for action - customizing a box plot
          1. What just happened?
          2. range
          3. axis(...)
          4. Pop quiz
          5. Have a go hero
        6. Time for action - customizing a histogram
          1. What just happened?
          2. breaks
          3. freq
          4. Pop quiz
          5. Have a go hero
        7. Time for action - customizing a pie chart
          1. What just happened?
          2. Custom labels
          3. legend(...)
          4. Pop quiz
          5. Have a go hero
        8. Time for action - building a graphic
          1. What just happened?
          2. Pop quiz
          3. Have a go hero
        9. Time for action - building a graphic with multiple visuals
          1. What just happened?
          2. par(mfcol)
          3. Graphics
            1. Horizontal and vertical lines
            2. Nested functions
          4. Pop quiz
          5. Have a go hero
        10. Summary
      16. 10. Becoming a Master Strategist
        1. R's built-in resources
        2. Time for action - using R's help function
          1. What just happened?
          2. help(...)
          3. Pop quiz
          4. Have a go hero
        3. Time for action - expanding R with packages
          1. What just happened?
          2. Choose a CRAN mirror
          3. Install a package
          4. Load the package
          5. Use the package
          6. Pop quiz
          7. Have a go hero
        4. R's online resources
          1. Websites
            1. The R Project for Statistical Computing
            2. Quick-R
            3. R Programming wikibook
            4. R Graph Gallery
            5. Crantastic!
          2. Blogs
            1. R bloggers
            2. R Tutorial Series
          3. Online communities
            1. R-help mailing list
            2. Other mailing lists
          4. Search engines
            1. R Seek
            2. Google
        5. Summary
      17. A. Pop Quiz Answer Key
        1. Chapter 2
        2. Chapter 3
        3. Chapter 4
        4. Chapter 5
        5. Chapter 6
        6. Chapter 7
        7. Chapter 8
        8. Chapter 9
        9. Chapter 10
      18. Index