Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Data Analysis with R, Second Edition
Data Analysis with R, Second Edition

Data Analysis with R, Second Edition: A comprehensive guide to manipulating, analyzing, and visualizing data in R , Second Edition

eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Data Analysis with R, Second Edition

The Shape of Data

Welcome back! Now that we have enough knowledge about R under our belts, we can finally move on to applying it. Let us go then, you and I, into statistics-land...

Univariate data

In this chapter, we are going to deal with univariate data, which is a fancy way of saying samples of one variable--the kind of data that goes into a single R vector. Analysis of univariate data isn't concerned with the why questions—causes, relationships, or anything like that; the purpose of univariate analysis is simply to describe.

In univariate data, one variablelet's call it xcan represent categories such as soy ice cream flavors, heads or tails, names of cute classmates, the roll of a die, and so on. In cases like these, we call x a categorical variable.

categorical.data <- c("heads", "tails", "tails", "heads") 

Categorical data is represented, in the preceding statement, as a vector of character type. In this particular example, we could further specify that this is a binary or...

Frequency distributions

A common way of describing univariate data is with a frequency distribution. We've already seen an example of a frequency distribution when we looked at the preferences for soy ice cream at the end of the last chapter. For each flavor of ice cream (categorical variable), it depicted the count or frequency of the occurrences in the underlying dataset.

To demonstrate examples of other frequency distributions, we need to find some data. Fortunately, for the convenience of useRs everywhere, R comes preloaded with almost one hundred datasets. You can view a full list if you execute help (package="datasets"). There are also hundreds more available from add-on packages.

The first dataset that we are going to use is mtcars--data on the design and performance of 32 automobiles, which was extracted from the 1974 Motor Trend US magazine. (To find out...

Central tendency

One very popular question to ask about univariate data is, What is the typical value? or What's the value around which the data are centered? To answer these questions, we have to measure the central tendency of a set of data.

We've seen one measure of central tendency already: the mode. The mtcars$carburetors data subset was bimodal, with a two and four carburetor setup being the most popular. The mode is the central tendency measure that is applicable to categorical data.

The mode of a discretized continuous distribution is usually considered to be the interval that contains the highest frequency of data points. This makes it dependent on the method and parameters of the binning. Finding the mode of data from a non-discretized continuous distribution is a more complicated procedure, which we'll see later.

Perhaps the most famous and...

Spread

Another very popular question regarding univariate data is, How variable are the data points? or How spread out or dispersed are the observations?  To answer these questions, we have to measure the spread, or dispersion, of a data sample.

The simplest way to answer this question is to take the smallest value in the dataset and subtract it by the largest value. This will give you the range. However, this suffers from a problem similar to the issue of the mean. The range in salaries at the law firm will vary widely depending on whether the CEO is included in the set. Further, the range is just dependent on two values, the highest and lowest, and therefore, can't speak of the dispersion of the bulk of the dataset.

One tactic that solves the first of these problems is to use the interquartile range.

What about measures of spread for categorical data?

The measures...

Populations, samples, and estimation

One of the core ideas of statistics is that we can use a subset of a group, study it, and then make inferences or conclusions about that much larger group.

For example, let's say we wanted to find the average (mean) weight of all the people in Germany. One way do to this is to visit all the 81 million people in Germany, record their weights, and then find the average. However, it is a far more sane endeavor to take down the weights of only a few hundred Germans, and use these to deduce the average weight of all Germans. In this case, the few hundred people we do measure is the sample, and the entirety of the people in Germany is called the population.

Now, there are Germans of all shapes and sizes: some heavier, some lighter. If we only pick a few Germans to weigh, we run the risk of, by chance, choosing a group of primarily underweight...

Probability distributions

Up until this point, when we spoke of distributions, we were referring to frequency distributions. However, when we talk about distributions later in the book--or when other data analysts refer to them--we will be talking about probability distributions, which are much more general.

It's easy to turn a categorical, discrete, or discretized frequency distribution into a probability distribution. As an example, refer to the frequency distribution of carburetors in the first image in this chapter. Instead of asking What number of cars have n number of carburetors?, we can ask, What is the probability that, if I choose a car at random, I will get a car with n carburetors?

We will talk more about probability (and different interpretations of probability) in Chapter 4, Probability, but for now, probability is a value between 0 and 1 (or 0 percent and 100...

Visualization methods

In an earlier image, we saw three very different distributions, all with the same mean and median. I said then that we need to quantify variance to tell them apart. In the following image, there are three very different distributions, all with the same mean, median, and variance:

Figure 2.10: Three PDFs with the same mean, median, and standard deviation

If you just rely on basic summary statistics to understand univariate data, you'll never get the full picture. It's only when we visualize it that we can clearly see, at a glance, whether there are any clusters or areas with a high density of data points, the number of clusters there are, whether there are outliers, whether there is a pattern to the outliers, and so on. When dealing with univariate data, the shape is the most important part. (That's why this chapter is called Shape of Data...

Univariate data


In this chapter, we are going to deal with univariate data, which is a fancy way of saying samples of one variable--the kind of data that goes into a single R vector. Analysis of univariate data isn't concerned with the why questions—causes, relationships, or anything like that; the purpose of univariate analysis is simply to describe.

In univariate data, one variable—let's call it x—can represent categories such as soy ice cream flavors, heads or tails, names of cute classmates, the roll of a die, and so on. In cases like these, we call x a categorical variable.

categorical.data <- c("heads", "tails", "tails", "heads") 

Categorical data is represented, in the preceding statement, as a vector of character type. In this particular example, we could further specify that this is a binary or dichotomous variable because it only takes on two values, namely, heads and tails.

Our variable x could also represent a number such as air temperature, the prices of financial instruments...

Frequency distributions


A common way of describing univariate data is with a frequency distribution. We've already seen an example of a frequency distribution when we looked at the preferences for soy ice cream at the end of the last chapter. For each flavor of ice cream (categorical variable), it depicted the count or frequency of the occurrences in the underlying dataset.

To demonstrate examples of other frequency distributions, we need to find some data. Fortunately, for the convenience of useRs everywhere, R comes preloaded with almost one hundred datasets. You can view a full list if you execute help (package="datasets"). There are also hundreds more available from add-on packages.

The first dataset that we are going to use is mtcars--data on the design and performance of 32 automobiles, which was extracted from the 1974 Motor Trend US magazine. (To find out more information about this dataset, execute ?mtcars).

Take a look at the first few lines of this dataset using the head function...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Analyze your data using R – the most powerful statistical programming language
  • Learn how to implement applied statistics using practical use-cases
  • Use popular R packages to work with unstructured and structured data

Description

Frequently the tool of choice for academics, R has spread deep into the private sector and can be found in the production pipelines at some of the most advanced and successful enterprises. The power and domain-specificity of R allows the user to express complex analytics easily, quickly, and succinctly. Starting with the basics of R and statistical reasoning, this book dives into advanced predictive analytics, showing how to apply those techniques to real-world data though with real-world examples. Packed with engaging problems and exercises, this book begins with a review of R and its syntax with packages like Rcpp, ggplot2, and dplyr. From there, get to grips with the fundamentals of applied statistics and build on this knowledge to perform sophisticated and powerful analytics. Solve the difficulties relating to performing data analysis in practice and find solutions to working with messy data, large data, communicating results, and facilitating reproducibility. This book is engineered to be an invaluable resource through many stages of anyone’s career as a data analyst.

Who is this book for?

Budding data scientists and data analysts who are new to the concept of data analysis, or who want to build efficient analytical models in R will find this book to be useful. No prior exposure to data analysis is needed, although a fundamental understanding of the R programming language is required to get the best out of this book.

What you will learn

  • • Gain a thorough understanding of statistical reasoning and sampling theory
  • • Employ hypothesis testing to draw inferences from your data
  • • Learn Bayesian methods for estimating parameters
  • • Train regression, classification, and time series models
  • • Handle missing data gracefully using multiple imputation
  • • Identify and manage problematic data points
  • • Learn how to scale your analyses to larger data with Rcpp, data.table, dplyr, and parallelization
  • • Put best practices into effect to make your job easier and facilitate reproducibility

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 28, 2018
Length: 570 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788397339
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Mar 28, 2018
Length: 570 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788397339
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 107.97
R Data Analysis Projects
€41.99
Data Analysis with R, Second Edition
€32.99
Regression Analysis with R
€32.99
Total 107.97 Stars icon

Table of Contents

18 Chapters
RefresheR Chevron down icon Chevron up icon
The Shape of Data Chevron down icon Chevron up icon
Describing Relationships Chevron down icon Chevron up icon
Probability Chevron down icon Chevron up icon
Using Data To Reason About The World Chevron down icon Chevron up icon
Testing Hypotheses Chevron down icon Chevron up icon
Bayesian Methods Chevron down icon Chevron up icon
The Bootstrap Chevron down icon Chevron up icon
Predicting Continuous Variables Chevron down icon Chevron up icon
Predicting Categorical Variables Chevron down icon Chevron up icon
Predicting Changes with Time Chevron down icon Chevron up icon
Sources of Data Chevron down icon Chevron up icon
Dealing with Missing Data Chevron down icon Chevron up icon
Dealing with Messy Data Chevron down icon Chevron up icon
Dealing with Large Data Chevron down icon Chevron up icon
Working with Popular R Packages Chevron down icon Chevron up icon
Reproducibility and Best Practices Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 50%
1 star 0%
hunterthehunted Aug 07, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written for people at any level of R. Highly recommended for anyone wanting to learn data analytics using R.
Amazon Verified review Amazon
Peter Baker Jul 16, 2021
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I have a good understanding of the R language and wanted a book to bring me forward in the field of Data Analysis... Boy, did I make a mistake."No prior exposure to data analysis is needed, although a fundamental understanding of the R programming language is required to get the best out of this book"This has to be a joke. I have never read a book that leaves you so dam confused even after of 2 chapters I was total unable to figure out what or which way the Author was going. Even the simple things like univariate data description is so long winded as to leave your head reeling.Don't get dragged in NOT for beginners
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.