-
Notifications
You must be signed in to change notification settings - Fork 1
/
10-LearnMore.Rmd
146 lines (107 loc) · 6.17 KB
/
10-LearnMore.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
# Chapter 10: Where to Go from Here and Common Pitfalls {-}
> "The journey of a thousand miles begins with one step." --- Lao Tzu
There are many resources that can aid in developing your `R` skills from here. We have introduced the basics of `R`, helping you take a few steps on your journey of understanding `R`. We have focused on the ones that are most important for researchers in the health, behavioral, and social sciences.
Since this has been a primer, we hope that you will continue your learning of `R` via the various sources available at little to no cost. Just like this book, many `R` books are available online as well as in print. This allows you to explore and learn online at your own pace without having to buy a bunch of books or other resources.
Below, we list a few `R` books that we have found to be useful. Most are available free in some form.
1. [R for Data Science by Hadley Wickham and Garrett Grolemund](http://r4ds.had.co.nz/)
2. [Efficient R Programming by Colin gillespie and Robin Lovelace](https://csgillespie.github.io/efficientR/)
3. [The R Cookbook](http://www.cookbook-r.com/)
4. [An Introduction to Statistical Learning](http://www-bcf.usc.edu/~gareth/ISL/)
5. [R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/)
There are *many, many* books that talk about `R` in various forms so by no means is this a complete list.
## Common Pitfalls {-}
To end, we wanted to highlight some pitfalls that can plague any beginner to `R`. We list a few that we've encountered, although others surely exist.
1. Document your work.
2. Avoid overriding objects unless it is on purpose. Changing objects can be hard to keep track of in bigger projects.
3. Ask questions. `R` is very flexible; this can make it overwhelming to learn since there are many ways to perform the same task. However, there are people who have figured out easy ways to do complex stuff and most are willing to answer an email.
4. Plan out the steps of your data manipulation and analyses. A few minutes of planning can help you not get lost in the technology and lose sight of the goal.
5. Understand the statistics before throwing data in a model. This can lead to major problems in science. At the very least, understand the assumptions of the modeling type and when it can and should be used.
6. Do exploratory data analysis (EDA) to understand your data. `R` is made for this--so use it. Otherwise, your model may be completely wrong and have many violated assumptions.
7. Be transparent in your writing. If you use the `R` scripts correctly, you can provide your code as part of any publication. This will greatly increase replicability of our important research findings.
## Quiz {-}
As a final note, we thought we would give you a quiz to test your memory of the topics we've covered. Don't worry; no pressure to get them all. We've included some tougher ones. Regardless of how well you do, we hope you'll continue improving in your `R` programming skills.
#### Question 1 {-}
What kind of vector is this?
```{r, eval=FALSE}
x <- c(10.1, 2.1, 4.6, 2.3, 8.9)
```
#### Question 2 {-}
What does this line of code do?
```{r, eval=FALSE}
df[c(1,5), c("B", "C")]
```
#### Question 3 {-}
In the `tidyverse` there are four join functions. What are they?
#### Question 4 {-}
What functions are used in the "three step summary" as described in Chapter 2?
#### Question 5 {-}
What does the following code do?
```{r, eval=FALSE}
ggplot(df, aes(x=C, y=D)) +
geom_boxplot(aes(color = C)) +
theme_bw() +
scale_color_manual(values = c("dodgerblue4", "coral2"))
```
#### Question 6 {-}
Name three functions you can use to summarize your data in an informative way.
#### Question 7 {-}
What type of model does `aov()` perform?
#### Question 8 {-}
What are the differences between `aov()` and `lm()`?
#### Question 9 {-}
What assumptions of normality and heteroskedasticity fail, what function can be used to fit logistic and poisson regressions?
#### Question 10 {-}
If you were trying to perform logistic regression, what arguments are necessary?
#### Question 11 {-}
In multilevel modeling, which functions can be used to fit a Generalized Estimating Equations model?
#### Question 12 {-}
When comparing mixed effects models, what does `anova()` do?
#### Question 13 {-}
Can `R` do structural equation modeling? If so, what package(s) are useful?
#### Question 14 {-}
What types of models can `glmnet()` perform? How can you do a cross-validated "glmnet" model?
#### Question 15 {-}
Is the following data in wide or long form? How do you know?
```{r, echo=FALSE}
data.frame("ID"=c(1:10), "Var_Time1"=rnorm(10), "Var_Time2"=runif(10)) %>%
gather("measures", "values", 2:3)
```
To make your data long form but it is currently in wide form, what function(s) can you use?
#### Question 16 {-}
What form of looping is the fastest? What does `apply()` do? Can you do for loops in `R`?
#### Question 17 {-}
What is the following code doing?
```{r, eval=FALSE}
sandwhich <- function(pb, jam){
s <- pb + jam
return(s)
}
```
#### Question 18 {-}
What is wrong with this chunk of code?
```{r, eval=FALSE}
df <- df +
mutate(newvar = ifelse(oldvar == 1, 1, 0))
```
#### Question 19 {-}
What is your favorite built in theme or how would you make your favorite custom theme?
#### Question 20 {-}
What kind of plot does the following make?
```{r, message=FALSE, warning=FALSE, eval=FALSE}
pos = position_dodge(width = .1)
ggplot(summed_data, aes(x = dep2, y = sed, group = asthma, color = asthma)) +
geom_line(position = pos) +
geom_errorbar(aes(ymin = sed - s_se, ymax = sed + s_se),
width = .1,
position = pos)
```
## Goodbye and Good Luck {-}
I hope this has been a useful primer to get you into `R`. If you still feel rusty, feel free to go through the book again or look at other online resources. `R` is very flexible and can ease the data and analysis burden of research. Implement good practices and your work will become easier to track, easier to document, and easier to communicate. Good luck on your journey using `R` in your research!
```{r, eval=FALSE}
Step1 <- of_a_journey(you) %>%
has(begun)
You <- now_have_seen(aspects, of, R) %>%
that_can(increase) %>%
productivity(your)
GoodLuck <- journey(on, your)
```