Lab 1

John Fieberg

Why R?

Free and Widely Used

  • Because it is free, you will always be able to use it even after graduating!
  • You will see it again in other courses (Ecology, Analysis of Populations, Habitats and Regulation of Wildlife)

Plotting capabilities

You can create almost any graph that you can dream of by modifying code you find online. For examples, see this website!

Open-source

  • You can extend and share code with others
  • Often leads to new developments showing up in R first
  • New quantitative methods in ecology are almost always implemented using R!

Lots of examples online! For examples from a workshop on animal movement, see this website!

Reproducibility

You can easily create documents that show the code used to analyze your data.

And archive them with the Data Repository of the University of Minnesota when you publish your research! For an example, see this repository!

Goals for lab 1

Goals

  • Introduction to R and Rstudio
  • Learn how to:
    • Read in data
    • Select variables from the data set
    • Select a subset of cases from a data set
    • Produce a scatterplot
    • Write your first reproducible report!

R vs Rstudio

  • R is the programming language (the engine)
  • Rstudio is a graphical user interface (GUI)
    • Provides an enhanced working environment when writing R code
    • Helps with project management
    • Makes it relatively easy to produce reproducible reports

Posit Cloud

We will work with a server-based version of R/Rstudio, Posit Cloud

This will simplify your (and my) life considerably

  • I can make sure you have all the files you need
  • I can pre-install all R packages (think “add ons”) that you need
  • I can access your code when you are struggling

Working on your own computer

If you have a personal computer, I encourage you to install R/Rstudio (but wait until after this lab).

This will allow you to experience R as you will after this class

  • installing R packages
  • creating your own projects

R Packages

  • We will make extensive use of several packages in this class: mosaic, swirl, dplyr, Lock5Data, and adb.
  • If you have a laptop, you should install these packages (in addition to base64enc for completing pre-labs)
  • In general: to use code that others have written (e.g., in the mosaic and swirl packages)
    • Need to install the packages with: install.packages("mosaic") [Needs to be done once]
      • Type library(mosaic) [needs to be done each time you want to use the code in the package]
  • mosaic, dplyr, Lock5data, and abd packages should have already been installed (by me) in Posit Cloud, so when running code there, we should only need have to type: library(*packagename*)

On to Lab1

Process for today

  1. Work with your peers, and use the provided template, to complete the lab assignment (add code as needed, answer questions highlighted in instructions)
  2. With 15 minutes left, we will stop and create our (pdf) reproducible reports.
  3. Turn in your report on Canvas.
  4. Anyone that shows up and fully participates in lab will be given the answer key. You should view the answer key, focusing on parts you may not have gotten to in lab or that may not have made complete sense.
  5. Upload a revised lab report. You are free to add new code, change existing code, and change your answers to the questions that were posed in the lab (BUT your answers still need to be in your own words!!!). You will have a week to submit a revised lab report. This version of the lab report will be graded using the rubric on the next slide.

Lab Report Grading

If you need help

  • Try Google.
  • Type ?functionname and look at the examples at the bottom of the help page (try, for example, typing: ?filter).
  • Consult other students at your table.
  • Raise your hand, and we will stop by.