Data Science in R
A Case Studies Approach to
Computational Reasoning
and Problem Solving
Chapman & Hall/CRC
The R Series
Series Editors
John M. Chambers
Department of Statistics
Stanford University
Stanford, California, USA
Duncan Temple Lang
Department of Statistics
University of California, Davis
Davis, California, USA
Torsten Hothorn
Division of Biostatistics
University of Zurich
Switzerland
Hadley Wickham
RStudio
Boston, Massachusetts, USA
Aims and Scope
This book series reflects the recent rapid growth in the development and application
of R, the programming language and software environment for statistical computing
and graphics. R is now widely used in academic research, education, and industry.
It is constantly growing, with new versions of the core software released regularly
and more than 6,000 packages available. It is difficult for the documentation to
keep pace with the expansion of the software, and this vital book series provides a
forum for the publication of books covering many aspects of the development and
application of R.
The scope of the series is wide, covering three main threads:
• Applications of R to specific disciplines such as biology, epidemiology,
genetics, engineering, finance, and the social sciences.
• Using R for the study of topics of statistical methodology, such as linear and
mixed modeling, time series, Bayesian methods, and missing data.
• The development of R, including programming, building packages, and
graphics.
The books will appeal to programmers and developers of R software, as well as
applied statisticians and data analysts in many fields. The books will feature
detailed worked examples and R code fully integrated into the text, ensuring their
usefulness to researchers, practitioners and students.
Published TitlesStated Preference Methods Using R, Hideo Aizaki, Tomoaki Nakatani, and Kazuo SatoUsing R for Numerical Analysis in Science and Engineering, Victor A. BloomfieldEvent History Analysis with R, Göran BroströmComputational Actuarial Science with R, Arthur CharpentierStatistical Computing in C++ and R, Randall L. Eubank and Ana KupresaninReproducible Research with R and RStudio, Christopher GandrudIntroduction to Scientific Programming and Simulation Using R, Second Edition, Owen Jones, Robert Maillardet, and Andrew Robinson Nonparametric Statistical Methods Using R, John Kloke and Joseph McKeanDisplaying Time Series, Spatial, and Space-Time Data with R, Oscar Perpiñán LamigueiroProgramming Graphical User Interfaces with R, Michael F. Lawrence and John VerzaniAnalyzing Sensory Data with R, Sébastien Lê and Theirry WorchAnalyzing Baseball Data with R, Max Marchi and Jim AlbertGrowth Curve Analysis and Visualization Using R, Daniel MirmanR Graphics, Second Edition, Paul MurrellData Science in R: A Case Studies Approach to Computational Reasoning and Problem Solving, Deborah Nolan and Duncan Temple Lang Multiple Factor Analysis by Example Using R, Jérôme PagèsCustomer and Business Analytics: Applied Data Mining for Business Decision Making Using R, Daniel S. Putler and Robert E. KriderImplementing Reproducible Research, Victoria Stodden, Friedrich Leisch, and Roger D. Peng Using R for Introductory Statistics, Second Edition, John VerzaniAdvanced R, Hadley WickhamDynamic Documents with R and knitr, Yihui Xie
This page intentionally left blank
This page intentionally left blank
Data Science in R
A Case Studies Approach to
Computational Reasoning
and Problem Solving
Deborah Nolan
University of California, Berkeley
USA
Duncan Temple Lang
University of California, Davis
USA
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2015 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
No claim to original U.S. Government works
Version Date: 20150310
International Standard Book Number-13: 978-1-4822-3482-4 (eBook - PDF)
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been
made to publish reliable data and information, but the author and publisher cannot assume responsibility for the valid-
ity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or uti-
lized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopy-
ing, microfilming, and recording, or in any information storage or retrieval system, without written permission from the
publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For
organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
To our families — Zoë and Suzana, and Dave, Ben, and Sam,
and to our mentors John Chambers and Terry Speed.