# Hands on R

## Michael DillonZoology and PhysiologyProgram in EcologyUniversity 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.

### Week 2 (24 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 (1 October): 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 (8 October): 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 (15 October): Basic plotting

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

### Week 6 (5 November): Loops and functions

I'll introduce loops and functions with an exercise using some fake data: download the data, then you can follow along. After this introduction, you'll do the BGR chapter 6 on your own (see downloads below) and keep track of questions/issues which we'll go over next week.

Data for in-class loops and functions exercise.

### Week 9: Introductory mapping

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

### Week 10: 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: 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: 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 >"