forked from geanders/RProgrammingForResearch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
homework.Rmd
151 lines (101 loc) · 12.7 KB
/
homework.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Appendix B: Homework
The following are six homework assignments for the course.
## Homework #1
**Due date: Sept. 14**
For your first homework assignment, you'll be working through a few [swirl](http://swirlstats.com/) lessons that are relevant to the material we've covered so far. Swirl is a platform that helps you learn R **in** R - you can complete the lessons right in your R console.
### Getting started
First, you'll need to install the swirl package:
```{r eval=FALSE}
install.packages("swirl")
```
Next, load the swirl package. We're going to download a course from swirl's [course repository](https://github.com/swirldev/swirl_courses) called R Programming E using the function `install_course_github`. Then call the `swirl()` function to enter the interactive platform:
```{r eval=FALSE}
library(swirl)
uninstall_course("R_Programming_E") # Only run if you have an old version of
# R_Programming_E installed
install_course_github("swirldev", "R_Programming_E")
swirl()
```
```{block, type = 'rmdnote'}
After calling `swirl()`, you may be prompted to clear your workspace variables by running `rm=(list=ls())`. Running this code will clear any variables you already have saved in your global environment. While swirl recommends that you do this, it's not necessary.
```
### Swirl lessons
Sign in with your name, and choose *R Programming E* when swirl asks you to choose a course. For this homework, you will need to work through the following lessons in that course (the lesson number is in parentheses):
- Basic Building Blocks (1)
- Vectors (4)
- Missing Values (5)
- Subsetting Vectors (6)
- Logic (8)
- Looking at Data (12)
- Dates and Times (14)
Each lesson should take about 10-15 minutes, but some are much shorter. You can complete the lessons in any order you want, but you may find it easiest to start with the lowest-numbered lessons and work your way up, in the order we've listed the lessons here.
You'll be able to get started on some of these lessons after your first day in class (Basic Building Blocks, for example), but others cover topics that we'll get to in weeks 2 and 3. Whether or not we've covered a swirl topic in class, you should be able to successfully work through the lesson. At the end of each lesson, you'll be prompted to "`inform someone about your successful completion of this lesson via email`." after answering `2` for 'Yes,' enter your full name, and enter rachel.severson@colostate.edu as the email address of the person you'd like to notify. You should be sending 7 emails in total.
```{block, type = 'rmdnote'}
After telling swirl that you would like to send a notification email, an already-populated email should pop up with the lesson you just completed in the subject line - you just need to push send. This might not happen if you access your email through a web browser instead of an app. In this case, just send an email manually with a screenshot of the end of the lesson, and the name of the lesson you just completed.
```
### Special swirl commands
In the swirl environment, knowing about the following commands will be helpful:
- Within each lesson, the prompt `...` indicates that you should hit Enter to move on to the next section.
- `play()`: temporarily exit swirl. It can be useful during a swirl lesson to play around in the R console to try things out.
- `nxt()`: regain swirl's attention after `play()`ing around in the console.
- `main()`: return to swirl's main menu.
- `bye()`: exit swirl. Swirl will save your progress if you exit in the middle of a lesson. You can also hit the Esc. key to exit. (To re-enter swirl, run `swirl()`. In a new R session you will have to first load the swirl library: `library(swirl)`.)
#### For fun
While they aren't required for class, you should consider trying out some other swirl lessons later in the course. The `Functions` lesson, as well as `lapply and sapply` and `vapply and tapply` could be particularly useful. You can also look through the [course directory](https://github.com/swirldev/swirl_courses) to see what other courses and lessons are available.
If you are doing extra swirl courses on your own, you probably want to do them through the "R Programming", rather than the "R Programming E", course, since you won't need to let us know by email. To get this, you can run:
```{r eval=FALSE}
library(swirl)
install_course("R_Programming")
swirl()
```
## Homework #2
**Due date: Sept. 28**
For Homework 2, recreate the R Markdown document that you can download from [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/Homework_2.docx).
Here are some initial tips:
- Your goal is to create an R Markdown document that you can compile to create a Word document that looks just like the example document we've linked above.
- You will turn in (by email) both the compiled Word document and the .Rmd original file.
- Add your name as "Author" and the due date of the assignment as "Date". You should add these within the R Markdown document, rather than changing them in the final, compiled Word document.
- If you want to get started before you know how to use R Markdown, you can go ahead and write all of the necessary code to replicate the output and figures in the document in an R script.
- The code chunks here have been hidden with the option `echo = FALSE`, but you should include your code in your final document.
- Set the chunk options `warning = FALSE` and `message = FALSE` to prevent warnings and messages from being printed out. You will get some messages and warnings in the code from things like missing values and from loading packages, but you want to hide all of those messages in your final document.
- For things like templates, colors, level of transparency, and point size, you will receive full credit if you create figures that are visually similar to the ones shown in the example document. In other words, if the example document shows some transparency in points, you will get full credit if you also include some transparency in the points in your plot, but you do not have to include the exact same value of `alpha`.
- In R, there are often many different ways to achieve something. As long as your code *works*, it's fine if you haven't coded it exactly like we have in our version. However, your output should look identical to ours (or, in the case of color, transparency, point size, and themes, visually similar).
- You will not lose points if you cannot recreate the table in the document (although you should try to!).
- The last section, under the heading "Extra challenge-- not graded", is not graded. However, if you'd like an extra challenge, you're welcome to try it out and include it in your final submission!
If you need them, here are some further tips:
- Functions from the tidyverse (especially from `dplyr`, `readr`, and `ggplot` packages) will make your life much easier for this exercise. You can now install and load the `tidyverse` package to load them all at once.
- To rename column names with "special" characters in them, wrap the whole old column name in backticks. For example, to change a column name that has a dollar sign in it, you would use something like "rename(new_col_name = \`old_col_name$\`)".
- To change the size of a figure in a report, use the "fig.width" and "fig.height" chunk options.
- You will want to use `scale_fill_brewer` in several of the figures.
- Don't forget that, within functions like `scale_x_continuous`, you can use the argument `breaks` to set where the axis has breaks, and then `labels` to set what will actually be shown at each break.
- The string "\\n" can be included in legends and labels to include a carriage return.
- Coordinates can be flipped in a graph with the `coord_flip` geom. So, if you can figure out a way to make a graph with the coordinates flipped, use that code and just add `coord_flip` at the end.
## Homework #3
**Due date: Oct. 12**
For Homework 3, recreate the R Markdown document that you can download from [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/Homework_3.docx).
Here are some initial tips:
- Your goal is to create an R Markdown document that you can compile to create a Word document that looks just like the target document we've linked above. The only difference is that you will use `echo = TRUE` to show your code within the rendered Word document. All formating within the text should be similar or identical to the target document.
- You will turn in (by email) both the compiled Word document and the .Rmd original file.
- Add your name as "Author" and the due date of the assignment as "Date". You should add these within the R Markdown document, rather than changing them in the final, compiled Word document.
- Set the chunk options `warning = FALSE` and `message = FALSE` to prevent warnings and messages from being printed out. You will get some messages and warnings in the code from things like missing values and from loading packages, but you want to hide all of those messages in your final document.
- For things like templates, colors, level of transparency, and point size, you will receive full credit if you create figures that are visually similar to the ones shown in the example document. In other words, if the example document shows some transparency in points, you will get full credit if you also include some transparency in the points in your plot, but you do not have to include the exact same value of `alpha`.
- In R, there are often many different ways to achieve something. As long as your code *works*, it's fine if you haven't coded it exactly like we have in our version. However, your output should look identical to ours (or, in the case of color, transparency, point size, and themes, visually similar).
- There is one formated table in the target document. Be sure that you render this as a formated table, not as raw R output.
If you need them, here are some further tips:
- Functions from the tidyverse (especially from `dplyr`, `readr`, and `ggplot` packages) will make your life much easier for this exercise. You can now install and load the `tidyverse` package to load them all at once.
- To reference column names with "special" characters in them, like dollar signs or spaces, wrap the whole old column name in backticks. For example, to change a column name that has a dollar sign in it, you would use something like "rename(new_col_name = \`old_col_name$\`)".
- To change the size of a figure in a report, use the "fig.width" and "fig.height" chunk options.
- Don't forget that there are functions in the `scale` family that allow you to use log-scale axes.
## Homework #4
**Optional due date: Oct. 28**
All instructions for this homework can be downloaded [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/Homework4and5.pdf). The example "fars_analysis.pdf" document you will try to recreate is [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/fars_analysis.pdf).
You have the option to turn in parts of this homework (up through creating a clean dataset) by Oct. 28. If you do so, I will email you the code I used to clean the data, so you can check your own code and be sure you have a reasonable version of the clean data as you do the final parts of the assignment.
## Homework #5
**Due date: Nov. 9**
All instructions for this homework can be downloaded [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/Homework4and5.pdf). The example "fars_analysis.pdf" document you will try to recreate is [here](https://github.com/geanders/RProgrammingForResearch/raw/master/Homework/fars_analysis.pdf).
You will submit this homework by posting a repo with your project directory on GitHub. We will work on setting that up during an in-course exercise.
## Homework #6
**Due date: Nov. 30**
1. Read the article *Good Enough Practices in Scientific Computing* by Wilson et al. (available [here](https://arxiv.org/abs/1609.00037)). In a half page, describe which of these "pretty good practices" your last homework incorporated. Also list one or two practices that you did not follow in your last homework but that would have made sense and how you could have followed them.
2. Read the article [*Science Isn't Broken*](http://fivethirtyeight.com/features/science-isnt-broken/) on FiveThirtyEight. This article includes an interactive graphic. In a half page, give your opinion on whether this interactive graphic helps convey the main message of the article. Also, describe in general details how you might be able to create a graphic like this in R.
3. Find an article in *The R Journal* that describes an R package that you could use in your own research or otherwise find interesting. Describe why the package was created and what you think it's most interesting features are. In an R Markdown document, run one or two of the R examples included in the article.