0% found this document useful (0 votes)
2 views

Beginning Data Science in R 4: Data Analysis, Visualization, and Modelling for the Data Scientist 2nd Edition Thomas Mailund pdf download

The document is a promotional listing for the book 'Beginning Data Science in R 4: Data Analysis, Visualization, and Modelling for the Data Scientist' by Thomas Mailund, which is available for download. It includes links to additional resources and related books on data science and programming in R. The book covers various topics including R programming, data manipulation, visualization, and supervised learning.

Uploaded by

haejorben63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Beginning Data Science in R 4: Data Analysis, Visualization, and Modelling for the Data Scientist 2nd Edition Thomas Mailund pdf download

The document is a promotional listing for the book 'Beginning Data Science in R 4: Data Analysis, Visualization, and Modelling for the Data Scientist' by Thomas Mailund, which is available for download. It includes links to additional resources and related books on data science and programming in R. The book covers various topics including R programming, data manipulation, visualization, and supervised learning.

Uploaded by

haejorben63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Beginning Data Science in R 4: Data Analysis,

Visualization, and Modelling for the Data


Scientist 2nd Edition Thomas Mailund pdf
download
https://ebookmeta.com/product/beginning-data-science-in-r-4-data-
analysis-visualization-and-modelling-for-the-data-scientist-2nd-
edition-thomas-mailund/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Functional Programming in R 4: Advanced Statistical


Programming for Data Science, Analysis, and Finance -
Second Edition Thomas Mailund

https://ebookmeta.com/product/functional-programming-
in-r-4-advanced-statistical-programming-for-data-science-
analysis-and-finance-second-edition-thomas-mailund/

Functional Data Structures in R 1st Edition Thomas


Mailund

https://ebookmeta.com/product/functional-data-structures-
in-r-1st-edition-thomas-mailund/

Data Architecture A Primer for the Data Scientist A


Primer for the Data Scientist 2nd Edition W.H. Inmon

https://ebookmeta.com/product/data-architecture-a-primer-for-the-
data-scientist-a-primer-for-the-data-scientist-2nd-edition-w-h-
inmon/

Construction 4 0 Advanced Technology Tools and


Materials for the Digital Transformation of the
Construction Industry Woodhead Publishing Series in
Civil and Structural Engineering 1st Edition Casini
https://ebookmeta.com/product/construction-4-0-advanced-
technology-tools-and-materials-for-the-digital-transformation-of-
the-construction-industry-woodhead-publishing-series-in-civil-
Solar Dragons Need Love Too 2 a harem lit slice of life
1st Edition Virgil Knightley

https://ebookmeta.com/product/solar-dragons-need-love-
too-2-a-harem-lit-slice-of-life-1st-edition-virgil-knightley/

Migration Health and Inequalities Critical Activist


Research across Ecuadorean Borders 1st Edition Roberta
Villalón

https://ebookmeta.com/product/migration-health-and-inequalities-
critical-activist-research-across-ecuadorean-borders-1st-edition-
roberta-villalon/

Embedded System Design with ARM Cortex-M


Microcontrollers: Applications with C, C++ and
MicroPython Cem Ünsalan

https://ebookmeta.com/product/embedded-system-design-with-arm-
cortex-m-microcontrollers-applications-with-c-c-and-micropython-
cem-unsalan/

Data Security: Technical And Organizational Protection


Measures Against Data Loss And Computer Crime 1st
Edition Thomas H. Lenhard

https://ebookmeta.com/product/data-security-technical-and-
organizational-protection-measures-against-data-loss-and-
computer-crime-1st-edition-thomas-h-lenhard/

Peer review In An Era Of Evaluation: Understanding The


Practice Of Gatekeeping In Academia 1st Edition Eva
Forsberg

https://ebookmeta.com/product/peer-review-in-an-era-of-
evaluation-understanding-the-practice-of-gatekeeping-in-
academia-1st-edition-eva-forsberg/
Underdogs Social Deviance and Queer Theory 1st Edition
Heather Love

https://ebookmeta.com/product/underdogs-social-deviance-and-
queer-theory-1st-edition-heather-love/
Beginning Data Science
in R 4
Data Analysis, Visualization,
and Modelling for the Data Scientist
Second Edition

Thomas Mailund
Beginning Data Science in R 4: Data Analysis, Visualization, and Modelling for the
Data Scientist

Thomas Mailund
Aarhus, Denmark

ISBN-13 (pbk): 978-1-4842-8154-3 ISBN-13 (electronic): 978-1-4842-8155-0


https://doi.org/10.1007/978-1-4842-8155-0

Copyright © 2022 by Thomas Mailund


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: James Markham
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Pixabay (www.pixabay.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.
springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science
+ Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub (https://github.com/Apress). For more detailed information, please visit http://www.
apress.com/source-code.
Printed on acid-free paper
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Introduction to R Programming�������������������������������������������������������������� 1


Basic Interaction with R���������������������������������������������������������������������������������������������������������������� 1
Using R As a Calculator����������������������������������������������������������������������������������������������������������������� 3
Simple Expressions����������������������������������������������������������������������������������������������������������������� 4
Assignments���������������������������������������������������������������������������������������������������������������������������� 6
Indexing Vectors���������������������������������������������������������������������������������������������������������������������� 9
Vectorized Expressions���������������������������������������������������������������������������������������������������������� 11
Comments����������������������������������������������������������������������������������������������������������������������������������� 13
Functions������������������������������������������������������������������������������������������������������������������������������������ 13
Getting Documentation for Functions������������������������������������������������������������������������������������ 14
Writing Your Own Functions�������������������������������������������������������������������������������������������������� 16
Summarizing and Vector Functions��������������������������������������������������������������������������������������� 17
A Quick Look at Control Flow������������������������������������������������������������������������������������������������ 20
Factors���������������������������������������������������������������������������������������������������������������������������������������� 26
Data Frames�������������������������������������������������������������������������������������������������������������������������������� 32
Using R Packages����������������������������������������������������������������������������������������������������������������������� 36
Dealing with Missing Values������������������������������������������������������������������������������������������������������� 37
Data Pipelines����������������������������������������������������������������������������������������������������������������������������� 38
Writing Pipelines of Function Calls���������������������������������������������������������������������������������������� 39
Writing Functions That Work with Pipelines�������������������������������������������������������������������������� 41
The Magical “.” Argument������������������������������������������������������������������������������������������������������ 42
iii
Table of Contents

Other Pipeline Operations������������������������������������������������������������������������������������������������������ 47


Coding and Naming Conventions������������������������������������������������������������������������������������������� 49
Exercises������������������������������������������������������������������������������������������������������������������������������������� 50
Mean of Positive Values��������������������������������������������������������������������������������������������������������� 50
Root Mean Square Error�������������������������������������������������������������������������������������������������������� 50

Chapter 2: Reproducible Analysis�������������������������������������������������������������������������� 51


Literate Programming and Integration of Workflow and Documentation������������������������������������ 52
Creating an R Markdown/knitr Document in RStudio����������������������������������������������������������������� 53
The YAML Language�������������������������������������������������������������������������������������������������������������������� 57
The Markdown Language����������������������������������������������������������������������������������������������������������� 59
Formatting Text���������������������������������������������������������������������������������������������������������������������� 60
Cross-Referencing����������������������������������������������������������������������������������������������������������������� 64
Bibliographies������������������������������������������������������������������������������������������������������������������������ 65
Controlling the Output (Templates/Stylesheets)�������������������������������������������������������������������� 66
Running R Code in Markdown Documents���������������������������������������������������������������������������������� 66
Using chunks when analyzing data (without compiling documents)������������������������������������ 69
Caching Results��������������������������������������������������������������������������������������������������������������������� 70
Displaying Data��������������������������������������������������������������������������������������������������������������������� 71
Exercises������������������������������������������������������������������������������������������������������������������������������������� 72
Create an R Markdown Document����������������������������������������������������������������������������������������� 72
Different Output��������������������������������������������������������������������������������������������������������������������� 72
Caching���������������������������������������������������������������������������������������������������������������������������������� 72

Chapter 3: Data Manipulation��������������������������������������������������������������������������������� 73


Data Already in R������������������������������������������������������������������������������������������������������������������������� 73
Quickly Reviewing Data�������������������������������������������������������������������������������������������������������������� 75
Reading Data������������������������������������������������������������������������������������������������������������������������������� 77
Examples of Reading and Formatting Data Sets������������������������������������������������������������������������� 79
Breast Cancer Data set���������������������������������������������������������������������������������������������������������� 79
Boston Housing Data Set������������������������������������������������������������������������������������������������������� 87
The readr Package���������������������������������������������������������������������������������������������������������������� 90

iv
Table of Contents

Manipulating Data with dplyr������������������������������������������������������������������������������������������������������ 92


Some Useful dplyr Functions������������������������������������������������������������������������������������������������� 94
Breast Cancer Data Manipulation���������������������������������������������������������������������������������������� 106
Tidying Data with tidyr��������������������������������������������������������������������������������������������������������� 110
Exercises����������������������������������������������������������������������������������������������������������������������������������� 118
Importing Data��������������������������������������������������������������������������������������������������������������������� 118
Using dplyr�������������������������������������������������������������������������������������������������������������������������� 119
Using tidyr��������������������������������������������������������������������������������������������������������������������������� 119

Chapter 4: Visualizing Data���������������������������������������������������������������������������������� 121


Basic Graphics�������������������������������������������������������������������������������������������������������������������������� 121
The Grammar of Graphics and the ggplot2 Package���������������������������������������������������������������� 128
Using qplot()������������������������������������������������������������������������������������������������������������������������ 129
Using Geometries���������������������������������������������������������������������������������������������������������������� 133
Facets��������������������������������������������������������������������������������������������������������������������������������������� 141
Scaling�������������������������������������������������������������������������������������������������������������������������������������� 145
Themes and Other Graphics Transformations��������������������������������������������������������������������� 151
Figures with Multiple Plots������������������������������������������������������������������������������������������������������� 156
Exercises����������������������������������������������������������������������������������������������������������������������������������� 160

Chapter 5: Working with Large Data Sets������������������������������������������������������������� 161


Subsample Your Data Before You Analyze the Full Data Set����������������������������������������������������� 162
Running Out of Memory During an Analysis����������������������������������������������������������������������������� 164
Too Large to Plot����������������������������������������������������������������������������������������������������������������������� 166
Too Slow to Analyze������������������������������������������������������������������������������������������������������������������ 171
Too Large to Load���������������������������������������������������������������������������������������������������������������������� 173
Exercises����������������������������������������������������������������������������������������������������������������������������������� 177
Subsampling������������������������������������������������������������������������������������������������������������������������ 177
Hex and 2D Density Plots���������������������������������������������������������������������������������������������������� 177

Chapter 6: Supervised Learning��������������������������������������������������������������������������� 179


Machine Learning��������������������������������������������������������������������������������������������������������������������� 179
Supervised Learning����������������������������������������������������������������������������������������������������������������� 180

v
Table of Contents

Regression vs. Classification����������������������������������������������������������������������������������������������� 181


Inference vs. Prediction������������������������������������������������������������������������������������������������������� 182
Specifying Models��������������������������������������������������������������������������������������������������������������������� 183
Linear Regression���������������������������������������������������������������������������������������������������������������� 183
Logistic Regression (Classification, Really)������������������������������������������������������������������������� 189
Model Matrices and Formula����������������������������������������������������������������������������������������������� 194
Validating Models���������������������������������������������������������������������������������������������������������������������� 204
Evaluating Regression Models�������������������������������������������������������������������������������������������� 206
Evaluating Classification Models����������������������������������������������������������������������������������������� 209
Confusion Matrix����������������������������������������������������������������������������������������������������������������� 210
Accuracy������������������������������������������������������������������������������������������������������������������������������ 213
Sensitivity and Specificity��������������������������������������������������������������������������������������������������� 215
Other Measures������������������������������������������������������������������������������������������������������������������� 216
More Than Two Classes������������������������������������������������������������������������������������������������������� 218
Sampling Approaches��������������������������������������������������������������������������������������������������������������� 218
Random Permutations of Your Data������������������������������������������������������������������������������������� 219
Cross-Validation������������������������������������������������������������������������������������������������������������������ 223
Selecting Random Training and Testing Data���������������������������������������������������������������������� 227
Examples of Supervised Learning Packages���������������������������������������������������������������������������� 229
Decision Trees��������������������������������������������������������������������������������������������������������������������� 230
Random Forests������������������������������������������������������������������������������������������������������������������ 232
Neural Networks������������������������������������������������������������������������������������������������������������������ 233
Support Vector Machines���������������������������������������������������������������������������������������������������� 235
Naive Bayes������������������������������������������������������������������������������������������������������������������������������ 235
Exercises����������������������������������������������������������������������������������������������������������������������������������� 236
Fitting Polynomials�������������������������������������������������������������������������������������������������������������� 236
Evaluating Different Classification Measures���������������������������������������������������������������������� 236
Breast Cancer Classification������������������������������������������������������������������������������������������������ 237
Leave-One-Out Cross-Validation (Slightly More Difficult)���������������������������������������������������� 237
Decision Trees��������������������������������������������������������������������������������������������������������������������� 237
Random Forests������������������������������������������������������������������������������������������������������������������ 237

vi
Table of Contents

Neural Networks������������������������������������������������������������������������������������������������������������������ 238


Support Vector Machines���������������������������������������������������������������������������������������������������� 238
Compare Classification Algorithms�������������������������������������������������������������������������������������� 238

Chapter 7: Unsupervised Learning����������������������������������������������������������������������� 239


Dimensionality Reduction��������������������������������������������������������������������������������������������������������� 239
Principal Component Analysis��������������������������������������������������������������������������������������������� 240
Multidimensional Scaling���������������������������������������������������������������������������������������������������� 250
Clustering���������������������������������������������������������������������������������������������������������������������������������� 255
k-means Clustering������������������������������������������������������������������������������������������������������������� 255
Hierarchical Clustering�������������������������������������������������������������������������������������������������������� 263
Association Rules���������������������������������������������������������������������������������������������������������������������� 267
Exercises����������������������������������������������������������������������������������������������������������������������������������� 273
Dealing with Missing Data in the HouseVotes84 Data��������������������������������������������������������� 273
k-means������������������������������������������������������������������������������������������������������������������������������ 274

Chapter 8: Project 1: Hitting the Bottle����������������������������������������������������������������� 275


Importing Data�������������������������������������������������������������������������������������������������������������������������� 275
Exploring the Data��������������������������������������������������������������������������������������������������������������������� 276
Distribution of Quality Scores���������������������������������������������������������������������������������������������� 276
Is This Wine Red or White?�������������������������������������������������������������������������������������������������� 277
Fitting Models��������������������������������������������������������������������������������������������������������������������������� 282
Exercises����������������������������������������������������������������������������������������������������������������������������������� 285
Exploring Other Formulas���������������������������������������������������������������������������������������������������� 285
Exploring Different Models�������������������������������������������������������������������������������������������������� 285
Analyzing Your Own Data Set���������������������������������������������������������������������������������������������� 285

Chapter 9: Deeper into R Programming���������������������������������������������������������������� 287


Expressions������������������������������������������������������������������������������������������������������������������������������� 287
Arithmetic Expressions�������������������������������������������������������������������������������������������������������� 287
Boolean Expressions����������������������������������������������������������������������������������������������������������� 289
Basic Data Types����������������������������������������������������������������������������������������������������������������������� 290

vii
Table of Contents

Numeric������������������������������������������������������������������������������������������������������������������������������� 291
Integer��������������������������������������������������������������������������������������������������������������������������������� 291
Complex������������������������������������������������������������������������������������������������������������������������������� 292
Logical��������������������������������������������������������������������������������������������������������������������������������� 292
Character����������������������������������������������������������������������������������������������������������������������������� 293
Data Structures������������������������������������������������������������������������������������������������������������������������� 294
Vectors��������������������������������������������������������������������������������������������������������������������������������� 294
Matrix���������������������������������������������������������������������������������������������������������������������������������� 296
Lists������������������������������������������������������������������������������������������������������������������������������������� 298
Indexing������������������������������������������������������������������������������������������������������������������������������� 300
Named Values���������������������������������������������������������������������������������������������������������������������� 304
Factors��������������������������������������������������������������������������������������������������������������������������������� 305
Formulas����������������������������������������������������������������������������������������������������������������������������� 305
Control Structures��������������������������������������������������������������������������������������������������������������������� 306
Selection Statements���������������������������������������������������������������������������������������������������������� 306
Loops����������������������������������������������������������������������������������������������������������������������������������� 307
Functions���������������������������������������������������������������������������������������������������������������������������������� 311
Named Arguments��������������������������������������������������������������������������������������������������������������� 312
Default Parameters�������������������������������������������������������������������������������������������������������������� 313
Return Values���������������������������������������������������������������������������������������������������������������������� 314
Lazy Evaluation�������������������������������������������������������������������������������������������������������������������� 315
Scoping�������������������������������������������������������������������������������������������������������������������������������� 317
Function Names Are Different from Variable Names����������������������������������������������������������� 322
Recursive Functions������������������������������������������������������������������������������������������������������������������ 322
Exercises����������������������������������������������������������������������������������������������������������������������������������� 325
Fibonacci Numbers�������������������������������������������������������������������������������������������������������������� 325
Outer Product���������������������������������������������������������������������������������������������������������������������� 325
Linear Time Merge��������������������������������������������������������������������������������������������������������������� 325
Binary Search���������������������������������������������������������������������������������������������������������������������� 326
More Sorting������������������������������������������������������������������������������������������������������������������������ 326
Selecting the k Smallest Element���������������������������������������������������������������������������������������� 327

viii
Table of Contents

Chapter 10: Working with Vectors and Lists�������������������������������������������������������� 329


Working with Vectors and Vectorizing Functions���������������������������������������������������������������������� 329
ifelse������������������������������������������������������������������������������������������������������������������������������������ 332
Vectorizing Functions���������������������������������������������������������������������������������������������������������� 332
The apply Family����������������������������������������������������������������������������������������������������������������� 335
apply������������������������������������������������������������������������������������������������������������������������������������ 336
Nothing Good, It Would Seem���������������������������������������������������������������������������������������������� 339
lapply����������������������������������������������������������������������������������������������������������������������������������� 340
sapply and vapply���������������������������������������������������������������������������������������������������������������� 342
Advanced Functions������������������������������������������������������������������������������������������������������������������ 342
Special Names��������������������������������������������������������������������������������������������������������������������� 342
Infix Operators��������������������������������������������������������������������������������������������������������������������� 343
Replacement Functions������������������������������������������������������������������������������������������������������� 344
How Mutable Is Data Anyway?�������������������������������������������������������������������������������������������������� 347
Exercises����������������������������������������������������������������������������������������������������������������������������������� 348
between������������������������������������������������������������������������������������������������������������������������������� 348
rmq�������������������������������������������������������������������������������������������������������������������������������������� 348

Chapter 11: Functional Programming������������������������������������������������������������������ 349


Anonymous Functions��������������������������������������������������������������������������������������������������������������� 349
Higher-Order Functions������������������������������������������������������������������������������������������������������������� 351
Functions Taking Functions As Arguments�������������������������������������������������������������������������� 351
Functions Returning Functions (and Closures)�������������������������������������������������������������������� 352
Filter, Map, and Reduce������������������������������������������������������������������������������������������������������������� 357
Functional Programming with purrr������������������������������������������������������������������������������������������ 360
Functions As Both Input and Output������������������������������������������������������������������������������������������ 363
Ellipsis Parameters…���������������������������������������������������������������������������������������������������������� 368
Exercises����������������������������������������������������������������������������������������������������������������������������������� 370
apply_if�������������������������������������������������������������������������������������������������������������������������������� 370
power���������������������������������������������������������������������������������������������������������������������������������� 370
Row and Column Sums������������������������������������������������������������������������������������������������������� 370
Factorial Again…���������������������������������������������������������������������������������������������������������������� 370

ix
Table of Contents

Function Composition���������������������������������������������������������������������������������������������������������� 371


Implement This Operator����������������������������������������������������������������������������������������������������� 371

Chapter 12: Object-Oriented Programming���������������������������������������������������������� 373


Immutable Objects and Polymorphic Functions������������������������������������������������������������������������ 373
Data Structures������������������������������������������������������������������������������������������������������������������������� 374
Example: Bayesian Linear Model Fitting������������������������������������������������������������������������������ 374
Classes�������������������������������������������������������������������������������������������������������������������������������������� 376
Polymorphic Functions�������������������������������������������������������������������������������������������������������������� 379
Defining Your Own Polymorphic Functions�������������������������������������������������������������������������� 380
Class Hierarchies���������������������������������������������������������������������������������������������������������������������� 382
Specialization As Interface�������������������������������������������������������������������������������������������������� 383
Specialization in Implementations�������������������������������������������������������������������������������������� 384
Exercises����������������������������������������������������������������������������������������������������������������������������������� 388
Shapes��������������������������������������������������������������������������������������������������������������������������������� 388
Polynomials������������������������������������������������������������������������������������������������������������������������� 389

Chapter 13: Building an R Package���������������������������������������������������������������������� 391


Creating an R Package�������������������������������������������������������������������������������������������������������������� 391
Package Names������������������������������������������������������������������������������������������������������������������� 392
The Structure of an R Package�������������������������������������������������������������������������������������������� 392
.Rbuildignore����������������������������������������������������������������������������������������������������������������������� 393
Description�������������������������������������������������������������������������������������������������������������������������������� 393
Title�������������������������������������������������������������������������������������������������������������������������������������� 394
Version��������������������������������������������������������������������������������������������������������������������������������� 394
Description�������������������������������������������������������������������������������������������������������������������������� 395
Author and Maintainer��������������������������������������������������������������������������������������������������������� 395
License�������������������������������������������������������������������������������������������������������������������������������� 396
Type, Date, LazyData������������������������������������������������������������������������������������������������������������ 396
URL and BugReports������������������������������������������������������������������������������������������������������������ 396
Dependencies���������������������������������������������������������������������������������������������������������������������� 396
Using an Imported Package������������������������������������������������������������������������������������������������� 397
Using a Suggested Package������������������������������������������������������������������������������������������������ 398
x
Table of Contents

NAMESPACE������������������������������������������������������������������������������������������������������������������������������ 399
R/ and man/������������������������������������������������������������������������������������������������������������������������� 400
Checking the Package�������������������������������������������������������������������������������������������������������������� 400
Roxygen������������������������������������������������������������������������������������������������������������������������������������ 401
Documenting Functions������������������������������������������������������������������������������������������������������� 401
Import and Export���������������������������������������������������������������������������������������������������������������� 402
Package Scope vs. Global Scope����������������������������������������������������������������������������������������� 404
Internal Functions���������������������������������������������������������������������������������������������������������������� 404
File Load Order�������������������������������������������������������������������������������������������������������������������� 404
Adding Data to Your Package���������������������������������������������������������������������������������������������������� 405
NULL������������������������������������������������������������������������������������������������������������������������������������ 406
Building an R Package�������������������������������������������������������������������������������������������������������������� 407
Exercises����������������������������������������������������������������������������������������������������������������������������������� 407

Chapter 14: Testing and Package Checking��������������������������������������������������������� 409


Unit Testing������������������������������������������������������������������������������������������������������������������������������� 409
Automating Testing�������������������������������������������������������������������������������������������������������������� 411
Using testthat���������������������������������������������������������������������������������������������������������������������������� 412
Writing Good Tests��������������������������������������������������������������������������������������������������������������� 414
Using Random Numbers in Tests����������������������������������������������������������������������������������������� 415
Testing Random Results������������������������������������������������������������������������������������������������������ 416
Checking a Package for Consistency���������������������������������������������������������������������������������������� 417
Exercise������������������������������������������������������������������������������������������������������������������������������������ 417

Chapter 15: Version Control���������������������������������������������������������������������������������� 419


Version Control and Repositories���������������������������������������������������������������������������������������������� 419
Using Git in RStudio������������������������������������������������������������������������������������������������������������������ 420
Installing Git������������������������������������������������������������������������������������������������������������������������� 421
Making Changes to Files, Staging Files, and Committing Changes������������������������������������� 422
Adding Git to an Existing Project����������������������������������������������������������������������������������������� 424
Bare Repositories and Cloning Repositories����������������������������������������������������������������������� 425
Pushing Local Changes and Fetching and Pulling Remote Changes����������������������������������� 426
Handling Conflicts��������������������������������������������������������������������������������������������������������������� 428
xi
Table of Contents

Working with Branches������������������������������������������������������������������������������������������������������� 429


Typical Workflows Involve Lots of Branches������������������������������������������������������������������������ 432
Pushing Branches to the Global Repository������������������������������������������������������������������������ 433
GitHub��������������������������������������������������������������������������������������������������������������������������������������� 434
Moving an Existing Repository to GitHub���������������������������������������������������������������������������� 436
Installing Packages from GitHub����������������������������������������������������������������������������������������� 437
Collaborating on GitHub������������������������������������������������������������������������������������������������������������ 437
Pull Requests����������������������������������������������������������������������������������������������������������������������� 438
Forking Repositories Instead of Cloning������������������������������������������������������������������������������ 438
Exercises����������������������������������������������������������������������������������������������������������������������������������� 440

Chapter 16: Profiling and Optimizing������������������������������������������������������������������� 441


Profiling������������������������������������������������������������������������������������������������������������������������������������� 441
A Graph-Flow Algorithm������������������������������������������������������������������������������������������������������ 442
Speeding Up Your Code������������������������������������������������������������������������������������������������������������� 456
Parallel Execution��������������������������������������������������������������������������������������������������������������������� 461
Switching to C++���������������������������������������������������������������������������������������������������������������������� 466
Exercises����������������������������������������������������������������������������������������������������������������������������������� 469

Chapter 17: Project 2: Bayesian Linear Regression���������������������������������������������� 471


Bayesian Linear Regression������������������������������������������������������������������������������������������������������ 471
Exercises: Priors and Posteriors������������������������������������������������������������������������������������������ 473
Predicting Target Variables for New Predictor Values���������������������������������������������������������� 476
Formulas and Their Model Matrix��������������������������������������������������������������������������������������������� 478
Working with Model Matrices in R�������������������������������������������������������������������������������������� 480
Exercises����������������������������������������������������������������������������������������������������������������������������� 485
Model Matrices Without Response Variables����������������������������������������������������������������������� 485
Exercises����������������������������������������������������������������������������������������������������������������������������� 487
Interface to a blm Class������������������������������������������������������������������������������������������������������������ 487
Constructor�������������������������������������������������������������������������������������������������������������������������� 488
Updating Distributions: An Example Interface��������������������������������������������������������������������� 489
Designing Your blm Class���������������������������������������������������������������������������������������������������� 494
Model Methods�������������������������������������������������������������������������������������������������������������������� 494
xii
Table of Contents

Building an R Package for blm������������������������������������������������������������������������������������������������� 497


Deciding on the Package Interface�������������������������������������������������������������������������������������� 497
Organization of Source Files������������������������������������������������������������������������������������������������ 498
Document Your Package Interface Well������������������������������������������������������������������������������� 498
Adding README and NEWS Files to Your Package�������������������������������������������������������������� 499
Testing�������������������������������������������������������������������������������������������������������������������������������������� 500
GitHub��������������������������������������������������������������������������������������������������������������������������������������� 500

Conclusions���������������������������������������������������������������������������������������������������������� 501
Data Science����������������������������������������������������������������������������������������������������������������������������� 501
Machine Learning��������������������������������������������������������������������������������������������������������������������� 501
Data Analysis���������������������������������������������������������������������������������������������������������������������������� 502
R Programming������������������������������������������������������������������������������������������������������������������������� 502
The End������������������������������������������������������������������������������������������������������������������������������������� 503

Index��������������������������������������������������������������������������������������������������������������������� 505

xiii
About the Author
Thomas Mailund is an associate professor in bioinformatics at Aarhus University,
Denmark. His background is in math and computer science, but for the last decade, his
main focus has been on genetics and evolutionary studies, particularly comparative
genomics, speciation, and gene flow between emerging species.

xv
About the Technical Reviewer
Jon Westfall is an associate professor of psychology at Delta
State University. He has authored Set Up and Manage Your
Virtual Private Server, Practical R 4, Beginning Android
Web Apps Development, Windows Phone 7 Made Simple,
and several works of fiction including One in the Same,
Mandate, and Franklin: The Ghost Who Successfully Evicted
Hipsters from His Home and Other Short Stories. He lives in
Cleveland, Mississippi, with his wife.

xvii
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER XIV.
Mrs. Fielding staggered to her feet. She stood looking at Flower with
a tortured face.
"Ah! even a mother's instinct has played me false in this. I thought, I
hoped—" she cried out, passionately, then checked herself, and the
agony of her face changed to wrath and fury.
Advancing toward the shrinking, terrified girl, she exclaimed,
hoarsely, angrily:
"So I have wasted my love on you—you, my rival's child! She had his
heart and you his face—my false husband's beautiful face! Are you
not afraid that I will strike you dead for having deceived me so
bitterly!"
"I, mamma, I deceive you? Ah, no, no, for I did not know!" Flower
moaned, faintly, and shrinking in terror from the wild-eyed woman
towering over her so fiercely, and who cried out, scornfully, now:
"No, that is true, you did not know what a heritage of shame was
yours, what a cloud hung over your birth—and yet you proved
yourself true to your inherited nature, to your mother's false, light
instincts. You rushed into your sin, into shame—"
"Hush!" Flower cried, indignantly, her face dyed red with shame. She
stood upright, and holding to the arms of the chair to steady her
trembling form, said, eagerly: "I am Laurie Meredith's wife!"
"Ha! ha!" laughed Jewel, with scornful incredulity.
"Ha! ha!" echoed Mrs. Fielding, and there was a sound in her voice
that was terrible to hear—the tones of incipient madness.
There was madness in her eyes, too, so horribly they glittered as she
sprung toward Flower, and all in an instant buried her working white
fingers in the girl's long tresses.
"Daisy Forrest, I shall kill you!" she screamed, with an awful, blood-
curdling laugh; and dragging her victim down upon her knees, she
tried to clasp her fingers around the fair white throat of her hated
rival's child, and strangle her life out.
In another moment murder would have been done, but fortunately
the monomaniac was thwarted in her deadly purpose, for her
maddened shriek had brought the servants rushing to the scene,
and Jewel, who had been silently gloating over the terrible deed,
realized that her plans would be thwarted if this went further, and
her crazed mother murdered poor Flower for her unconscious
transgression.
So with her own white, jeweled hands she assisted the servants in
their efforts to drag Mrs. Fielding away from her victim, succeeding
only just in time, for Flower was discovered unconscious upon the
floor, and some time elapsed before she even breathed again, so
terrible had been the onslaught of her enemy.
But Mrs. Fielding was for the time a raving mad woman. She had to
be bound and locked into a chamber alone while the man-servant
ran all the way to town to bring a physician.
The remaining servants crowded around Jewel and begged to hear
what had been the cause of the strange scene they had witnessed.
She explained satisfactorily to all, when she replied, angrily:
"My sister had gone astray and disgraced us, and when mamma
found it out quite suddenly just now she went mad with horror, and
would have slain her if your timely entrance had not prevented her
rash deed."
Then she sent them all out, and sat down in the parlor to watch
Flower, who still lay on the floor breathing faintly, but in such a weak
and dazed condition that she realized nothing of what had happened
or of what was going on around her, still less of the baleful black
eyes that watched her so malevolently, as Jewel said to herself:
"My mother is crazed, and the task of punishing this hated girl has
fallen from her hands to mine. Let me think over all the most
horrible things I have ever heard of, and decide what I can do to
make her suffer the longest and worst in return for the torments I
have borne since she took my lover from me. Oh, I hate her as
bitterly as my mother hated her mother, and I swear I will have
vengeance for my wrongs!"
And those beautiful, evilly splendid black eyes, as they floated over
poor Flower's silent, unconscious form, looked baleful enough for
their very glances to kill.
CHAPTER XV.
Presently the house-maid put her head in at the door, giving Jewel a
violent start.
"Has the doctor come?" she asked.
"No, miss; but me and the cook thinks we had better carry Miss
Flower upstairs and put her to bed," Tibbie replied, with a
compassionate look at the silent form upon the floor.
Jewel frowned and considered a moment, then gave her assent to
the plan.
Then she added:
"When you come down, you had better lock the door, as she might
try to run away. In fact, she was about to do so this evening, but
mamma prevented her. Although she has proved so bad, and
disgraced the family, we intend to keep her at home and take care of
her."
The kind-hearted Tibbie murmured an approval of this kindness, and
with the cook's assistance, soon had Flower undressed and placed in
bed. Then seeing that she was still in a dazed and half-unconscious
condition, and either unable or disinclined to speak, they shaded the
lamp and withdrew, locking the door as ordered, and giving the key
to the triumphant Jewel.
In the meantime the physician arrived and pronounced Mrs. Fielding
temporarily insane.
"I will leave soothing medicine for her, and I will send two nurses
from town, for she will have violent paroxysms, and it will take at
least two people to restrain her from doing harm to herself or
others," he said, and took leave, wondering at the coolness and self-
command of this beautiful young girl, whose bright eyes were not
dimmed by a tear, as he explained to her the terrible condition of her
mother.
He would have been more surprised if he could have read the
thoughts of that vindictive heart.
"So she is really insane!" she said to herself. "I am glad of that.
There will be no one now to interfere with my plans for Flower. It is
true she would have killed her if she had been let alone, but I do not
want her to die yet. I want her to live and wither under the shame
of her birth, and under the agony of her desertion by Laurie
Meredith. I will torment her as much as I can until the child is born,
then I hope she will die, and the brat, too, so that when Laurie
Meredith comes back I can have the pleasure of telling him that they
are dead, and showing him their graves."
Her passionate, jealous love for handsome Laurie Meredith was
mixed with hate now, and she delighted in stabbing his heart as he
had stabbed hers when he turned from her dark, dazzling charms to
her sister's fair, angelic beauty.
Going to her room, she unlocked her trunk and took out some
papers, over which she gloated with fierce delight.
"Although I long for power and gold, millions could not buy these
from me, for my sweet revenge is better than gold! Ah, how cleverly
I parted them! They outwitted me when they managed to steal away
and get married, but I've kept them apart ever since, I've made
them pay dearly for their temerity!" she cried, exultantly.
The papers she held were the half-burned diary of Charley Fielding,
the marriage-certificate and card she had stolen from Flower's desk,
and the note she had intercepted on its way to Flower, together with
several letters that Laurie Meredith had written to his wife since his
departure, and which, through Jewel's clever plotting, she had failed
to receive.
She pressed them in her hands, gloating over them with more
delight than a ball-room belle would have done over the most
priceless diamonds, for they represented the power she thirsted for
so ardently—the power to torment those whom she hated.
She cared nothing for the fact, that in spite of all that had come and
gone, poor, unhappy Flower was her half-sister still. She only knew
that ever since the fatal hour when Laurie Meredith had made choice
between them she had hated the blue-eyed, golden-haired beauty
with a jealous fury that was as pitiless as death.
She thought she was a very clever girl, she had managed everything
so adroitly. In the first place, she had bribed Sam to give her
Flower's letter that night, and to take back a reply from herself. She
had found out from that letter that Flower was Laurie Meredith's
wife, that she was going away with him, and that a telegram had
called him away one day sooner, causing him to write to Flower to
come at once to him, as he must be far on his way north before the
next night, which was set as the time for them to leave.
In that sudden emergency Jewel's keen wits served her well. She
remembered that her handwriting was so similar to her sister's that
few could tell them apart, so she decided upon a bold step. She
wrote to Laurie Meredith in his wife's name, declaring that she had
changed her mind about going with him, that she could not bring
herself to leave her mother and sister, but that she would be his true
and faithful wife, and wait for him until he came back from Germany.
The young husband was most bitterly disappointed, but the telegram
that summoned him to a parent's sick-bed admitted of no delay. He
went without Flower, but he wrote to her very soon from his
Northern home, entreating her to reconsider her determination and
join him there.
Jewel had a fervent admirer in the person of the post-office clerk.
By cleverly playing on his vanity she induced him to let her have
Flower's letters, and each one she answered briefly, by denying
Laurie Meredith's wish and indulging in weak regrets over the haste
with which she had wedded him, lamenting lest her mother should
find out her folly and withhold forgiveness.
So it was that not one of those loving letters, for which Flower would
have given her very life, ever reached her, and Jewel sat here
gloating over their possession, while in the very next room poor little
Flower lay upon her sleepless bed, an image of despair, wondering if
it could be true all that Jewel had told her—that she was a child of
shame, her mother a bad, wicked woman, and her father a sinful
wretch who had broken the hearts of both her mother and Jewel's.
CHAPTER XVI.
If any one had told Jewel Fielding that she had the heart of a
murderess, she would have indignantly denied the accusation—she
would have been frightened and angry at the very idea—yet it was
nothing less than a slow murder that she began the next day.
In the first place, she gave out to the servants that Flower was so
ashamed and remorseful over her sin that she wished to keep her
own room all the time, and desired to see no human face save that
of her sister; so, lest any one should enter, she meant to keep her
door locked all the while. Jewel declared that she desired to humor
her sister's whim, and would carry her meals upstairs daily with her
own hands.
Having thus paved the way to carrying the key of Flower's room in
her pocket, and to starving her without being found out, the
vindictive girl went into Flower's room, and surprised her at the task
of plaiting a rope out of her bed-clothes by which to escape through
her window, which was in the second story.
Jewel produced from under her dainty apron a hammer and some
nails, with which she proceeded to nail down the window-sashes
securely.
At first Flower tried to prevent her by holding back her arm; but
Jewel shook her loose with a fierce strength, and, turning, menaced
the white temple with the lifted hammer.
"Dare to hold back my arm again, and I will kill you!" she hissed,
with vindictive rage, while the murderous fire that flashed from her
black eyes appalled Flower's very soul.
With a moan she fell upon the bed, and lay watching Jewel until she
had finished securing the windows.
Then she rose up in bed, and brushing back the wealth of sunny
curls from her aching brow, began to plead pathetically for her
freedom.
"I wish to go away, and you have no right to forbid me," she said at
last, bitterly, resenting the scorn of the other.
Jewel laughed mockingly.
"No right!" she exclaimed. "Ha! ha! Then I will take the right! You
stole Laurie Meredith from me, and now you are going to be
punished for your treachery."
"Punished! As if I had not already suffered enough!" the wretched
girl cried, in pathetic despair.
"You are going to suffer more yet," hissed Jewel, with blazing eyes.
"I am going to keep you locked up here, and allow you nothing but
bread and water, and not enough of that. You shall wish yourself
dead every day, but there will be just enough bread to keep you
alive in misery—no more!"
Flower's beautiful face turned ghastly, her blue eyes stared at the
cruel girl with a dazed, horrified look.
"Oh, Jewel, I wish I were dead already! I have nothing left to live for
now!" she exclaimed. "But, still, would it not be too horrible to
starve me now? It—it would be a double murder, for—for—oh,
Jewel, did you not forget the child?"
The piteous pleading for her unborn child only angered Jewel the
more, and with scornful, cutting phrases she taunted her with her
disgrace and misery, and reiterated her intention of torturing her in
return for what she called her treachery.
When she left the room Flower believed that her fate was sealed.
Jewel had revealed her real self so plainly that she could hope for no
mercy and no pity.
She wept bitterly for the little unborn child, that through Jewel's
cruelty would have to die. She had hoped somehow that she would
find Laurie before it was born, and that all would yet be well. For
surely, surely, he had not deserted her. It was only that some
unfathomable treachery on Jewel's part had kept them asunder. She
did not want to believe him false.
"But I must die, all the same, and he will never know how I suffered
through my love for him," she sighed, day after day, as her strength
waned under the scanty diet of dry bread and stale water served to
her daily by Jewel, with cruel taunts and scornful looks for sauce.
She grew weaker and weaker, great hollows came into her pale
cheeks, her blue eyes looked larger than ever with the purple
shadows beneath them, while the one longing cry of her heart was
always for freedom, freedom, from this dreadful house, through
whose whole extent the maniacal shrieks of the mad Mrs. Fielding
echoed night and day.
After weeks of this terrible life there came a day when the horror-
haunted house became unnaturally still and quiet. Mrs. Fielding had
been removed to an insane asylum, and her wild cries no longer
echoed on the shuddering air.
Jewel knew that at the next meeting of the county court a guardian
must be appointed for herself and her sister until her mother's
recovery, and she resolved to finish her awful work before any
prying, perhaps suspicious stranger should come into the house.
More than eight months had elapsed since Laurie Meredith had gone
away, and Jewel knew that the time of Flower's trouble was near at
hand.
She had been holding back one terrible thing for a coup d'état at the
last, and she decided now that the fitting moment had arrived in
which to startle Flower into a slightly premature illness and thus
make sure of her death at once.
It was a fiend's plan, a fiend's wish, but Jewel never faltered in her
deadly purpose. Her evil passions drove her on to the commission of
a deed that, call it by what specious name she chose in her own
mind, would be no less than murder.
So she went into Flower's room one night carrying a lighted lamp in
one hand and a newspaper in the other.
In this long, weary month she had never permitted Flower the use of
a lamp at night, thinking that the long, interminable hours of
darkness would add to her torture, as indeed they had done most
effectually.
So the poor girl started up from her bed in alarm, dazed by the
brilliant light of the lamp, and filled with a wild hope that Jewel was
about to relent toward her, she exclaimed, wildly:
"Ah, sister, you bring me a light. You begin to relent. Blessings on
you, dear Jewel! Now, give me food, too, I am so hungry, so thirsty,
and the air of this closed room stifles me! Open the window and let
the sweet air of spring come in! Then bring me food, food, for I am
starving."
Jewel set down the lamp and took from her pocket a beautiful, red-
cheeked apple.
"I will give you just one bite of this if you will return it to me when
you have taken it," she said, with a mocking laugh. And Flower
promised; but when she had taken as large a bite as her pearly
teeth could compass, her horrible hunger and thirst overcame her,
and she clung wildly to the luscious fruit, begging, pleading for it,
until Jewel forced it from her after a short, sharp struggle, and
restored it to her pocket.
"You are not half as hungry and thirsty for that delicious fruit as I
was hungry and thirsty for Laurie Meredith's love!" she said, bitterly.
"I loved him with my whole heart, yet you took him from me, and
now you shall suffer for it! Ah, no, Madame Flower, I have not
relented! I am not going to give you any food, nor water, nor fresh
air; and if I brought a light it was only that I might gloat over your
agony when you read something that I came upon accidentally this
evening, and which will add the last drop of bitterness to the
overflowing cup of your misery."
She laughed exultantly, and Flower shrunk back, with her hand
before her eyes to shut out the blaze of those angry eyes that
burned upon her face.
"I—I had better not read it, then. I have borne all that I can bear
already," she moaned, faintly.
Jewel struck the wasted little white hand rudely away from before
Flower's eyes, and said, sharply:
"I thought you would be glad to read this paragraph about Laurie
Meredith. It explains his seeming desertion and falsity to you."
At these words a wild, strangling gasp came from Flower's lips, and
she caught eagerly at the paper, while Jewel, with a plump, jeweled
finger, pointed out a paragraph marked heavily with black ink.
Laurie Meredith's own hand had marked it, and he had sent the
paper to Flower many months ago, little dreaming what a terrible
purpose it was destined to serve.
It was a Boston newspaper, and the paragraph was simply this:

"As we go to press we have just heard that our esteemed


townsman, Laurie Meredith, died very suddenly last night."
CHAPTER XVII.
Jewel watched her victim eagerly, breathlessly.
She saw the hue of death overspread the lovely, wasted face, the
blue eyes, already dim through the tears that had washed their
brightness away, dilate in wonder and horror. Oh, how sweet it was
to see that look of mortal agony on the face that Laurie Meredith
had loved to kiss! Jewel said to herself that in the months since he
went away, she had made her successful rival shed a thousand tears
for each and every kiss he had pressed on those lovely, rosebud lips.
But her thirst for revenge was not sated yet. There was yet another
sweet draught waiting for her lips in the near future.
All this time she had been keeping up the correspondence with
Laurie Meredith, in order to prevent him from coming back South to
see Flower. But she said to herself that when the girl was dead she
would cease writing. He would become uneasy then, and the
chances were that he would soon come back. Then she, the girl he
had slighted, she would show him his wife's grave.
What sweetness there was in this thought for Jewel! She gloated
over it often, and thought that surely no girl had ever had a more
perfect revenge for slighted love than she had taken.
Her thoughts went further yet sometimes.
She had taken the greatest pains to hide her enmity to her sister.
There was no one who could say she had been unkind to Flower;
Laurie Meredith should never know otherwise, and from her reputed
tenderness to his dead wife, and her sweet sympathy with himself,
should spring up another flower of love that should bloom for her
alone. Some day she would be his wife, and the secret of all she had
done to part him from Flower should be buried forever in the poor
girl's grave.
She could see nothing to mar the success of her far-reaching plans.
With Flower dead, and her mother the inmate of an insane asylum,
she would be her own mistress, with quite a handsome fortune at
her command, and she intended to make capital of her liberty and
her position.
True, the physician had said that her mother's reason would most
probably return within a few months, but Jewel had made up her
mind that the foolish, half-mad creature should never leave the
asylum again. For so young a girl she was wonderfully clever and
headstrong, and she was fully determined to have her own way.
With all these thoughts in her mind she stood watching Flower
reading those few brief lines, and she was not surprised when with
one low cry of anguish the unhappy girl let the paper slip from her
nerveless hands, and fell back in a heavy swoon upon the pillow.
Jewel laughed as she looked at the still, white face, and moved
toward the door.
"I will walk up and down the hall and get some fresh air while she
recovers at her leisure," she said, aloud; and she stepped outside
and went to the hall window, which was open, letting in a flood of
balmy air, sweet with the heavy scent of the early blooming lilacs.
She leaned her elbows on the window-ledge and looked out at the
beautiful tides of the sea rolling into the shore with a hollow
murmur, while the moon's bright rays made silver paths across the
restless waves. But Jewel shivered, and exclaimed:
"But for him I should be dead, drowned in that cruel sea! He saved
my life, and I dedicated it to him. I made him the king of my heart!
Oh, why did she come between us? If I am wicked it is all her fault.
She drove me mad."
Absorbed in her angry self-excuses, it was almost half an hour
before she returned to the room she had left, and then she found
Flower lying just as she had left her, cold and apparently rigid, with
no movement at her heart.
Jewel could not repress a low cry of horror. She was only a girl, and
wicked as she was, she was frightened when she saw that life had
fled from the body of her she had so cruelly tortured.
She felt Flower's hands and they were deadly cold; she shouted in
her ear and she did not respond. Then running into her own room,
she brought out a pitcher of fresh water, which she poured over
Flower's head and face in a perfect deluge.
But not a sigh, not the movement of an eyelash rewarded her efforts
at resuscitation. With something like awe she began to realize that
her work was completed sooner than she had expected. Flower was
already dead.
She flung wide the door and began to scream loudly for the
servants.
Her voice rang wildly down the long halls and dim stairways,
returning to her in ghostly echoes; but no one answered to her wild
calls. The servants had stolen away to a merry-making in the town.
Something of the truth began to dawn upon her mind when she had
shouted herself hoarse.
"They are either stolen away or fast asleep," she muttered, and
rushed down-stairs to their quarters in the yard.
The cottage door was locked, and Jewel pounded lustily without
receiving any reply. Looking at the windows, she saw that they were
closed and dark.
"The wretches! how dared they go away and leave me with that
dead girl?" she muttered, ignoring the fact that Flower had been
alive a little while ago. The deep, hoarse baying of the watch-dog,
aroused in his distant kennel by the noise she had made, caused her
to start and crouch down shivering on the back door-step.
"I shall stay here till they come. I—I—can not watch by that dead
girl alone!" she muttered, with a superstitious horror of death.
But in the meantime the copious shower of water she had poured
over Flower had taken effect.
While Jewel was battering at the door of the servants' quarters
Flower had revived and found the door wide open, and such a
draught of sweet, pure air rushing into the room that it seemed to
endow her with new life.
She dragged herself wearily into the hall and heard Jewel's angry
voice berating the servants down in the yard. She instantly
suspected the true state of the case.
"She thinks I am dead, and wishes to arouse the servants. I must try
to escape before she returns," she moaned, faintly, and made her
way down-stairs like a spirit, slipped the bolt of the front door, and
let herself out, friendless and homeless, into the dark.
CHAPTER XVIII.
Nothing but her terrible fear of being recaptured and imprisoned by
her relentless foe could have given poor Flower the strength to get
away from the house that, after being her home so long, had
become a place "by horror haunted."
But with a brave heart, although her footsteps faltered often, she set
off from the spot, traveling as fast as her reduced strength would
permit, and taking the high-road that led away from the town and
toward the deserted cabin of the dead nurse.
It was instinct rather than intention that led her to the place; for she
had no thought of stopping there, but only of putting miles of space
between herself and Jewel, of whom she had now become horribly
afraid.
But, poor girl, starved as she had been, and in her delicate condition
of health, she had not strength enough to carry her far. Besides, she
had been tormented for several days by peculiar pains, which now
became so acute as to materially interfere with her progress.
"I can not go any further. I must lie down here in the road and die,"
she moaned, lifting her tear-wet eyes to the moonlit sky, as if
beseeching the pitying Lord to have mercy on His suffering child.
In a minute more the white-paled fence and dark grove of trees
surrounding the cabin came into view.
The sight recalled old Maria to Flower's mind, and she sighed
plaintively:
"Ah, mammy, dear, I wish you were alive yet; then I should have at
least one friend in my misery."
She stopped and leaned on the old gate. All was dark and silent, and
the long branches of the trees threw fantastic shadows on the
ground that at any other time would have awed the sensitive girl;
but she was oblivious now to everything but her pain, her weariness,
and her cruel hunger and thirst.
"There is no one here. I will go into the house and lie down on the
pretty white company-bed that mammy always kept so nice, and I
will die there. Jewel will never think of looking for me here. She
knew that I was afraid of ghosts," she murmured, as she unlatched
the gate and dragged herself up the graveled walk to the door.
She pulled the latch and found that it was not locked. There was
nothing to prevent her entering, so she groped her way in, and,
shivering and moaning, crossed the floor to the tiny room which
Maria had always kept sacred to hospitality. She fell heavily across
the little white bed, and lay there thinking desolately that death
could not be far away.
Ah, how grateful the clean, soft feather bed felt to Flower's weary,
aching limbs! She thought that if only those keen, sickening pains
would cease she could fall asleep and die thus, perhaps, in a
pleasant stupor; but the agony only grew greater, and a sudden
realization of truth forced a groan of fear from her lips.
Her travail was coming upon her, and the girl fainted outright, and
lay for some moments wrapped in a blissful unconsciousness.

The night grew older, the moon rode high in the heavens, and the
stillness of the midnight hour was broken by the shrill whistle of a
steamer that touched at the wharf a mile below, remained only long
enough to throw out a plank and permit the landing of two
passengers and their baggage, then went on its way majestically.
A newly married widower was bringing home a bride, no less a
personage than Sam, the good-looking mulatto ne'er-do-well. As he
had married from mercenary motives the first time, his second
match was for love alone, and Maria's successor was a colored lady
of as bright a type as himself, young and sprightly, and good-
looking.
She rejoiced in the patronymic of Pocahontas, which was shortened
by general consent of herself and friends to "Poky."
Sam made arrangements for getting his bride's baggage brought up
in the morning, and tucking Poky's hand under his arm, set forth to
tramp the distance that lay between the steamboat wharf and the
humble cabin.

The girl who had lain in the darkness all night, racked by cruel pains,
and praying for death, gave a quick start and held her breath in fear.
She heard loud voices and footsteps in the outer room, and
foreboded that Jewel had tracked her here.
"Oh, Heaven! and I had thought to die alone and in peace,
undisturbed by her jealous, mocking eyes!" she sighed to herself,
despairingly.
She flung herself desperately out of the bed down upon the floor,
crawled under the white valance that hung all around the old-
fashioned bed, and lay there holding her breath in terror, hoping that
she would not be discovered. One hope alone was left her—to die
before those angry eyes of her jealous half-sister shone upon her
again.
In the meantime Sam had lighted a candle, and his wife had helped
herself to a chair, while she gazed around with a critical eye at the
appointments of the room.
It was well furnished indeed, for old Maria had been as thrifty as
Sam was shiftless, and Poky said presently that "arter she had tidied
up ter-morror it would be a very decent sort of a place."
"So I told yer, my lub," replied Sam, affectionately, and he gave the
brown beauty an energetic kiss. Then he said, persuasively, "Poky,
'sposen yer light a fire and let us have a cup of coffee before we go
to bed."
Poky assented good-naturedly, and very soon a fire was crackling in
the little kitchen stove, and the odor of coffee and broiling ham
pervaded the air. Then Poky took from the capacious basket she had
brought on her arm a loaf of bread and a roll of butter, and
proceeded to set the little table for her lord's repast.
It was just as she had finished her thrifty preparations, and invited
Sam to "draw up his cheer," that he gave a startled little cry, and
looked over his shoulder apprehensively:
"Sam!"
"Poky!"
"What's de matter, nigger, lookin' over yo' shoulder like you see
sumfin'? Don't yer go 'magining now dat ole 'oman is ha'ntin' de
house!"
He came closer to his wife and whispered, tremulously:
"Hush, honey; Maria did say as how if de dead could come back she
would, and—and—I heard somefin' sartain—oh, Lord!"
He gave a jump, and so did Poky. Both had heard something this
time—the low wails of a new-born infant proceeding from the next
room.
They held their breath for a minute, then Poky, who was rather
strong-minded, said, contemptuously:
"Cats!"
"Do—do—you think so, Poky?" her better half inquired, dropping his
trembling frame into a chair, and more than half convinced that
Maria was haunting him already.
"Sartain!" said Poky, with a sniff. "Lors, Sam, what a coward you be!
It's only some cats as is got in thrue a open window."
She seized a poker and the candle and disappeared into the
"company room," leaving Sam cowering in the dark, and trembling
lest the shade of his departed Maria should pounce upon him at any
minute and shake him for having presumed to give her a successor.
Then a succession of low wails echoed on the air again, and Sam
shook himself together with returning courage.
"'Twas cats after all! I thought so!" he ejaculated, with a feeble
chuckle. "And, Lordy, but Poky's a-makin' 'em git!"
Apparently it took her some time to disperse the feline intruders, for
fifteen minutes elapsed, and she did not return. Then he attempted
to follow her and got the door slammed in his face with the curt yet
good-naturedly delivered sentence:
"You stay whar you is, nigger!"
He slunk back to his chair, and presently she came out with an
important face, and lighting another candle, placed it on the table,
and told him to eat his supper.
"But, Poky—"
"Yes, it's all right, Sam. 'Twasn't no cats, nor no ghosts, only a
beautiful young gal, Sam, runned away from her friends to-night and
hid herself here for her chile to be borned, which it was dat baby we
heerd a-caterwauling."
"Who is she, Poky?" amazedly.
"She said you'd know—some sort o' name like Flower o' de fiel', or
somethin'. But I mus' go back and tend to her and dat baby. Lucky
for her we cum here dis night. Eat your supper without me, Sam,
'cause I'se needed bad in dere."
She disappeared again, and Sam sat there conscience-stricken,
wondering if his sin that night months ago had brought this thing to
pass.
CHAPTER XIX.
He had known that Laurie Meredith and Flower Fielding were lovers,
and he had guessed that Jewel was jealous, when she bribed him so
heavily to give her that important letter and to take back the answer
she sent. In his eagerness to possess himself of her costly bribe he
had not counted the cost of his treachery to the lovers. Now he
began to experience a sneaking consciousness that his guilt had
somehow helped to pave the way to that trouble in yonder.
He wondered what had become of Laurie Meredith, that his pretty
sweetheart had been forced to seek refuge in a deserted negro
cabin in her sore distress and trouble, and so wondering, he fell
asleep in his chair, and remained there until morning, snoring
profoundly, and oblivious to everything.

When he opened his eyes again the broad sunlight of new day was
shining in through the open door, and the song of birds was in the
air.
Poky's trunk had come up, and she was down on her knees
unpacking it, and softly humming a revival song.
Sam's neck, which had been hanging over on his breast, felt as if it
was half broken. He straightened up and gaped so loudly that his
wife turned around and began to rate him soundly for sleeping in his
chair all night, declaring that she had nearly shaken him to pieces
without being able to rouse him, so had retired, leaving him to the
enjoyment of his arm-chair.
Sam did not doubt the assertion, knowing himself to be a very heavy
sleeper. He sat still a little while collecting his wits, and then said:
"Yes, I remember it all now, Poky. I fell to sleep while you was in de
comp'ny with Miss Flower an' de baby."
"Wha-at?" Poky exclaimed, and he repeated his words, only to be
laughed at by his wife, who declared that he must have been
dreaming, as she did not know what he meant in the least.
In vain did Sam go over the startling events of last night to his
laughing wife. She admitted the cats in the company room, but the
rest of the story she laughed to scorn.
"You fell asleep, you foolish nigger, while I was scatterin' dem tom-
cats off dat shed, and you dreamed all de rest," she said; and to
satisfy his doubts she made him go into the spare room, which he
found neat and tidy, as in Maria's time, the white bed smooth and
unrumpled, the two cane-seated chairs standing rigidly against the
wall, the small looking-glass on the white-draped toilet-table
reflecting his crest-fallen face only, as Poky, standing at the open
door, said, jibingly:
"I hope you'se satisfied now! You don't see any babies nor flowers in
dere, does you?"
The puzzled dreamer shuffled out with rather a sheepish air, and
while he did justice to his morning repast, had to endure a running
fire of commentaries on his dream that drove him at last quite out of
the house, to escape being the butt of Poky's merry malice.
Presently, while he was sulkily smoking his pipe in the front yard,
she came out to him in her check apron, with her sleeves rolled up,
and carrying the broom in her brown, shapely hand. With rather a
sober air, she said:
"I declare, Sam, I was so tickled at yer foolish dream that I forgot to
tell yer what the man said as brought my trunk this mornin'."
"Well?" inquired her sulky spouse.
"Why, it 'pears like a young lady 'bout dis neighborhood drowndid
herself las' night."
"Sho!" exclaimed Sam, wonderingly.
"Yes, siree—drowndid herself on account of trubble an' sickness.
What made it all de worse was dat she was de beautifulest gal in de
country, and had a twin sister ekally beautiful, and dat pore thing is
'most crazy 'bout it all," explained Poky, while Sam eagerly
demanded names.
"Sho! I has such a pore mem'ry fer names," Poky began, reflectively;
then she stuttered: "Ju—Ju—Jule—"
"Jewel and Flower!" shouted Sam, and her eyes beamed with
delight.
"Dat's dem! and 'twas de las' one—dat Flower—dat got up outen her
sick-bed and runned away las' night, and Jule she said shorely she
done drowndid herself, 'cause how she done said she would do it de
first chance, and she was so weak she couldn't a' walked no furder
than down to de sea-shore."
"Golly! I mus' go up to de big house and hear 'bout it," Sam
exclaimed, darting toward the gate, while Poky called after him,
jibingly:
"Sam, don't go and tell anybody 'bout yer foolish dreams las' night."
CHAPTER XX.
In the golden days of June, more than three months after the
occurrences of our last chapter, Laurie Meredith returned to the
scene of his love affair, and made his way to the large stone house
where the Fieldings had lived last summer.
He had not had a letter from Flower for the last two months, and
this had brought him to seek her earlier than he otherwise would
have done, for while he had received her letters he had known that
she was well and contented, but her silence filled him with such fear
and discontent that he left Germany, determined to have it out with
the Fieldings and take his bride away.
No rumor of the changes that had taken place since his departure
had reached him. He knew not that Mrs. Fielding was the inmate of
a lunatic asylum, and Flower reported dead. His heart was full of
eager joy as he ran up the steps of the old stone house, expecting in
a very short time to clasp Flower to his yearning heart, and tell her
that she must leave her mother and sister and come with him now,
for he could never be parted from her again.
The parlor window was open, and the notes of the piano,
accompanied by a sweet voice, became audible as he stepped upon
the porch. He stopped a minute to hear, thinking that the musical
voice belonged to Flower. Then he shivered. The voice and the
words were so sad that they struck a chill to his heart.
It was only an old song, heard many a time before, but its plaintive
sadness had never struck him as forcibly as now, when it came
sighing through the lace curtains, and mingling with the summer
breezes:

"Weary of living, so weary,


Longing to lie down and die,
To find for the sad heart and dreary
The end of the pilgrimage nigh;
Weary, so weary of wishing
For a form that has gone from my sight,
For a voice that is hushed to me ever,
For eyes that to me were so bright!

"Weary, so weary of waiting,


Waiting for sympathy sweet,
For something to love and to love me,
The pleasures that are not so fleet;
For a hand to be held on my forehead,
A glimpse of the golden-brown hair,
For a step that to me was sweet music,
And a brow that was noble and fair!'"
Laurie Meredith's heart thrilled in sympathy with the singer. It was
Flower, of course. She was thinking of him, the sweet darling, he
knew. Oh, how glad she would be to see him again!
He opened the front door without ceremony, and entered the hall,
reckless of the risk he ran of meeting Mrs. Fielding and encountering
her angry reproaches. He would stop for nothing now, so anxious
was he to clasp that sweet singer to his heart, and tell her she
should never be "weary of waiting" again, never be parted from him
more.
But the wide hall was silent and deserted. Very softly he opened the
parlor door and stepped across the threshold. Then he saw that the
girl at the piano was the only occupant of the room.
She turned around quickly, and he saw dark eyes instead of blue
ones, dark locks instead of golden curls. Jewel sprung up with a
thrilling cry:
"At last!"
There was unmistakable love and joy in her face and voice. She
made no effort to conceal her glad surprise. Had she not been
waiting for this hour for months, had she not dressed for him daily,
determined that whenever he came he should find her at her best?
And now, conscious of her pretty, rose-tinted mull, that was so
becoming to her dusky beauty, she rejoiced that her efforts were
crowned with success. Her beauty could not fail to make a strong
impression.
But he started back in surprise and disappointment, and forgetting
even the conventional greeting he owed her, exclaimed, eagerly:
"Where is Flower?"
"Flower?" cried Jewel, sharply, with a clouded brow. "Oh, Mr.
Meredith, did you not know? Poor Flower is dead!"
CHAPTER XXI.
Jewel had not meant to break the truth so suddenly to Laurie
Meredith, but his cruel indifference to herself, and his anxiety over
Flower, piqued her into retorting upon him so suddenly. She had her
revenge, for, after gazing at her blankly for one agonized moment,
the young man threw up his arms, staggered wildly, then fell like a
log at her feet.
The terrible revulsion of feeling from love, hope, and expectancy to
despair had almost slain him, and he lay for several minutes quite
unconscious, while Jewel knelt beside him in an agony of fear.
"He is dead, and all my schemes have been in vain," she thought,
wildly; and in her despair she kissed the cold, white face, and laid
her dark head on the pulseless breast of the man she loved so
wildly, and wished that she too were dead and cold.
Presently she lifted her head and laid her cheek against his,
whispering, reproachfully:
"Oh, my love, if you had given your heart to me instead of her, all
this would not have happened. We should have been as happy as
the day is long."
A step in the hall startled her, and she sprung up just as the door
opened, and her companion, an elderly widow lady, entered the
parlor.
"Oh, Mrs. Wellings!" exclaimed Jewel, wildly, and the lady screamed
as she saw the apparently dead man on the floor.
As soon as she could speak she began to question Jewel volubly,
and the girl explained that he was a friend of hers, and had dropped
like that on entering the room.
A physician was hastily summoned, and it was found that Laurie
Meredith was not dead. He soon revived, but he had received such a
shock that weeks of illness followed, and Jewel declared that he
must not be moved from the house.
There was plenty of room. The doctor could send an experienced
nurse, she said, and she and Mrs. Wellings would do all they could.
So it followed, that when Laurie Meredith first opened his eyes, after
weeks of delirium, with a conscious gaze they fell on Jewel sitting by
his bed, looking exquisitely charming in a long white tea-gown with
crimson silk facings, and some crimson rosebuds in her braided hair.
He looked at her bewilderedly at first, then a memory of the past
began to dawn on him, and he asked her if he had been sick.
"Yes, with brain-fever, for nearly three weeks, but you are better
now," Jewel replied, in a sweet, gentle voice that thrilled him in spite
of himself, for it sounded something like Flower's as it had whispered
to him of her love last summer. He closed his eyes a few moments,
and when he opened them again he remembered all.
"Oh, Heaven! I remember all now," he moaned, "You told me that
my darling was dead."
"Yes," she said, in a soft, sweet tone, "Flower is dead—poor,
unfortunate girl—but I would not have broken it to you so abruptly if
I had known that you would take it so hard."
"You knew I loved her, Jewel," he said, looking keenly into the
beautiful, sparkling face.
"Yes, once," she replied; "but I thought it had all blown over long
ago. Mamma refused her consent, and then you went away. I
thought you had forgotten it, as Flower did very soon."
"No, no, she did not forget, Jewel!" he groaned; then paused,
remembering that Jewel could not be expected to know anything of
that secret marriage and their correspondence. Presently he said,
mournfully:
"She is dead—beautiful Flower is dead! How long ago was it, Jewel?"
She named the day when Flower had run away, and added:
"She committed suicide. She drowned herself in the sea."
She feared he would faint again, so awful was the pallor that
overspread his face, so she cried out, hastily:
"But it was not her love for you that drove her to despair, but her
shame and grief at finding out the secret of her parentage."
And she went on to tell him of the secret old Maria had revealed on
her death-bed, and which had driven her mother mad at last, and
caused Flower to drown herself.
"Mamma did not tell her for a long time, and when Flower heard it
at last she went almost as mad as poor mamma, and vowed she
would drown herself. Oh, Mr. Meredith, you can not think how
dreadful it all was!" sobbed Jewel, desolately.
He made no comment. He could not speak after the dreadful story
she had been telling him. He only lay and listened in dumb horror.
Jewel recovered herself, and continued:
"There was mamma, raving mad, and at last they had to take her to
the asylum. As for Flower, she fell ill, and tried again and again to
take her own life. I had to watch her always to prevent her going to
the sea and throwing herself in. You see, Mr. Meredith, she was my
half-sister, and I could not help but love her in spite of her birth and
of our father's sin. So I did not tell any one our dreadful secret, I
only loved poor Flower the more, and in her sickness I tended her
carefully until that awful night when I thought her dead, and rushed
down-stairs to call for help. Then she revived, got out of the house,
and drowned herself."
"Her body—was it ever recovered?" he asked, and Jewel replied:
"No; but we are certain she drowned herself, because some of her
garments were found on the sea-shore."

You might also like