The R Student Companion

Supplemental Website

 

Author:  Brian Dennis, Professor Emeritus

Department of Fish and Wildlife Science

and

Department of Mathematics and Statistical Sciences

University of Idaho

gmail address:  dr.of.chaos

 

Book published by CRC Press

Citation:  Dennis, B.  2013.  The R Student Companion.  CRC Press, Boca Raton, Florida, USA.

 

Here you can download R scripts for drawing most of the figures in the book, along with most of the scripts used and studied in the book's text, as well as data sets appearing in tables in the book.  Also, typos/errors will be posted here as they become known.

 

 

R scripts and data sets in the book, by chapter. 

 

Right click the link and download the file.

 

1.  Introduction:  Getting Started with R

Figure 1.1 (money in a bank)

Figure 1.2 (data & model:  wolf rate of feeding on moose)

 

2.  R Scripts

Figure 2.1 (loan principal remaining after t months)

wolf moose graph (data & model:  wolf rate of feeding on moose)

 

3.  Functions

hypotenuse length (using Pythagoras' formula)

molar mass (of a chemical substance)

 

4.  Basic Graphs

Figure 4.1 (one variable graphs)

Figure 4.2 (two variable graphs)

basic graph types (simple templates for each graph)

Table 4.1 (U.S. economy data)

 

5.  Data Input and Output

Figure 5.1 (scatterplot of ACT and university GPA values)

GPA males only (read GPA data from a file; extract GPA data for males only and write to a file)

Table 5.1 (GPA data)

 

6.  Loops

Figure 6.1 (age-structured wildlife population)

fibonacci (generates Fibonacci sequence)

sum and sum of squared integers (illustrates a "for loop")

 

7.  Logic and Control

Figure 7.1 (batting average simulation)

Figure 7.2 (blood pressure profile plot)

if statement example (illustrates use of "if statement")

event simulator function (simulates random vector of 0's and 1's)

olympic 1500m mens times (data: winning times in the Olympic men's 1500 meter race)

Table 7.1 (blood pressure data)

 

8.  Quadratic Functions

Figure 8.2 (Golden Ratio rectangle)

Figure 8.3 (Golden Ratio quadratic equation)

Figure 8.4 (Golden Ratio quadratic equation:  closeup)

Figure 8.5 (four quadratic equation)

Figure 8.6 (shrimp sustainable yield model)

Table 8.1 (shrimp sustainable yield data)

 

9.  Trigonometric Functions

Figure 9.2 (two similar right triangles)

Figure 9.3 (right triangle inscribed in a circle)

Figure 9.4 (right triangle inscribed in a circle-- upper left quadrant)

Figure 9.5 (plots of sine and cosine functions)

Figure 9.6 (plot of tangent function)

Figure 9.7 (general Pythagorean relationship for triangles)

Figure 9.8 (drawing a circle)

Figure 9.9 (Archimedes spiral)

Figure 9.10 (star parallax)

Figure 9.11 (projectile motion)

Figure 9.12 (Earth's orbit)

archimedes ipod ("Archimedes with an iPod" polar curve)

parallax distance (distance to Proxima Centauri using parallax)

 

10.  Exponential and Logarithmic Functions

Figure 10.1 (plot of y = x^a as a function of a)

Figure 10.2 (plot of y = (1 + 1/x)^x for increasing positive values of x)

Figure 10.3 (plot of y = (1 + 1/x)^x for negative values of x)

Figure 10.4 (exponential growth function)

Figure 10.5 (exponential and logarithmic functions)

Figure 10.6 (logistic growth function)

Figure 10.7 (Hubbert's model)

US population data

Gause Paramecia data

Norway oil production data

 

11.  Matrix Arithmetic

Figure 11.1 (age-structured wildlife population projection)

 

12.  Systems of Linear Equations

Figure 12.1 (two linear equations)

Figure 12.3 (scatterplot of Old Faithful data)

Figure 12.4 (three different prediction lines)

Figure 12.5 (Old Faithful data and prediction line)

Figure 12.6 (Cepheid variable star data from Small Magellanic Cloud and prediction line)

solve system of linear equations and invert matrix

Table 12.1 (Old Faithful data)

Cepheids in Small Magellanic Cloud data

income and college grads by states data

extinctions in Tanzinian parks data

 

13.  Advanced Graphs

Figure 13.1 (common data point symbols)

Figure 13.2 (common line symbols)

Figure 13.3 (text positions in relation to coordinate points on graphs)

Figure 13.4 (scatterplot matrix of Iris data)

Figure 13.5 (sum of squares surface wire mesh plot)

Figure 13.6 (sum of squares surface contour plot)

pronghorn data

 

14.  Probability and Simulation

Figure 14.1 (proportion of successes as number of trials increases)

Figure 14.2 (binomial distribution simulation)

Figure 14.3 (binomial probabilities)

Figure 14.4 (central limit theorem)

Figure 14.5 (normal density curve)

Figure 14.6 (randomly fluctuating stock price)

Figure 14.7 (stock price histogram)

     bonus:  vectorized version of Figure 14.7 (runs much faster!)

 

15.  Fitting Models to Data

Figure 15.1 (prediction errors for shrimp yield model)

Figure 15.2 (pronghorn prediction model and data)

Figure 15.3 (fitting nonlinear feeding rate model to wolf-moose data)

fitting quadratic yield-effort curve to shrimp data

Table 15.1 (data:  wolf rate of feeding on moose)

pronghorn data

shrimp sustainable yield data

 

16.  Conclusion.  It Doesn't Take a Rocket Scientist

Figure 16.1 (coordinate system for Earth's position relative to the Sun)

Orbit of the Earth around the Sun

 

Typos and errors.

 

Please report errors/typos to me at my gmail address above.

 

Chapter 1

 

p 11,  4 lines from bottom, the correct R expression should have a and b reversed:

 

> k=a*m/(b+m)

 

Chapter 6

 

p 102 Data table for black spruce:  in the last line of the table, the entry ".991" should be listed

in the first column (Fraction Remaining in Stage) instead of the second column.

 

Chapter 7

 

p 104, correction to the first complete sentence:

 

The vector is a logical vector, in which which in R is considered neither categorical nor numeric.

 

p 116, in Table 7.1, the labels "Special Diet Yes" and "Special Diet No" are reversed.

 

Chapter 8

 

p 128, Figure 8.2:  The expression "1 - x" in the figure  should be "x - 1".

 

Chapter 12

 

p 227, Computational Challenge 12.3:  the winning time in 1988 should be 216.0, not 16.0.

 

Appendix

 

p 323 The first entry in the Matrices section should read: " A=matrix(x,m,n): Vector x is read into an m by n

matrix A, column by column.  A=matrix(x,m,n,byrow=TRUE) reads x into A row by row.  Values in x are recycled."

 

Typos in the Chinese edition:

 

p 77, part 6.2, the 3rd part, the vector’s name should be num.fibs, not num.bifs.