Advanced Statistics for the Behavioral Sciences A Computational Approach with R eBook Full Text
Advanced Statistics for the Behavioral Sciences A Computational Approach with R eBook Full Text
Visit the link below to download the full version of this book:
https://medipdf.com/product/advanced-statistics-for-the-behavioral-sciences-a-co
mputational-approach-with-r/
Advanced Statistics
for the Behavioral Sciences
A Computational Approach with R
Jonathon D. Brown
Department of Psychology
University of Washington
Seattle, WA, USA
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface
“My thinking is first and last and always for the sake of my doing.”
—William James
v
vi Preface
Organization
I begin with linear algebra for two reasons. First, and most obviously, linear
algebra underlies most statistical analyses; second, understanding the mathematical
operations involved in Gaussian elimination and backward substitution provides a
basis for understanding how modern statistical software packages approach statisti-
cal analyses (e.g., why the QR decomposition is used to solve linear regression
problems). An emphasis on numerical analysis, which occurs throughout the text,
represents one of the book’s most distinctive features.
Using ℛ
All of the analyses in this book were performed using ℛ, a free software program-
ming language and software environment for statistical computing and graphics that
can be downloaded at http://www.r-project.org. However, instead of relying on
canned functions or user-created packages that must be downloaded and installed,
I have provided my own code so that readers can see for themselves how the
analyses are performed. Moreover, each analysis uses a small (n ¼ 12) data set to
encourage readers to track the operations “in real time,” with each data set telling a
coherent story with interpretable results.
The codes I have included are not intended to supplant packaged ones in ℛ.
Instead, they are offered as a pedagogical tool, designed to demystify the operations
that underlie each analysis. Toward that end, they are written with an eye toward
simplicity, occupying no more than one manuscript page of text. Few of them
contain checks for anomalous cases, so they should be used only for the particular
analyses for which they are intended. At the end of each section, the relevant
functions available in ℛ are identified, ensuring that readers can see how each
analysis is performed and have access to the state-of-the-art code that is properly
used for each statistical model.
Most of the codes are contained within each chapter, allowing readers to copy and
paste them into ℛ while they are working through the problems in the book.
Occasionally a code is called from a previous chapter, in which case I have specified
Preface vii
Intended Audience
This book is intended for graduate students in the behavioral sciences who have
taken an introductory graduate level course. It consists of 14 chapters, making it
suitable for a 15-week semester or a 10-week quarter. This book should also be of
interest to intellectually curious researchers who have been using a particular
statistical method in their research (e.g., mixed-effects models) without fully under-
standing the mathematics behind the approach. My hope is that researchers will more
readily embrace advanced statistical analyses once the underlying operations have
been illuminated.
ix
x Contents
3 Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1 Simple Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.1.1 Inspecting the Residuals . . . . . . . . . . . . . . . . . . . . . . 79
3.1.2 Describing the Model’s Fit to the Data . . . . . . . . . . . . 80
3.1.3 Testing the Model’s Fit to the Data . . . . . . . . . . . . . . 80
3.1.4 Variance Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.1.5 Tests of Significance . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.1.6 Confidence Intervals . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.1.7 R Code: Confidence Interval Simulation . . . . . . . . . . 83
3.1.8 Confidence Regions . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.1.9 Forecasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.1.10 R Code: Simple Linear Regression . . . . . . . . . . . . . . 87
3.1.11 R Code: Simple Linear Regression: Graphs . . . . . . . . 88
3.2 Multiple Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.2.1 Regression Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
3.2.2 Regression Coefficients . . . . . . . . . . . . . . . . . . . . . . . 92
3.2.3 Variance Estimates, Significance Tests, and
Confidence Intervals . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.2.4 Model Comparisons and Changes in R2 . . . . . . . . . . . 95
3.2.5 Comparing Predictors . . . . . . . . . . . . . . . . . . . . . . . . 97
3.2.6 Forecasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.2.7 R Code: Multiple Regression . . . . . . . . . . . . . . . . . . . 99
3.3 Polynomials, Cross-Products, and Categorical Predictors . . . . . . 99
3.3.1 Polynomial Regression . . . . . . . . . . . . . . . . . . . . . . . 100
3.3.2 R Code: Polynomial Regression . . . . . . . . . . . . . . . . 105
3.3.3 Cross-Product Terms . . . . . . . . . . . . . . . . . . . . . . . . 105
3.3.4 R Code: Cross-Product Terms and Simple Slopes . . . . 109
3.3.5 Johnson-Neyman Procedure . . . . . . . . . . . . . . . . . . . 110
3.3.6 R Code: Johnson-Neyman Procedure . . . . . . . . . . . . . 111
3.3.7 Categorical Predictors . . . . . . . . . . . . . . . . . . . . . . . . 111
3.3.8 R Code: Contrast Codes for Categorical Predictors . . . 113
3.3.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
3.4 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4 Eigen Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.1 Diagonalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.1.1 Eigenvector Multiplication . . . . . . . . . . . . . . . . . . . . 117
4.1.2 The Characteristic Equation . . . . . . . . . . . . . . . . . . . 119
4.1.3 R Code: Eigen Decomposition of a 2 2 Matrix with
Real Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.1.4 Properties of a Diagonalized Matrix . . . . . . . . . . . . . . 121
4.2 Eigenvalue Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
4.2.1 Basic QR Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 122
4.2.2 R Code: QR Algorithm Using Gram-Schmidt
Orthogonalization . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
xii Contents