Project-Based R Companion to Introductory Statistics Project-Based R Companion to Introductory Statistics Chelsea Myers First edition published 2021 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN © 2021 Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, LLC Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity 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 utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, 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, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978- 750-8400. For works that are not available on CCC please contact [email protected] Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging‑in‑Publication Data Names: Myers, Chelsea, author. Title: Project-based R companion to introductory statistics / Chelsea Myers. Description: First edition. | Boca Raton : Taylor and Francis, 2021. | Includes bibliographical references and index. Identifiers: LCCN 2020041189 (print) | LCCN 2020041190 (ebook) | ISBN 9780367262082 (paperback) | ISBN 9780429292002 (ebook) Subjects: LCSH: Mathematical statistics—Data processing. | R (Computer program language) Classification: LCC QA276.4 .M94 2021 (print) | LCC QA276.4 (ebook) | DDC 519.50285/5133—dc23 LC record available at https://lccn.loc.gov/2020041189 LC ebook record available at https://lccn.loc.gov/2020041190 ISBN: 978-0-367-68734-2 (hbk) ISBN: 978-0-367-26208-2 (pbk) ISBN: 978-0-429-29200-2 (ebk) Typeset in Minion Pro by KnowledgeWorks Global Ltd. Access the Support Material: https://www.routledge.com/Project‑Based‑R‑ Companion‑to‑Introductory‑Statistics/Myers/p/book/9780367262082 Contents Author, xi Introduction, xiii Chapter 1 ◾ G etting Started with R and RStudio 1 WORKING WITH RStudio 1 GUIDED PROJECT: OPEN AND MODIFY THE Titanic.xlsx DATASET IN RStudio 3 STUDENT PROJECT: OPEN AND MODIFY THE Ohio.xlsx DATASET IN RStudio 12 REFERENCES 13 Chapter 2 ◾ D escribing Categorical Data 15 INTRODUCTION 15 CATEGORICAL DATA 16 GUIDED PROJECT: DOES THE USE OF ANTISEPTICS DURING SURGERY REDUCE MORTALITY? 17 STUDENT PROJECT: DETERMINE THE IMPACT TICKET CLASS HAD ON PASSENGER SURVIVAL ON THE TITANIC 27 REFERENCES 28 Chapter 3 ◾ D escribing Quantitative Data 29 INTRODUCTION 29 STATISTICAL DISTRIBUTIONS 30 v vi ◾ Contents GUIDED PROJECT 1: DETERMINE THE CASUALTY RATE FOR UNION ARMY SOLDIERS IN COMPANIES FROM OHIO DURING THE US CIVIL WAR 31 GUIDED PROJECT 2: DETERMINE THE TYPICAL HEALTHY ADULT HUMAN BODY TEMPERATURE 42 STUDENT PROJECT 1: DETERMINE THE TYPICAL WEIGHT OF AN ADULT HUMAN BRAIN 46 STUDENT PROJECT 2: DESCRIBE THE DISTRIBUTION OF HORSE KICK DEATHS IN THE PRUSSIAN ARMY FROM 1875 TO 1894 47 REFERENCES 48 Chapter 4 ◾ The Normal Distribution 49 INTRODUCTION 49 GUIDED PROJECT: DETERMINE THE SPEED OF LIGHT IN AIR 50 STUDENT PROJECT: IS THERE EVIDENCE THAT THE HEALTHY ADULT HUMAN BODY TEMPERATURE IS NOT 98.6°F? 56 REFERENCES 57 Chapter 5 ◾ Two-Way Tables 59 INTRODUCTION 59 CONTINGENCY TABLES 59 GUIDED PROJECT: ARE FEMALE CHARACTERS IN SLASHER FILMS MORE LIKELY TO BE MURDERED THAN MALE CHARACTERS? 60 STUDENT PROJECT: DETERMINE THE IMPACT PASSENGER AGE AND SEX HAD ON THE LIKELIHOOD A PASSENGER SURVIVED THE TITANIC SINKING 66 REFERENCES 67 Contents ◾ vii Chapter 6 ◾ Linear Regression and Correlation 69 INTRODUCTION 69 SCATTERPLOTS AND LINEAR REGRESSION 69 THE CORRELATION COEFFICIENT (r) AND THE COEFFICIENT OF DETERMINATION (R2) 70 GUIDED PROJECT 1: CAN FORENSIC SCIENTISTS DETERMINE HOW LONG A BODY HAS BEEN BURIED BY HOW MUCH NITROGEN REMAINS IN THE LONG BONES OF THE SKELETON? 71 GUIDED PROJECT: DETERMINE THE RELATIONSHIP BETWEEN LAND AREA AND THE NUMBER OF PLANT SPECIES LIVING ON THE BRITISH ISLES 83 STUDENT PROJECT: IS HEAD SIZE RELATED TO BRAIN WEIGHT IN HEALTHY ADULT HUMANS? 88 REFERENCES 89 Chapter 7 ◾ Random Sampling 91 INTRODUCTION 91 SAMPLING METHODS 92 GUIDED PROJECT 1: COMPARE DIFFERENT SAMPLING METHODS FOR ESTIMATING THE MEAN FINISHING TIME AT THE DISNEY MARATHON IN 2020 93 GUIDED PROJECT 2: COMPARE DIFFERENT SAMPLING METHODS FOR ESTIMATING THE MEAN HEIGHT OF NATIONAL HOCKEY LEAGUE (NHL) PLAYERS IN 2013–2014 99 STUDENT PROJECT: COMPARE DIFFERENT SAMPLING METHODS FOR ESTIMATING THE MEAN HEIGHT OF A PREMIER LEAGUE PLAYER IN 2014–2015 104 REFERENCES 105 viii ◾ Contents Chapter 8 ◾ Inference About a Population Mean 107 INTRODUCTION 107 HYPOTHESIS TESTS 107 CONFIDENCE INTERVALS 108 ASSUMPTIONS FOR INFERENCE ABOUT A POPULATION MEAN 108 GUIDED PROJECT: IS 98.6°F (37.0°C) ACTUALLY THE NORMAL HUMAN BODY TEMPERATURE? 109 STUDENT PROJECT: HOW STANDARD IS THE CAFFEINE CONTENT IN FOUNTAIN SOFT DRINKS SERVED IN CHAIN RESTAURANTS? 117 REFERENCES 118 Chapter 9 ◾ Inference About a Population Proportion 119 INTRODUCTION 119 ASSUMPTIONS FOR INFERENCE ABOUT A POPULATION PROPORTION 119 GUIDED PROJECT: DETERMINE IF FATAL CAR ACCIDENTS ARE MORE LIKELY TO OCCUR ON FRIDAY THE 13TH THAN OTHER FRIDAYS 120 STUDENT PROJECT: IS CHOLERA TRANSMITTED BY DRINKING CONTAMINATED WATER? 129 REFERENCES 130 Chapter 10 ◾ Comparing Two Population Means 131 INTRODUCTION 131 TWO INDEPENDENT SAMPLE DESIGN 131 MATCHED PAIRS STUDY DESIGN 132 GUIDED PROJECT 1: CAN FINGERTIP AND UPPER ARM MEASURES OF SYSTOLIC BLOOD PRESSURE BE USED INTERCHANGEABLY? 133 Contents ◾ ix GUIDED PROJECT 2: DETERMINE THE MOST EFFECTIVE MOSQUITO REPELLANT TREATMENT FOR SOLDIERS IN THE INDIAN ARMY 140 STUDENT PROJECT 1: DETERMINING LEAD CONCENTRATIONS IN LIP COSMETICS 145 STUDENT PROJECT 2: ARE THE RESULTS OF A NEW TEST DESIGNED TO ASSESS FAT CONTENT IN HUMAN MILK CONSISTENT WITH THE “GOLD STANDARD” GERBER METHOD 146 REFERENCES 147 Chapter 11 ◾ Comparing Two Population Proportions 149 INTRODUCTION 149 STUDENT PROJECT: ARE FEMALE CHARACTERS IN SLASHER FILMS MORE LIKELY TO BE MURDERED THAN MALE CHARACTERS? 150 STUDENT PROJECT: IS CHOLERA TRANSMITTED BY DRINKING CONTAMINATED WATER? 154 REFERENCES 156 STUDENT PROJECT 1 – DOES BRAIN WEIGHT DIFFER BY AGE IN HEALTHY ADULT HUMANS?, 157 STUDENT PROJECT 2 – PREVENTING ACUTE MOUNTAIN SICKNESS WITH GINKGO BILOBA AND ACETAZOLAMIDE, 159 STUDENT PROJECT 3 – WHAT FACTORS INFLUENCE MAMMAL SLEEP PATTERNS?, 163 INDEX, 165