Statistical Analysis with R

4.3 (3 reviews total)
By John M. Quick
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Uncovering the Strategist's Data Analysis Tool

About this book

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.

Publication date:
October 2010


Chapter 1. Uncovering the Strategist's Data Analysis Tool

Near the end of the second century A.D., China's Han dynasty crumbled and left numerous warlords fighting for the throne. By the start of the third century, three kingdoms—Shu, Wei, and Wu—emerged as contenders for China's rule. These factions would vie for power for the better part of 80 years during what is known as the Three Kingdoms period of Chinese history.

The most famous military strategist of the era, Zhuge Liang, joined the Shu army in 207 A.D. He is well known for baffling opposing forces with ingenious techniques and cunning tactics. As a result, Zhuge Liang remains a Chinese cultural symbol of intellect and wisdom to this day. In 228 A.D., Zhuge Liang would launch the first of five campaigns against the rival kingdom of Wei. During his fifth, and final, campaign at the Wuzhang Plains, Zhuge Liang fell terminally ill. Following his death in August of 234 A.D., the Shu army was forced to withdraw from its conflict with the kingdom of Wei.

— Taken from Three Kingdoms. Beijing, China: Foreign Language Press; Luo Guanzhong. Translator Moss Roberts.

Prior to his passing, the legendary strategist chose you to succeed him as commander of the Shu forces. Zhuge Liang also left you with secret documents that reveal the knowledge of a powerful data analysis tool.

With your forces currently recuperating in Hanzhong, China, it is your duty to plan the next move. Armed with the late strategist's tool and your talents for data analysis, the fate of the Shu kingdom is in your hands.

By the end of this chapter, you will be able to:

  • Describe the R Project for Statistical Computing

  • Detail how you will benefit from using R

  • Explain why R is an essential tool for your work

  • Decide why this book is right for you

  • List the major topics covered in this book


What is R?

As the newly appointed strategist for the Shu army, your decisions will impact the lives of many. Great decisions tend not to occur by random chance. Rather, they are a product of knowledge, planning, and sound rationale. A major factor in generating fruitful outcomes is considering the available information and using it to assess your potential courses of action. Fortunately, an essential software tool exists that will help you rise to the occasion and make the most of any situation.

The R Project for Statistical Computing (or just R for short) is a powerful data analysis tool. It is both a programming language and a computational and graphical environment.

R is free, open source software made available under the GNU General Public License. It runs on Mac, Windows, and Unix operating systems.

The official R website is available at the following site:


What are the benefits of using R?

There are several ways in which R will benefit you, be it as an information technology professional, business analyst, leader of the Shu army, or otherwise. These benefits are discussed in the following points:

  • Free: R is available to you at no cost. The saying, "give a person a data analysis tool and he or she will learn to analyze data" has never been more true.

  • Cross-platform: R runs on Mac, Windows, and numerous Unix systems. Whether you are visiting the Emperor in Chengdu or laying siege to the enemy capital at Luoyang, you can be confident that your software will run, regardless of the local operating system.

  • Open source: R is open source. It allows you to exercise your genius in ways that a closed software does not.

  • Programmable: R includes a powerful yet straightforward programming language that is designed to compliment the formation of complex strategies.

  • Extendable: R can be expanded through thousands of available packages. If you are looking for a function to calculate the odds of a successful fire attack, the chances are someone has already made it. If not, you can create it and offer it to the world.

  • Graphical: R contains robust graphical capabilities. Whether you are looking to create an unassuming plot of provision use over time or an elaborate array of battle maps, R is at your service.

  • Community-supported: R has a vast user community that is continually updating and contributing to its capabilities. Even the great Zhuge Liang had to rely on his allies from time to time.


Why should I use R?

You should use R because you are interested in taking control of and making the most out of your data. R provides you with opportunities to design and execute complex, customized analyses that other software packages do not. At the same time, R remains accessible and relevant to a large audience of potential users.

With the fate of a kingdom resting upon your shoulders, you can ill afford a miscalculation or misinterpretation. R will assist you in making the best possible decisions and allow you to rise to greatness as a premier strategist.


Why should I read this book?

You should read this book because you are interested in learning how to improve your work through the use of R. You do not need to be an expert at using a programming language, other software packages, or statistics. No prior experience with R is necessary. With a willingness to learn and an interest in conducting superior data analyses, you will quickly become an experienced and knowledgeable user of R.


What topics are covered in this book?

This book covers an extensive range of topics in R. It will comfortably and rapidly familiarize you with the basics, before you proceed into in-depth analyses and custom graphics. A brief description of each chapter's content is provided.

Chapter 2—Preparing R for Battle

In this chapter, we will step through the R installation process. Afterwards, you will launch R and execute your first commands in the R console.

By the end of the chapter, you will be able to:

  • Download R

  • Install R

  • Run R on your computer

  • Issue an R command

  • Set your R working directory

Chapter 3—Exploring the Mysterious Data Analysis Tool

In this chapter, we will explore the anatomy of the R console in greater depth by solving a challenging puzzle that was presented to us by the late Zhuge Liang.

By the end of the chapter, you will be able to:

  • Use proper syntax within the R console

  • Comment your R code

  • Make calculations using formulas

  • Distinguish between different types of input and output in the R console

Chapter 4—Collecting and Organizing Information

In this chapter, we will focus on getting our data into R and then manipulating it via variables. We will also learn how to manage the R workspace.

By the end of the chapter, you will be able to:

  • Import external data into R

  • Use variables to organize and manipulate your data

  • Manage the R workspace

Chapter 5—Assessing the Situation

In this chapter, we will extensively examine and evaluate our data. This will entail the use of diverse functions to create predictive data models. Throughout this process, we will also consider the practical and statistical meaning behind our analyses.

By the end of the chapter, you will be able to:

  • Use multi-argument and variable-argument functions to make calculations

  • Create predictive data models using regression analysis

  • Consider the statistical and practical significance of your analyses

Chapter 6—Planning the Attack

In this chapter, we will turn towards using our data models to predict outcomes. We will also assess the viability of these outcomes. Along the way, we will create and employ our own custom functions that expand the capabilities of R.

By the end of the chapter, you will be able to:

  • Use regression models to predict outcomes

  • Create your own custom functions to address specific needs

  • Assess the viability of achieving the outcomes predicted by regression models.

Chapter 7—Organizing the Battle Plans

In this chapter, our task will be to review and organize a complete data analysis. We will emphasize the need to clarify and communicate our data analyses effectively, which can be achieved through a series of common steps.

By the end of the chapter, you will be able to:

  • Organize and clarify your raw R data analyses

  • Communicate your raw R data analyses in the most effective manner

  • Apply the steps common to all well-conducted R analyses

Chapter 8—Briefing the Emperor

In this chapter, we will take our first look at R's graphical capabilities by generating several charts, graphs, and plots. Throughout, we will use common graphical parameters to customize these visuals. We will also save and export our graphics for external use.

By the end of the chapter, you will be able to:

  • Create six different charts, graphs, and plots in R

  • Customize your R visuals using text, colors, axes, and legends

  • Save and export your graphics for use outside of R

Chapter 9—Briefing the Generals

In this chapter, we will take a deeper look at R's graphical capabilities. We will practice customizing different types of charts, graphs, and plots by modifying their unique parameters. We will also learn how to build our own custom graphics from scratch using R's graphics functions.

By the end of the chapter, you will be able to:

  • Customize several charts, graphs, and plots using arguments specific to each

  • Use graphics functions to add information to any visual

  • Create custom graphics by building them from the ground up

Chapter 10—Becoming a Master Strategist

In the final chapter, we will look to the future. We will focus on the ways in which you can learn beyond the contents of this book to further expand your knowledge of R.

By the end of the chapter, you will be able to:

  • Use R's built-in help system

  • Install packages that expand R's functionality

  • Take advantage of electronic learning resources, such as websites, blogs, and online communities



In this chapter, we were introduced to R. We learned that its benefits include being free, cross-platform, open source, programmable, extendable, graphical, and community-supported. We also considered why you should use R to conduct your data analyses and how this book can help you quickly become an experienced R user.

You should now be able to:

  • Describe the R Project for Statistical Computing

  • Detail how you will benefit from using R

  • Explain why R is an essential tool for your work

  • Decide why this book is right for you

  • List the major topics covered in this book

In the next chapter, we will work through the installation process to prepare R for battle.

About the Author

  • John M. Quick

    He is an Educational Technology doctoral student at Arizona State University who is interested in the design, research, and use of educational innovations. Currently, his work focuses on mobile, game-based, and global learning, interactive mixed-reality systems, and innovation adoption. John's blog, which provides articles, tutorials, reviews, perspectives, and news relevant to technology and education, is available from In his spare time, John enjoys photography, nature, and travel.

    Browse publications by this author

Latest Reviews

(3 reviews total)
Omöjligt att bedöma då jag ännu inte fått boken.
I've just started using it but so far it exceeds my expectations
Book Title
Access this book and the full library for FREE
Access now