R Statistics Cookbook
Over 100 recipes for performing complex statistical operations with R 3.5
Francisco Juretig
BIRMINGHAM - MUMBAI
R Statistics Cookbook
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Pravin Dhandre
Acquisition Editor: Devika Battike
Content Development Editor: Athikho Sapuni Rishana
Technical Editor: Utkarsha S. Kadam
Copy Editor: Safis Editing
Project Coordinator: Kirti Pisat
Proofreader: Safis Editing
Indexer: Priyanka Dhadke
Graphics: Jisha Chirayil
Production Coordinator: Arvindkumar Gupta
First published: March 2019
Production reference: 1280319
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78980-256-6
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Francisco Juretig has worked for over a decade in a variety of industries such as retail, gambling and finance deploying data-science solutions. He has written several R packages, and is a frequent contributor to the open source community.
About the reviewer
Davor Lozic is a senior software engineer interested in a variety of subjects, in particular, computer security, algorithms, and data structures. He manages teams of more than 15 engineers and is a professor when it comes to teaching what there is to know about database systems. You can contact him at davor@warriorkitty.com. He likes cats! If you want to talk about any aspect of technology, or if you have funny pictures of cats, feel free to contact him.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Preface
R is a popular programming language for developing statistical software. This book will be a useful guide to solving common and not-so-common challenges in statistics. With this book, you'll be equipped to confidently perform essential statistical procedures across your organization with the help of cutting-edge statistical tools.
You'll start by implementing data modeling, data analysis, and machine learning to solve real-world problems. You'll then understand how to work with nonparametric methods, mixed effects models, and hidden Markov models. This book contains recipes that will guide you in performing univariate and multivariate hypothesis tests, several regression techniques, and using robust techniques to minimize the impact of outliers in data.You'll also learn how to use the caret package for performing machine learning in R. Furthermore, this book will help you understand how to interpret charts and plots to get insights for better decision making.
By the end of this book, you will be able to apply your skills to statistical computations using R 3.5. You will also become well-versed with a wide array of statistical techniques in R that are extensively used in the data science industry.
Who this book is for
If you are a quantitative researcher, statistician, data analyst, or data scientist looking to tackle common and not-so-common challenges in statistics, then this book is what you need! A solid understanding of R programming and a basic understanding of statistics and linear algebra.
What this book covers
, Getting Started with R and Statistics , reviews a variety of techniques in R for performing data processing, data analysis, and plotting. We will also explain how to work with some basic statistical techniques, such as sampling, maximum likelihood estimation, and random number generation. In addition, we will present some useful coding techniques, such as C++ functions using Rcpp, and R6Classes. The former will allow us to add high-performance compiled code, whereas the latter will allow us to perform object-oriented programming in R.
, Univariate and Multivariate Tests for Equality of Means , explains how to answer the most basic statistical question: do two (or possibly more) populations have the same mean? This arises when we want to evaluate whether certain treatment/policy is effective compared to a baseline effect. This can naturally be extended to multiple groups, and the technique used for this is called Analysis of Variance (ANOVA). ANOVA can itself be extended to accommodate multiple effects; for example, testing whether the background color of a website and the font style drive sales up. This is known as two-way ANOVA, and leads to additional complications: not only do we have multiple effects to estimate, but also we could have interaction effects happening between these two effects (for example, a certain background color could be effective when used in conjunction with a specific font type). ANOVA can also be extended in other dimensions, such as adding random effects (effects that originate from a large population and where we don't want to estimate a parameter for each one of them), or repeated measures for each observation.