Hands on R

Michael Dillon
Zoology and Physiology
Program in Ecology
University of Wyoming

This course is an introduction to R for the complete beginner. My goal is for students to leave the course feeling comfortable enough with R to be able to find solutions for their particular analysis needs.

For Fall 2013, we will meet on Fridays from 2-4pm in BS302. There are plenty of computers (PC) available in the lab, but I encourage you to bring your own laptop.

Fall 2013 Syllabus

Installation (prior to first class)

1. If you don't already have R installed somewhere, please follow these instructions to do so.

2. Please fill out this survey and bring it with you next week. I use this to get a feel for the backgrounds of students taking the course so I can assess the effectiveness of the course and the degree to which I am reaching my target student.

Week 1 (30 August): A first session in R

Lecture slides

First session handout

Handout: in-class calculator worksheet with homework exercises at end.

Owen calculator R script (check this out after you have gone through the in class exercises by yourself)

Owen homework exercises script [posted after you have turned in your homework]

Week 2 (6 September): RStudio, Project organization and Getting Data into R

Handout for this week--detailed run-down of lecture content with links to all other content for in-class exercises and with the homework assignment. From this handout, you can download everything else you need.

Week 3 (13 September): Importing Data, Objects in R and descriptive statistics

Handout for this week--lecture content with homework assignment. From this handout, you can download everything else you need.

Week 4 (20 September): Packages and subsetting data

Handout for this week--lecture content with homework assignment. From this handout, you can download everything else you need.

Week 5 (27 September): Basic plotting

Basic Plotting handout with homework assignment. From this handout, you can download everything else you need.

Week 7 (11 October): Loops and functions

BGR Chapter 6: Loops and Functions text

Loops and functions data

Homework: Write both a loop and a function to do something interesting with your class project data. Clean up the script by moving all "junk" to the bottom and ensuring that it will work when run sequentially from line 1 to the end. Email the script and any data necessary to make it work by Thursday, October 17.

Week 8 (18 October): Advanced plotting

Data for in-class loops and functions exercise.

Advanced plotting handout with homework assignment. From this handout, you can download everything else you need.

Week 9 (25 October): Introductory mapping

Download the Maps handout and Compressed archive with files needed for in-class exercises.

Homework: Read Zuur et. al 2010 for next week.

Week 10 (1 November): Intro to basic stats

First, we'll discuss Zuur et. al 2010 (see link above). You can download the scripts and data for this paper here.

Then, we'll talk about t-tests and ANOVAs and work through some examples together. Download the lecture slides, scripts and data here

In class, you'll work through Dalgaard, Chapter 5: One- and two-sample tests. All the data used for this book are available in the "ISwR" package (install and require as usual). To access the data, just use the data() command (e.g. for section 5.3, the command "data(energy)" will load the energy data into a data frame called "energy".

Homework: By Thursday, Nov. 7, Either send me a script with answers to the exercises at the end of chapter 5 OR do some one- and two-sample tests on your own data, if appropriate.

Week 11 (8 November): Chi square, intro to regression, and writing to files

All class materials are here.

First, we will go over count data, contingency tables and associated tests. You'll get a chance to practice those with the chisq.R script.

Next, we'll run through the basics of linear modeling. You can download the lecture slides here. You'll try it out with the regression1.R script and associated data. I've also included a regression2.R script which goes through (briefly) some additional regression approaches, including non-linear terms in linear models, non-linear models, and generalized additive models. I refer you to Analyzing Ecological Data and Mixed Effects Models and Extensions in R (both books are available online through the UW library) for more discussion and demonstration of advanced model building and selection approaches.

Finally, we'll discuss some simple approaches to writing data (and other things) to files using the outdata.R script.

Homework: Come to class next week prepared to discuss an outline of your final project. We'll discuss this in class today.

Week 12 (15 November): Permutation tests

First, we'll go over a simple example of using permutations to test for significance. Download the zip file here.

Then I'll answer any questions about your final project objectives and help you individuals with any hurdles you may have in that project. (See final project guidelines below).

Final project guidelines

1. Written portion: 2-5 page description of the interesting question, the data collected, and the analyses completed. This should be a pdf with figures (made in R) embedded. Be sure the header information includes your email.

2. R script and data necessary to do the analyses and produce the figures in part 1. This should be well-organized, well-documented, and "clean", meaning that anyone can start with your script and data and reproduce your analyses.

3. Presentation: MAX of 5 minutes giving a quick overview of the question and one or two cool analyses/plots you've done with your data.

Parts 1 and 2 should be emailed to me before class on Friday, Dec. 6, when we'll do the presentations (Part 3). Please take this seriously (25% of your grade, as discussed in the syllabus), with the caveat that I am looking for you to make progress in your own graduate work and what that looks like will be different for every person.

Final Projects -- a resource!

Check out the Final project summaries If you see something that may be useful for your own work, contact information for project authors are included in their summaries.

R resources

Quick R: Lots of nice information, particularly for users of SAS, SPSS, and Stata. Example-driven approach.

Cookbook for R (formerly R Cookbook): Just as the name suggests, this has contributed "recipes" for analysis. Useful, but you have to do some digging.

R for Matlab users: Nice table of R commands side-by-side with Matlab commands (for those of you coming from a Matlab background).

Google "R cran < topic >"

Last modified: Fri Jan 10, 2014