Course information

Download a pdf of the lecture slides covering this topic.

Note: For Fall 2021, only ERHS 535 is being offered.

0.1 Course overview

This document provides the course notes for Colorado State University’s R Programming for Research courses (ERHS 535, ERHS 581A3, and ERHS 581A4). The courses offer in-depth instruction on data collection, data management, programming, and visualization, using data examples relevant to data-intensive research.

0.2 Time and place

Students for ERHS 535, ERHS 581A3, and ERHS 581A4 will meet together. Students in ERHS 535 will meet for the entire semester, completing a three-credit course. Students in ERHS 581A3 will meet for the first five weeks of the semester, completing a one-credit course. Students in ERHS 581A4 will meet from the sixth week to the final week of the semester, completing a two-credit course.

The course meets in a mixed format, with about two hours of asynchronous video lectures per week and about two hours of in-person meeting time. Course lectures are provided through YouTube videos. These are embedded in the online course book, and the book also provides links to playlists for each chapter of all the videos for that chapter.

Exceptions to the regular live meeting times are:

  • There will be no meeting on Labor Day (Monday, Sept. 6).
  • There are no course meetings the week of Thanksgiving (week of Nov. 22).
  • Office hours will be on Wednesday (time to be announced)

0.3 Detailed schedule

Here is a more detailed view of the schedule for this course for Fall 2021:

Week Class date Videos In-class exercises Graded items
1 Aug. 23 None Ch 0: 0.7.1–0.7.3
1 Aug. 25 Ch 1, Videos 1–9 Ch 1: 1.10.3–1.10.10
2 Aug. 30 Ch 1, Video 10; Ch 2, Videos 1–4 Ch 2: 2.7.1–2.7.3
2 Sept. 1 Ch 2, Videos 5–10 Ch 2: 2.7.4–2.7.6 Quiz 1
3 Sept. 8 Ch 3, Videos 1–5 Ch 3: 3.8.1—3.8.3 Quiz 2
4 Sept. 13 Ch 3, Videos 6–10 Ch 3: 3.8.4–3.8.5 HW 1 due
4 Sept. 15 Ch 4, Videos 1–4 Ch 3: 3.8.6; Ch 4: 4.10.1 Quiz 3
5 Sept. 20 Ch 4, Videos 5–7 Ch 4: 4.10.2–4.10.3
5 Sept. 22 Ch 5, Videos 1–4 Ch 5: 5.6.1–5.6.4 Quiz 4
6 Sept. 27 Ch 5, Videos 5–6, Ch 6, Videos 1–3 Ch 6: 6.7.1–6.7.2
6 Sept. 29 Ch 6, Videos 4–8 Ch 6: 6.7.2–6.7.3 Quiz 5
7 Oct. 4 Ch 6, Videos 9–12 Ch 6: 6.7.4–6.7.5 HW 2 due
7 Oct. 6 No videos Work on Q4 from HW 3 Quiz 6
8 Oct. 11 Ch 7, Videos 1–3 Ch 7: 7.8.2–7.8.3
8 Oct. 13 Ch 7, Videos 4–5 Ch 7: 7.8.3 Quiz 7
9 Oct. 18 Ch 7, Videos 6 (Optional: Ch 7, Videos 7–8) Ch 7: 7.8.4–7.8.5
9 Oct. 20 Ch 7, Videos 9–11 Ch 7: 7.8.6 Quiz 8, HW 3 due
10 Oct. 25 Ch 7, Videos 12–14 Ch 7: 7.8.7
10 Oct. 27 Ch 8, Video 1 Ch 8: 8.5.1–8.5.2 Quiz 9
11 Nov. 1 Ch 8, Videos 2–3 Ch 8: 8.5.3
11 Nov. 3 No videos Ch 8: 8.5.4 HW 4 due
12 Nov. 8 Ch 9, Videos 1–4 Guest exercise
12 Nov. 10 Ch 9, Videos 5–7 Guest exercise
13 Nov. 15 Ch 9, Videos 8–9 Ch 9: 9.4.1–9.4.3
13 Nov 17 Ch 12, Videos 1–3 Group work on final project HW 5 due
14 Nov. 29 Ch 12, Videos 4–5 Group work on final project
14 Dec. 1 Ch 10, Videos 1–3 Group work on final project
15 Dec. 6 Ch 10, Videos 4–5 Group work on final project
15 Dec. 8 No videos Group work on final project HW 6 due

Students in ERHS 581A3 will be in weeks 1–5 of this schedule. Students in ERHS 581A4 will be in weeks 6–16 of this schedule.

Office hours for Fall 2021 will be (locations to be determined):

  • September 29 (9-10 AM and 1-2 PM)
  • October 13 (9-10 AM)
  • October 20 (12-2 PM)
  • October 27 (9-10 AM)
  • November 3 (12-2 PM)
  • November 10 (9-10 AM)
  • November 17 (12-2 PM)

0.4 Grading

0.4.1 Grading for ERHS 535

For ERHS 535, course grades will be determined by the following five components:

Assessment component Percent of grade
Final group project 30
Weekly in-class quizzes, weeks 2-10 25
Six homework assignments 25
Attendance and class participation 10
Weekly in-course group exercises 10

0.4.2 Grading for ERHS 581A3

For ERHS 581A3, course grades will be determined by the following four components:

Assessment component Percent of grade
Weekly in-class quizzes, weeks 2-5 40
Two homework assignments 30
Attendance and class participation 10
Weekly in-course group exercises 20

0.4.3 Grading for ERHS 581A4

For ERHS 581A4, course grades will be determined by the following five components:

Assessment component Percent of grade
Final group project 30
Weekly in-class quizzes, weeks 1–5 (weeks 6–10 of the semester) 25
Four homework assignments 30
Attendance and class participation 5
Weekly in-course group exercises 10

0.4.4 Attendance and class participation

Because so much of the learning for this class is through interactive work in class, it is critical that you attend the live sessions. Half of the class will have these meetings from 10:00 AM–10:55 AM on Mondays and Wednesdays and the other half will have these meetings from 11:00 AM–12:55 PM on Mondays and Wednesdays.

Videos of the lectures for each chapter of the online book will be shared through YouTube. These will be embedded in the book, and a playlist for each chapter will also be provided through a link at the start of that chapter in the book. You are responsible for watching these videos before the in-person meetings. You will get email reminders with a list of the videos that you need to watch before each live meeting. There will be about two hours worth of video lectures each week, broken into videos about 10–15 minutes each.

If you are in ERHS 535, out of a possible 10 points for class attendance, you will get:

  • 10 points if you miss two or fewer classes
  • 8 points if you miss three classes
  • 6 points if you miss four classes
  • 4 points if you miss five classes
  • 2 points if you miss six classes
  • 0 points if you miss seven or more classes

If you are in ERHS 581A3 or ERHS581A4, out of a possible 10 points for class attendance, you will get:

  • 10 points if you miss one or fewer classes
  • 8 points if you miss two classes
  • 6 points if you miss three classes
  • 4 points if you miss four classes
  • 2 points if you miss five classes
  • 0 points if you miss six or more classes

Exceptions:

  • Attendance on the first day of class (Aug. 23) will not be counted.
  • If you miss classes for “University-sanctioned” activities. These can include attending a conference, travel to collect data for your dissertation), For these absences, you must provide a signed letter from your research adviser. For more details, see CSU’s Academic Policies on Course Attendance.
  • If you have to miss class for a serious medical issue (e.g., operation, sickness severe enough to require a doctor’s visit), the absence will be excused if you bring in a note from a doctor of other medical professional giving the date you missed and that it was for a serious medical issue.

For an absence to be excused, you must email me a copy of the letter by 5:00 pm the Friday afternoon following the class you missed.

0.4.5 Weekly in-course group exercises

The live meetings will be spent doing in-course group exercises. As long as you are in class and participate in these exercises, you will get full credit for this component.

If you miss a live class meeting, to get credit towards this component of your grade, you will need to turn a few paragraphs describing what was covered in the exercise and what you learned. To get credit for this, you must submit it to me by email by 5:00 pm the Friday afternoon of the week of the class you missed.

All in-class exercises are included in the online course book at the end of the chapter on the associated material.

0.4.6 In-class quizzes

There will be weekly in-course quizzes for weeks 2–10 of the course. Students in ERHS 535 will take all these quizzes. Students in ERHS 581A3 will take quizzes in weeks 2–5. Students in ERHS 581A4 will take quizzes in weeks 6–10.

Quizzes will be conducted through Google Forms. They will be immediately graded, and you will get back your grade and feedback as soon as you submit the quiz. All students will take the quizzes from 10:50 AM to 11:10 AM on Wednesdays. Students in the 11:00 AM cohort should plan to arrive to the live meeting 10 minutes early on Wednesdays.

Each quiz will have at least 10 questions. Typically, a quiz will have more questions, usually 12–15 questions. The grading of the quizzes is structures so that you can get full credit for the quiz portion of the grade without getting 100% of quiz questions right. Instead, if you get ten questions right per quiz on average, you will get full credit for the quiz portion of the grade.

Once you reach the maximum possible points on quizzes, you can continue to take the quizzes for practice, or you can choose to skip any following quizzes.

Quiz questions will be multiple choice, matching, or very short answers. The “Vocabulary” appendix of our online book has the list of material for which you will be responsible for this quiz. Most of the functions and concepts will have been covered in class, but some may not. You are responsible for going through the list and, if there are things you don’t know or remember from class, learning them. To do this, you can use help functions in R, Google, StackOverflow, books on R, ask a friend, and any other resource you can find. The final version of the Vocabulary list you will be responsible will be posted by the Wednesday evening before each quiz. In general, using R frequently in your research or other coursework will help you to prepare and do well on these quizzes.

Except in very unusual situations, the only time you will be able to make up a quiz is during office hours of the same week when you missed the quiz. Note that you can still get full credit on your total possible quiz points if you miss a class, but it means you will have to work harder and get more questions right for days you are in class.

0.4.6.1 Quiz grade calculations for ERHS 535

For students in ERHS 581A3, the nine quizzes in weeks 2–10 count for 25 points of the final grade. The final quiz total for students in ERHS 535 will be calculated as:

\[ \mbox{Quiz grade} = 25 * \frac{\mbox{Number of correct quiz answers}}{90} \]

0.4.6.2 Quiz grade calculations for ERHS 581A3

For students in ERHS 581A3, the four quizzes in weeks 2–5 count for 40 points of the final grade. The final quiz total for students in ERHS 581A3 will be calculated as:

\[ \mbox{Quiz grade} = 40 * \frac{\mbox{Number of correct quiz answers}}{40} \]

0.4.6.3 Quiz grade calculations for ERHS 581A4

For students in ERHS 581A4, the five quizzes in weeks 6–10 count for 25 points of the final grade. The final quiz total for students in ERHS 581A3 will be calculated as:

\[ \mbox{Quiz grade} = 25 * \frac{\mbox{Number of correct quiz answers}}{50} \]

0.4.7 Homework

There will be homework assignments due throughout the course (see the detailed schedule in the online course book for exact due dates).

The first two homeworks (HWs #1 and # 2) should be done individually. For later homeworks, you may be given the option to work in small groups of approximately three students.

Homeworks will be graded for correctness, but some partial credit will be given for questions you try but fail to answer correctly. Some of the exercises will not have “correct” answers, but instead will be graded on completeness.

For later homeworks, a subset of the full set of questions will be selected for which I will do a detailed grading of the code itself, with substantial feedback on coding. All other questions in the homework will be graded for completeness and based on the final answer produced.

Homework is due to me by email by midnight on the due date. Your grade will be reduced by 10 points for each day it is late, and will receive no credit if it is late by over a week.

0.4.8 Final group project

You will do the final group project in groups of 3–4. The final product will be a flexdashboard (html created from RMarkdown file) that presents interesting facets of a dataset to viewers and allows them to interact in at least some of the panes. There is more information about flexdashboards available at https://rmarkdown.rstudio.com/flexdashboard/examples.html.

Your group’s dashboard should include a text block somewhere on the dashboard that explains the data (including the data source) as well as what the dashboard can be used to explore and how to navigate it (for example, see the left-most pane in this dashboard: https://walkerke.shinyapps.io/neighborhood_diversity/). Besides this text block, your dashboard show have at least three panes with output (figures or tables). At least one should be interactive (using htmlwidgets). You may include everything in a single page (like https://beta.rstudioconnect.com/jjallaire/htmlwidgets-waste-sites/htmlwidgets-waste-sites.html) or you can spread results and text across several tabs of a dashboard (like https://walkerke.shinyapps.io/neighborhood_diversity/#explore-metros and https://beta.rstudioconnect.com/jjallaire/htmlwidgets-showcase-storyboard/htmlwidgets-showcase-storyboard.html).

There is extensive documentation about building flexdashboards here: https://rmarkdown.rstudio.com/flexdashboard/using.html. To divide group work, you may find it helpful to have some group members work on designing and setting up the framework for the dashboard, and then other members focus on writing the code for the figures and tables that will go in specific panes of the dashboard. Everything can then be put together by moving the code for those figures and tables into the flexdashboard Rmarkdown file.

You will have in-class group work time to work on this during the in-person sessions. This project will also require some work with your group outside of class. I will provide feedback and help during the in-class group work time.

The final group project will be graded with A through F, with the following point values (out of 30 possible):

  • 30 points for an A
  • 25 points for a B
  • 20 points for a C
  • 15 points for a D
  • 10 points for an F

If you turn nothing in, you will get 0 points.

0.4.8.1 Final presentation

  • In total, the group’s presentation should last 15 minutes. There will then be 5 minutes for questions.
  • Split the presentation up into two parts: (1) an overview of your flexdashboard (about 7 minutes) and (2) a tutorial-style discussion of how you used R to do the project (about 8 minutes).
  • The overview of your flexdashboard should:
    • Explain the data sources for your dashboard
    • Explain what a user should be able to explore or understand by using your dashboard
    • Walk viewers through each pane in the flexdashboard and how any interactive elements can be used
  • The tutorial part should include the following sections:
    • Interesting packages / techniques: Spend a bit more time on any parts that you found particularly interesting or exciting. Were there packages you used that were helpful that we haven’t talked about in class? Did you find out how to do anything that you think other students could use in the future? Did you end up writing a lot of functions to use? Did you have an interesting way of sharing code and data among your group members?
    • Lessons learned: If you were to do this project again from scratch, what would you do differently? Were there any big wrong turns along the way? Did you find out how to do something late in the project that would have saved you time if you’d started using it earlier?

0.4.8.2 Flexdashboard

The grade for the flexdashboard will be based on the following criteria:

  • It should work.
  • It should include text that is clearly written, without grammatical errors or typos. Any graphics are easily to interpret and follow some of the principles of good graphics covered in class.
  • It includes at least three rendered outputs (e.g., plots, tables). At least one should be interactive.
  • It is self-contained—in other words, a user shouldn’t need to hear you explain the dashboard to understand it. It should include enough information on the app for a user to figure out how to use the app and interpret the output.

0.5 Course set-up

Please download and install the latest version of R and RStudio (Desktop version, Open Source edition) installed. Both are free for anyone to download.

Students in ERHS 535 and ERHS 581A4 will also need to download and install a version of LaTeX (MikTeX for Windows and MacTeX for Macs). They will also need to download and install git software and create a GitHub account.

Here are useful links for this set-up:

0.6 Coursebook

This coursebook will serve as the only required textbook for this course. I am still in the process of editing and adding to this book, so content may change somewhat over the semester (particularly for later weeks, which is currently in a rawer draft than the beginning of the book). We typically cover about a chapter of the book each week of the course.

This coursebook includes:

  • Embedded video lectures for the course
  • Links to the slides presented in video lectures for each topic
  • In-course exercises, typically including links to the data used in the exercise
  • An appendix with homework assignments
  • A list of vocabulary and concepts that should be mastered for each quiz

If you find any typos or bugs, or if you have any suggestions for how the book can be improved, feel free to post it on the book’s GitHub Issues page.

This book was developed using Yihui Xie’s wonderful bookdown framework. The book is built using code that combines R code, data, and text to create a book for which R code and examples can be re-executed every time the book is re-built, which helps identify bugs and broken code examples quickly. The online book is hosted using GitHub’s free GitHub Pages. All material for this book is available and can be explored at the book’s GitHub repository.

0.6.1 Other helpful books (not required)

The best book to supplement the coursebook and lectures for this course is R for Data Science, by Garrett Grolemund and Hadley Wickham. The entire book is freely available online through the same format at the coursebook. You can also purchase a paper version of the book (published by O’Reilly) through Amazon, Barnes & Noble, etc., for around $40. This book is an excellent and up-to-date reference by some of the best R programmers in the world.

There are a number of other useful books available on general R programming, including:

The R programming language is used extensively within certain fields, including statistics and bioinformatics. If you are using R for a specific type of analysis, you will be able to find many books with advice on using R for both general and specific statistical analysis, including many available in print or online through the CSU library.

0.7 In-course Exercise Chapter 0

Today, we’ll practice doing an in-course exercise. The purpose of this in-course exercise is to help you explore the online book and videos for this class to make sure that you are comfortable with navigating those resources. You will work on this for about 20 minutes.

The last prompt requires you to have RStudio installed. If nobody in the group has RStudio installed, you can read through this part without doing the activities.

0.7.2 Find the video lectures

  • Look through the book to find links to the YouTube video lectures for Chapter 1 (“R Preliminaries”). You should be able to find:
    • Embedded videos throughout the text
    • Links to download the pdfs for each video below each embedded video
    • A link to a YouTube playlist with all the video lectures for the chapter at the beginning of the chapter text.
  • Download the pdf copy of the slides for the first video lecture for Chapter 1.
  • Watch the very beginning of the first video lecture for Chapter 1.
  • You will need to watch the first nine video lectures for Chapter 1 before we meet on Wednesday.
    • What are the titles of these nine videos?
    • What is the title of the only video for Chapter 1 that you are not required to watch before Wednesday’s meeting?

0.7.3 Try coding a bit

  • Open RStudio
  • Open an R script by going to “File” -> “New File” -> “R Script”
  • Type the following code in the R script:
sample(c("Johnny", "Waylon", "Willie", "Kris"))
  • Highlight the code you just typed and then click the “Run” bottom on the top right of the script file. Look in the “Console” pane of RStudio. What output do you see?
  • In the script, replace each name with the name of a member of your group. Re-run the code by highlighting it again and the pressing the “Run” button. What output do you see in the console?
  • Without changing the code, highlight and run it three more times. Is the output the same each time?
  • Click your cursor in the R script pane and then save this R script by going to “File” -> “Save.” Save the file somewhere that’s easy to find, like on your Desktop (you can delete it after today). Save it with the name “example.R.”
  • Send this file to your other group members through Zoom chat as a file attachment. When you use Chat in Zoom, you should see a button for “File.” This should allow you to select and send the R script you just saved.
  • Have another group member share their screen and then open this file in RStudio (open RStudio, and then go to “File” -> “Open File” and select the file from where you saved it in your computer). Try highlighting and running this code on this computer.