Chapter 1 Introduction

1.1 Status of this book

Wilcox, Rand (2017). Modern Statistics for the Social and Behavioral Sciences: A Practical Introduction, Second Edition (2 New edition). Boca Raton, FL: Taylor & Francis Inc. [The picture is a mockup of the original cover where I have added “Personal Notes on” and “Notes by Peter Baumgartner”].

The text you are currently reading collects my excerpts and personal notes on “Modern Statistics for the Social and Behavioral Sciences”.

Please keep in mind that this book is just a kind of training exercise for me. There will be no new insights presented, and as I am still learning the basics of R and statistics, you may find misunderstandings and errors in my writings. For authoritative reference, you have to consult the original book.

With this book, I pursue three personal learning goals:

  • To get more practice with R, the free software environment for statistical computing and graphics.
  • To learn more about modern statistics for the social sciences to get at least an intermediate practical knowledge for developing my data analysis projects.
  • To get more experience with the bookdown package.

1.2 Web pages

The book (and therefore my notes as well) uses the following resources:

1.3 Software (R Packages)

To use the software accompanying the book is a little bit complicated as there exist three different options, each with their advantages and disadvantages.

1.3.1 Textfile with all functions

The current release (Sept. 2019) Rallfun-v37.txt is a textfile and should be sourced with source_url("https://dornsife.usc.edu/assets/sites/239/docs/Rallfun-v37.txt"). It is the most updated version. It has the disadvantage that no help files are available. But most functions called without parenthesis from the console display the source code, which includes on the top a piece of summarized information about the function and its parameters.

I have converted the .txt extension to an .R file. Loading Rallfun-v37.R into RStudio displayed a message that several packages (with their dependencies) needed to be installed:

install.packages(c(“ddalpha”, “gbm”, “ICSOutlier”, “mboost”, “mrfDepth”, “neuralnet”, “rankFD”, “tseries”)) also installing the dependencies ‘TTR’, ‘ICS’, ‘stabs’, ‘nnls’, ‘Deriv’, ‘quantmod’

To source the huge file will take some time and generates an error: Error in eval(ei, envir) : object 'splotg5' not found. Version v36 has still worked. It turned out that the function splotg5() in v37 was missing. After I copied it from version v36, the error message disappeared.

The many functions not only cluttered up the global environment (workspace) but needed too much of the working memory also. Memory problems of this large file (> 2 MB) practically prevent working with it. So I have loaded the data in the setup chunk in a local environment named allfun to avoid clogging the workspace (the Global Environment). Calling one of these particular functions provided by Wilcox, I have to embed the R code into with(allfun, {x}), where x stands for the embedded R code.

1.3.2 GitHub Version

You can download the WRS Package from https://github.com/nicebread/WRS from Github, where you can also find the details of the installation process. (I am not sure, but the installation process seems more cumbersome – at least when you have to download all the dependent and suggested packages manually. )

The Github version is not always up-to-date, but at the time of this writing (2019-08-03), it has already installed Version v0.36. On Github, you will also find instructions on the installation of the C++ version. The C++ code in the package WRScpp may considerably shorten the executions times of some functions. But currently, I have problems to install them. (See my error report.)

1.3.3 Install CRAN version

The appeal of this limited edition of 37 functions is the included help files. There is a long article1 with a description of the functions currently available. (Here is the link for direct access to the PDF.)

Whenever you use a function of the CRAN version, you can conveniently use RStudio’s help utility to look into the details of this function.

1.4 Summary

There are several options to load the required packages. Each has some advantages and disadvantages:

Option Advantage Disadvantage
Rallfun-v??.txt All functions
Up to date, latest version
Help infos available
Memory problem
Not included as R packages
Own environment to prevent obstracting workspace
Help infos as comments baked into function
WRS (Github) Many functions
R package
Not all functions
Not obvious which are missing
No help pages
WRS2 (CRAN) R package
Help files
Only a small subset of functions

To get a better overview of used functions, I will apply a double strategy to implement these functions of the Wilcox book:

  1. I will use the file Rallfun-v??.txt to get all functions into the R memory. But I will create a separate environment allfun to prevent memory problems and the clogging of the workspace. For using these special functions provided by the book, I will have to address this particular environment by the with command.

  2. I will note missing functions from Rallfun-v??.txt and looking for them in the other files and/or in the older version of the Rallfun-v??.txt-file. I will add these functions to the allfun environment.

  3. Finally, at the end of each chapter, I will remove all non-base packages and clean up the working space so that I can start each chapter from scratch without side effects.

> # xxx <- suppressWarnings(lapply(names(sessionInfo()$otherPkgs),
> # function(pkgs) detach( paste0('package:', pkgs), character.only = T,
> # unload = T, force = T )))
> 
> rm(list = setdiff(ls(), freeze))