Notes on Data Analysis and Graphics Using R

Table of contents


John Maindonald and John Braun are coauthors of the book Data Analysis and Graphics Using R; Professor Maindonald maintains a web page of material that supplements that book.

Data Analysis and Graphics Using R was written for researchers who need to perform statistical analyses of their data. The book’s chapters are:

  1. A brief introduction to R
  2. Styles of data analysis
  3. Statistical models
  4. An introduction to formal inference
  5. Regression with a single predictor
  6. Multiple linear regression
  7. Exploiting the linear model framework
  8. Logistic regression and other generalized linear models
  9. Multi-level models, time series, and repeated measures
  10. Tree-based classification and regression
  11. Multivariate data exploration and discrimination
  12. The R system—additional topics

A new edition of Data Analysis and Graphics Using R will be published in 2006.

Note: Professor Maindonald has also written a shorter, free PDF tutorial, Using R for Data Analysis and Graphics. See my notes for more information.

This page stores my notes as I work through the chapters of this book. I am using R 2.2.1 and R GUI 1.14 for Mac OS X.

The DAAG package

The DAAG package contains the data used in the examples and exercises of the book.

Installing DAAG

Here’s how to install the DAAG package using R for Mac OS X:

  1. In the R GUI, click on the Packages & Data menu and select Package Installer.
  2. In the R Package Installer window, click on the popup menu at the upper left of the window and select CRAN (binaries), then click on the Get List button.
  3. R may prompt you at this point to choose a CRAN mirror site.
  4. In the package list, select DAAG, then click on the Install Selected button at the lower right. R will download and install the DAAG package on your system. When the download is complete, the value in the Installed Version column is updated.
  5. Close the R Package Installer window.

Loading DAAG

Here is the command for loading the DAAG package in an R session so you can use it:

library( package = DAAG )

For information about the contents of the DAAG package, enter the following command:

help( package = DAAG )

Chapter 1

§ 1.8.1

These plots are from page 16. There aren’t enough points for the human eye to pick up a pattern until lines are added to the plot.

get( getOption( "device" ) )()
plot( (1:50) * 0.92, sin( (1:50) * 0.92 ) )
Plot of sin() function

Plot of sin() function

get( getOption( "device" ) )()
plot( (1:50) * 0.92, sin( (1:50) * 0.92 ) )
lines( (1:50) * 0.92, sin( (1:50) * 0.92 ) )
Plot of sin() function with lines

Plot of sin() function with lines

§ 1.8.3

Using R 2.2.1 to replicate figure 1.4, I had to widen the left margin by one line of text so that the square root symbol would be drawn completely.

##  Open a default device.

get( getOption( "device" ) )()

##  Plot. Top line of square root symbol is drawn beyond the left margin
##  of the device.

    x    = p,
    y    = sqrt( p * ( 1 - p ) ),
    ylab = expression( sqrt( p( 1 - p ) ) ),
    type = "l" )

##  Open a second default device.

get( getOption( "device" ) )()

##  Widen the left margin.
##  The default margins are c( 5.1, 4.1, 4.1, 2.1 )
##  (bottom, left, top, right).

oldpar <- par( mar = c( 5.1, 5.1, 4.1, 2.1 ) )

##  Plot.

    x    = p,
    y    = sqrt( p * ( 1 - p ) ),
    ylab = expression( sqrt( p( 1 - p ) ) ),
    type = "l" )

##  Restore the old plot parameters.

par( oldpar )

§ 1.8.5

The graphics device for Mac OS X is quartz().