Skip to content

Commit

Permalink
updates after having completed teaching in 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgerstenberg committed Mar 11, 2021
1 parent 7b04de1 commit f8c18a9
Show file tree
Hide file tree
Showing 936 changed files with 73,202 additions and 36,361 deletions.
18 changes: 16 additions & 2 deletions 01-introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ library("tidyverse") # everything else
# Visualization
library("patchwork") # making figure panels
library("cowplot") # making figure panels
library("ggpol") # for making fancy boxplots
library("ggridges") # for making joyplots
library("gganimate") # for making animations
Expand All @@ -71,13 +70,13 @@ library("ggrepel") # for labels in ggplots
library("corrr") # for calculating correlations between many variables
library("corrplot") # for plotting correlations
library("DiagrammeR") # for drawing diagrams
library("ggeffects") # for visualizing effects
library("bayesplot") # for visualization of Bayesian model fits
# Modeling
library("afex") # also for running ANOVAs
library("lme4") # mixed effects models
library("emmeans") # comparing estimated marginal means
library("broom") # getting tidy model summaries
library("broom.mixed") # getting tidy mixed model summaries
library("janitor") # cleaning variable names
library("car") # for running ANOVAs
Expand All @@ -91,6 +90,7 @@ library("multilevel") # Sobel test
library("extraDistr") # additional probability distributions
library("effects") # for showing effects in linear, generalized linear, and other models
library("brms") # Bayesian regression
library("parameters") # For extracting parameters
# Misc
library("tictoc") # timing things
Expand All @@ -99,8 +99,22 @@ library("lsr") # for computing effect size measures
library("extrafont") # additional fonts
library("pwr") # for power calculations
library("arrangements") # fast generators and iterators for permutations, combinations and partitions
library("stargazer") # for regression tables
library("sjPlot") # for regression tables
library("xtable") # for tables
```

## Installing packages

```{r, eval=FALSE, include=FALSE}
# Note: To get greta to work on my mac, I had to run the following commands
devtools::install_github("greta-dev/greta")
greta::install_tensorflow(method = "conda",
version = "1.14.0",
extra_packages = "tensorflow-probability==0.7.0")
```


## Session info

```{r, echo=F}
Expand Down
27 changes: 13 additions & 14 deletions 02-visualization1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library("tidyverse") # for plotting (and many more cool things we'll discover la
# these options here change the formatting of how comments are rendered
# in RMarkdown
opts_chunk$set(comment = "#>",
opts_chunk$set(comment = "",
fig.show = "hold")
```

Expand Down Expand Up @@ -740,11 +740,11 @@ Here, I've set `color = "black"` within the `geom_smooth()` function, and now on

### Cheatsheets

- [RStudio IDE](figures/cheatsheets/rstudio-ide.pdf) --> information about RStudio
- [RMarkdown](figures/cheatsheets/rmarkdown.pdf) --> information about writing in RMarkdown
- [RMarkdown reference](figures/cheatsheets/rmarkdown-reference.pdf) --> RMarkdown reference sheet
- [Data visualization](figures/cheatsheets/visualization-principles.pdf) --> general principles of effective graphic design
- [ggplot2](figures/cheatsheets/data-visualization.pdf) --> specific information about ggplot
- [RStudio IDE](figures/rstudio-ide.pdf) --> information about RStudio
- [RMarkdown](figures/rmarkdown.pdf) --> information about writing in RMarkdown
- [RMarkdown reference](figures/rmarkdown-reference.pdf) --> RMarkdown reference sheet
- [Data visualization](figures/visualization-principles.pdf) --> general principles of effective graphic design
- [ggplot2](figures/data-visualization.pdf) --> specific information about ggplot

### Datacamp courses

Expand All @@ -758,28 +758,27 @@ Here, I've set `color = "black"` within the `geom_smooth()` function, and now on
- [R graphics cookbook](http://www.cookbook-r.com/Graphs/) --> quick intro to the the most common graphs
- [ggplot2 book](https://ggplot2-book.org/)
- [R for Data Science book](http://r4ds.had.co.nz/)
+ [R Markdown](https://r4ds.had.co.nz/r-markdown.html)
+ [Data visualization](http://r4ds.had.co.nz/data-visualisation.html)
+ [Graphics for communication](http://r4ds.had.co.nz/graphics-for-communication.html)
+ [Data visualization](http://r4ds.had.co.nz/data-visualisation.html)
+ [Graphics for communication](http://r4ds.had.co.nz/graphics-for-communication.html)
- [Data Visualization -- A practical introduction (by Kieran Healy)](http://socviz.co/)
+ [Look at data](http://socviz.co/lookatdata.html#lookatdata)
+ [Make a plot](http://socviz.co/makeplot.html#makeplot)
+ [Show the right numbers](http://socviz.co/groupfacettx.html#groupfacettx)
- [Fundamentals of Data Visualization](https://clauswilke.com/dataviz/) --> very nice resource that goes beyond basic functionality of `ggplot` and focuses on how to make good figures (e.g. how to choose colors, axes, ...)
- [Fundamentals of Data Visualization](https://serialmentor.com/dataviz/) --> very nice resource that goes beyond basic functionality of `ggplot` and focuses on how to make good figures (e.g. how to choose colors, axes, ...)

### Misc

- [learn R demos](https://github.com/poldrack/learnr_demos) --> tutorials on learning R created by Russ Poldrack for Psych 10 (the Stanford undergraduate statistics class)
- [nice online ggplot tutorial](https://evamaerey.github.io/ggplot2_grammar_guide/about)
- [how to read R help files](https://socviz.co/appendix.html#a-little-more-about-r)
- [ggplot2 extensions](http://www.ggplot2-exts.org/gallery/) --> gallery of ggplot2 extension packages
- [ggplot2 gui](https://github.com/dreamRs/esquisse) --> ggplot2 extension package
- [ggplot2 visualizations with code](http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html) --> gallery of plots with code
- [R Markdown for class reports](http://www.stat.cmu.edu/~cshalizi/rmarkdown/)
- [styler](https://github.com/r-lib/styler) --> RStudio add-in that re-formats code

## Session info

```{r, echo=F}
sessionInfo()
```

```{r, echo=FALSE, fig.cap="Defense at the reproducibility court.", out.width="95%"}
include_graphics("figures/reproducibility_court.jpg")
```
28 changes: 13 additions & 15 deletions 03-visualization2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -775,17 +775,17 @@ Here are some snippets I use:

```{r, eval=FALSE}
snippet snbar
ggplot(data = ${1:data}, mapping = aes(x = ${2:x}, y = ${3:y})) +
stat_summary(fun = "mean", geom = "bar", color = "black") +
stat_summary(fun.data = "mean_cl_boot", geom = "linerange")
ggplot(data = ${1:data}, mapping = aes(x = ${2:x}, y = ${3:y})) +
stat_summary(fun = "mean", geom = "bar", color = "black") +
stat_summary(fun.data = "mean_cl_boot", geom = "linerange")
snippet sngg
ggplot(data = ${1:data}, mapping = aes(${2:aes})) +
${0}
ggplot(data = ${1:data}, mapping = aes(${2:aes})) +
${0}
snippet sndf
${1:data} = ${1:data} %>%
${0}
${1:data} = ${1:data} %>%
${0}
```

To make a bar plot, I now only need to type `snbar` and then hit TAB to activate the snippet. I can then cycle through the bits in the code that are marked with `${Number:word}` by hitting TAB again.
Expand All @@ -806,23 +806,21 @@ usethis::edit_rstudio_snippets()

This command opens up a separate tab in RStudio called `r.snippets` so that you can make new snippets and adapt old ones more quickly. Take a look at the snippets that RStudio already comes with. And then, make some new ones! By using snippets you will be able to avoid typing the same code over and over again, and you won't have to memorize as much, too.

## Additional resources
## Additional resources

### Cheatsheets

- [shiny](figures/shiny.pdf) --> interactive plots

### Data camp courses

- [ggplot (intermediate)](https://learn.datacamp.com/courses/intermediate-data-visualization-with-ggplot2)
- [shiny 1](https://www.datacamp.com/courses/building-web-applications-in-r-with-shiny)
- [shiny 2](https://www.datacamp.com/courses/building-web-applications-in-r-with-shiny-case-studies)
- [shiny](https://www.datacamp.com/courses/building-web-applications-in-r-with-shiny-case-studies)

### Books and chapters

- [R for Data Science book](http://r4ds.had.co.nz/)
+ [Data visualization](http://r4ds.had.co.nz/data-visualisation.html)
+ [Graphics for communication](http://r4ds.had.co.nz/graphics-for-communication.html)
+ [Data visualization](http://r4ds.had.co.nz/data-visualisation.html)
+ [Graphics for communication](http://r4ds.had.co.nz/graphics-for-communication.html)
- [Data Visualization -- A practical introduction (by Kieran Healy)](http://socviz.co/)
+ [Refine your plots](http://socviz.co/refineplots.html#refineplots)

Expand All @@ -840,4 +838,4 @@ Information about this R session including which version of R was used, and what

```{r}
sessionInfo()
```
```
24 changes: 9 additions & 15 deletions 04-data_wrangling1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ In this lecture, we will take a look at how to wrangle data using the [dplyr](ht
- See different ways for getting a sense of one's data.
- Master key data manipulation verbs from the `dplyr` package (incl. `filter()`, `arrange()`, `rename()`, `relocate()`, `select()`, `mutate()`) as well as the helper functions `across()` and `where()`.

## Install packages

```{r install-packages, eval=FALSE}
install.packages(c("skimr", "visdat", "summarytools", "DT"))
```


## Load packages

Let's first load the packages that we need for this chapter.
Expand All @@ -27,6 +20,9 @@ library("visdat") # for visualizing data
library("summarytools") # for visualizing data
library("DT") # for visualizing data
library("tidyverse") # for data wrangling
opts_chunk$set(comment = "",
fig.show = "hold")
```

## Some R basics
Expand Down Expand Up @@ -874,12 +870,12 @@ Compute the body mass index for `masculine` characters who are `human`.
# write your code here
```

## Additional resources
## Additional resources

### Cheatsheets

- [base R](figures/cheatsheets/base-r.pdf) --> summary of how to use base R (we will mostly use the tidyverse but it's still important to know how to do things in base R)
- [data transformation](figures/cheatsheets/data-transformation.pdf) --> transforming data using `dplyr`
- [base R](figures/base-r.pdf) --> summary of how to use base R (we will mostly use the tidyverse but it's still important to know how to do things in base R)
- [data transformation](figures/data-transformation.pdf) --> transforming data using `dplyr`

### Data camp courses

Expand All @@ -897,12 +893,10 @@ Compute the body mass index for `masculine` characters who are `human`.
- [Chapters 9-15 in "R for Data Science"](https://r4ds.had.co.nz/wrangle-intro.html)
- [Chapter 5 in "Data Visualization - A practical introduction"](http://socviz.co/workgeoms.html#workgeoms)

### Misc

- [Tidyverse style guide](https://style.tidyverse.org/)
## Session info

## Session info
Information about this R session including which version of R was used, and what packages were loaded.

```{r, echo=F}
```{r}
sessionInfo()
```
40 changes: 21 additions & 19 deletions 05-data_wrangling2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -620,35 +620,37 @@ save(df.test, df.starwars, file = "data/test_starwars.RData")

## Additional resources

### Cheatsheets
### Cheatsheets

- [wrangling data](figures/cheatsheets/data-wrangling.pdf) --> wrangling data using `dplyr` and `tidyr`
- [importing & saving data](figures/cheatsheets/data-import.pdf) --> importing and saving data with `readr`
- [wrangling data](figures/data-wrangling.pdf) --> wrangling data using `dplyr` and `tidyr`
- [importing & saving data](figures/data-import.pdf) --> importing and saving data with `readr`

### Data camp courses
### Data camp courses

- [Joining tables](https://www.datacamp.com/courses/joining-data-in-r-with-dplyr)
- [writing functions](https://www.datacamp.com/courses/writing-functions-in-r)
- [importing data 1](https://www.datacamp.com/courses/importing-data-in-r-part-1)
- [importing data 2](https://www.datacamp.com/courses/importing-data-in-r-part-2)
- [categorical data](https://www.datacamp.com/courses/categorical-data-in-the-tidyverse)
- [dealing with missing data](https://www.datacamp.com/courses/dealing-with-missing-data-in-r)
- [Joining tables](https://www.datacamp.com/courses/joining-data-in-r-with-dplyr)
- [writing functions](https://www.datacamp.com/courses/writing-functions-in-r)
- [importing data 1](https://www.datacamp.com/courses/importing-data-in-r-part-1)
- [importing data 2](https://www.datacamp.com/courses/importing-data-in-r-part-2)
- [categorical data](https://www.datacamp.com/courses/categorical-data-in-the-tidyverse)
- [dealing with missing data](https://www.datacamp.com/courses/dealing-with-missing-data-in-r)

### Books and chapters

- [Chapters 17-21 in R for Data Science](https://r4ds.had.co.nz/program-intro.html)
- [Exploratory data analysis](https://bookdown.org/rdpeng/exdata/)
- [R programming for data science](https://bookdown.org/rdpeng/rprogdatascience/)
- [Chapters 17-21 in R for Data Science](https://r4ds.had.co.nz/program-intro.html)
- [Exploratory data analysis](https://bookdown.org/rdpeng/exdata/)
- [R programming for data science](https://bookdown.org/rdpeng/rprogdatascience/)

### Tutorials
### Tutorials

- __Joining data__:
- [Two-table verbs](https://dplyr.tidyverse.org/articles/two-table.html)
- [Tutorial by Jenny Bryan](http://stat545.com/bit001_dplyr-cheatsheet.html)
- [tidyexplain](https://github.com/gadenbuie/tidyexplain): Animations that illustrate how `gather()`, `spread()`, `left_join()`, etc. work
- **Joining data**:

- [Two-table verbs](https://dplyr.tidyverse.org/articles/two-table.html)
- [Tutorial by Jenny Bryan](http://stat545.com/bit001_dplyr-cheatsheet.html)

- [tidyexplain](https://github.com/gadenbuie/tidyexplain): Animations that illustrate how `pivot_longer()`, `pivot_wider()`, `left_join()`, etc. work

## Session info

```{r data-wrangling2-47, echo=F}
```{r, echo=F}
sessionInfo()
```
22 changes: 9 additions & 13 deletions 06-probability.Rmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# Probability and causality

## Install and load packages, load data, set theme

Let's first install the new packages that you might not have yet.

```{r, eval=FALSE}
install.packages(c("arrangements", "kableExtra", "DiagrammeR"))
```
## Load packages, load data, set theme

Let's load the packages that we need for this chapter.

Expand Down Expand Up @@ -434,22 +428,24 @@ df.rain_given_sprinkler_and_rain %>%

### Cheatsheets

- [Probability cheatsheet](figures/cheatsheets/probability.pdf)
- [Probability cheatsheet](figures/probability.pdf)

### Books and chapters

- [Probability and Statistics with examples using R](http://www.isibang.ac.in/~athreya/psweur/)
- [Learning statistics with R: Chapter 9 Introduction to probability](https://learningstatisticswithr-bookdown.netlify.com/probability.html#probstats)
- [Elements of causal inference; pdf of book can be downloaded for free](https://mitpress.mit.edu/books/elements-causal-inference)

### Misc

- [Bayes' theorem in three panels](https://www.tjmahr.com/bayes-theorem-in-three-panels/)
- [Statistics 110: Probability; course at Harvard](https://projects.iq.harvard.edu/stat110)
- [Causal Diagrams: Draw Your Assumptions Before Your Conclusions; Free online course on causal inference](https://www.edx.org/course/causal-diagrams-draw-your-assumptions-before-your)
- [An introduction to Causal inference; Excellent blog post on causal inference](https://fabiandablander.com/r/Causal-Inference.html)
- [Bayes theorem and making probability intuitive](https://www.youtube.com/watch?v=HZGCoVF3YvM&feature=youtu.be)
- [Causal inference with Bayes rule](https://gradientinstitute.org/blog/6/)

## Session info

## Session info
Information about this R session including which version of R was used, and what packages were loaded.

```{r probability-21, echo=F}
```{r, echo=F}
sessionInfo()
```
Loading

0 comments on commit f8c18a9

Please sign in to comment.