-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
244 changed files
with
10,327 additions
and
10,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
--- | ||
aliases: | ||
- data-wrangling.html | ||
--- | ||
# Data Wrangling | ||
|
||
```{r} | ||
|
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
--- | ||
aliases: | ||
- tidy-data.html | ||
--- | ||
# Tidy data | ||
|
||
```{r} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
--- | ||
aliases: | ||
- functional-programming.html | ||
--- | ||
|
||
# Functional Programming | ||
|
||
```{r} | ||
|
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 4 additions & 0 deletions
4
probability-and-hypothesis-testing.qmd → 05-probability-and-hypothesis-testing.qmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
--- | ||
aliases: | ||
- probability-and-hypothesis-testing.html | ||
--- | ||
# Probability and Hypothesis Testing | ||
|
||
|
||
|
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 4 additions & 0 deletions
4
...ummaries-and-dimensionality-reduction.qmd → ...ummaries-and-dimensionality-reduction.qmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 4 additions & 0 deletions
4
fallacies-correlation-and-regression.qmd → 07-fallacies-correlation-and-regression.qmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
--- | ||
aliases: | ||
- fallacies-correlation-and-regression.html | ||
--- | ||
# Fallacies, Correlation and Regression | ||
|
||
|
||
|
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
--- | ||
aliases: | ||
- freestyle.html | ||
--- | ||
# Freestyle | ||
|
||
```{r} | ||
|
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Large diffs are not rendered by default.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
_freeze/04-functional-programming/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
14 changes: 14 additions & 0 deletions
14
_freeze/05-probability-and-hypothesis-testing/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
18 changes: 18 additions & 0 deletions
18
_freeze/06-distributions-summaries-and-dimensionality-reduction/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
14 changes: 14 additions & 0 deletions
14
_freeze/07-fallacies-correlation-and-regression/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "161c6633465786a87ad4107fe3a9c241", | ||
"result": { | ||
"markdown": "---\naliases:\n - freestyle.html\n---\n\n# Freestyle\n\n\n\n\n\n> ... in which we learn about ANOVA, explore ggplot extensions and\n build and interactive web application with Shiny.\n\n\n{{< youtube gZ0u6b_1ej4 >}}\n\n\n\n## Setup\n\nToday we are using quite a bunch of packages.\nIn the lecture these are of course introduced one by one,\nbut because it is a good habit to have all your imports\nand dependencies near the top of your analysis they\nshow up here already.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-2_08c857bd8c93e82cee1d4f05eb13f5c8'}\n\n```{.r .cell-code}\nlibrary(multcomp)\nlibrary(patchwork)\nlibrary(gganimate)\nlibrary(palmerpenguins)\nlibrary(broom)\nlibrary(tidyverse)\n```\n:::\n\n\n## ANOVA\n\nLet's get started.\nANOVA stands for Analysis of Variance.\nWe start with our familiar penguins dataset and ask\nthe question: \"Is there a difference in bill length between the species?\"\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-3_027cbae8c1b9482d793f4bd6e1e7f02a'}\n\n```{.r .cell-code}\npenguins %>% \n ggplot(aes(species, bill_length_mm)) +\n geom_boxplot(outlier.color = NA) +\n geom_jitter(alpha = 0.2, width = 0.2)\n```\n\n::: {.cell-output-display}\n{width=100%}\n:::\n:::\n\n\nOptically, it certainly looks like it.\nWe could run a bunch of t-tests to compare between the groups,\nwhich would be 3 in total (Adelie–Chinstrap, Adelie–Gentoo, Gentoo–Chinstrap).\nAnd then we would have to correct for multiple testing.\nAt this point, only running one of tests (like Adelie vs. Chinstrap)\nbecause it looks so promising is not an option!\nLooking at the data visually is a form of comparison,\nso we would be cheating if we formed our hypothesis only after\nlooking at the data.\n\n**ANOVA** is a way of comparing multiple groups and tells us, if there\nis a difference at all between the groups.\nIt does not however tell us, between which groups the difference exists,\njust that there is an overall difference.\nIn order to get p-values for direct comparisons between the groups\nwe run a **post-hoc** (Latin for \"after the fact\") on our anova result.\n\nFirst I am sliding in a little extra code chunk, because later down\nthe line we might want to compare all groups to e.g. a baseline or\ncontrol group (see the section about Dunnet below) and this baseline\nis decided to be the first factor-level of the grouping variable.\nWith `fct_relevel` we can move a lovel to the first (or any other)\nposition.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-4_c91357273691af2dfb73d16ad16a8d20'}\n\n```{.r .cell-code}\npenguins <- penguins %>% \n mutate(species = fct_relevel(species, \"Gentoo\"))\n```\n:::\n\n\nNot we create an anova fit with `aov`.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-5_d7f5535449b932613d558b388d820c45'}\n\n```{.r .cell-code}\nanova_fit <- aov(bill_length_mm ~ species, data = penguins)\nanova_fit\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nCall:\n aov(formula = bill_length_mm ~ species, data = penguins)\n\nTerms:\n species Residuals\nSum of Squares 7194.317 2969.888\nDeg. of Freedom 2 339\n\nResidual standard error: 2.959853\nEstimated effects may be unbalanced\n2 observations deleted due to missingness\n```\n:::\n:::\n\n\nAnd explore if further with various functions.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-6_2cb474ed97caeccf7548df2040c475e7'}\n\n```{.r .cell-code}\nsummary(anova_fit)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n Df Sum Sq Mean Sq F value Pr(>F) \nspecies 2 7194 3597 410.6 <2e-16 ***\nResiduals 339 2970 9 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n2 observations deleted due to missingness\n```\n:::\n:::\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-7_eb58996257bce05f35e3c5e2268d4f4e'}\n\n```{.r .cell-code}\ntidy(anova_fit)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n# A tibble: 2 × 6\n term df sumsq meansq statistic p.value\n <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 species 2 7194. 3597. 411. 2.69e-91\n2 Residuals 339 2970. 8.76 NA NA \n```\n:::\n:::\n\n\n### Tukey Post-Hoc Test\n\nThe most straighforward post-hoc test, which is already built into R,\nis \"Tukey's Honest Significant Differences\",\nwhich compares all groups with all other groups.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-8_a7f53f7fdb3955a60a6951225d705abc'}\n\n```{.r .cell-code}\nTukeyHSD(anova_fit) %>% \n tidy()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n# A tibble: 3 × 7\n term contrast null.value estimate conf.low conf.high adj.p.value\n <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 species Adelie-Gentoo 0 -8.71 -9.56 -7.87 0 \n2 species Chinstrap-Gentoo 0 1.33 0.276 2.38 0.00890\n3 species Chinstrap-Adelie 0 10.0 9.02 11.1 0 \n```\n:::\n:::\n\n\n### Dunnet Post-Hoc Test\n\nIf we have a control group we use Dunnet's test to compare all other\ngroups to the control group.\nThis means we have to do less comparisons and end up with a higher statistical power.\n\nUnfortunately, Dunnet is not built into R, but we can get the necessary\nfunctions from the `multcomp` package.\nWhen loading the `multcomp` package we have to be careful\nto load it before the `tidyverse`!\nBecause `multcomp` also loads a bunch of other packages and one\nof them brings it's own `select` function, so loading it after\nthe `tidyverse` would overwrite tidyverse `select` and make our life very hard.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-9_83a4ce273295ee2a11ae887f24e2e4b6'}\n\n```{.r .cell-code}\nglht(anova_fit, mcp(species = \"Dunnet\")) %>% \n tidy()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n# A tibble: 2 × 7\n term contrast null.value estimate std.error statistic adj.p.value\n <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 species Adelie - Gentoo 0 -8.71 0.360 -24.2 -4.44e-16\n2 species Chinstrap - Gentoo 0 1.33 0.447 2.97 6.20e- 3\n```\n:::\n:::\n\n\nNote, that this package can also do Tukey's test by changing \"Dunnet\"\nto \"Tukey\".\n\n## ggplot extensions\n\nIn order to plot these nice significance stars on top of of our\ncomparisons let me first introduce you to ggplot extensions:\n\n<https://exts.ggplot2.tidyverse.org/>\n\nThis is just a collection of packages that extend ggplot in some shape or form\nor simply work very well with it.\n\n### `ggsignif`, `ggpubr`\n\nOne of these is `ggsignif`, which we can use to add comparison\nbrackets to our plot.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-10_1dad74f048066f456034c190305b1e38'}\n\n```{.r .cell-code}\npenguins %>% \n ggplot(aes(species, bill_length_mm)) +\n geom_boxplot(outlier.color = NA) +\n geom_jitter(alpha = 0.2, width = 0.2) +\n ggsignif::geom_signif(\n comparisons = list(c(\"Gentoo\", \"Adelie\")),\n annotations = c(\"hello\")\n )\n```\n\n::: {.cell-output-display}\n{width=100%}\n:::\n:::\n\n\n`ggsignif` can also run it's own comparisons, which is\na wilcoxon rank sum test by default, but especially\nfor statistical tests I prefer to run them myself first\nbefore trusting more packages.\nAdditionally, we have of course a different type of test (ANOVA),\nand we already have our values, so we use it just to manually\nadd text to the annotation:\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-11_b9da96b8537f258e0ba046f68bcdcd39'}\n\n```{.r .cell-code}\nstars <- function(p) {\n case_when(\n p <= 0.001 ~ \"***\",\n p <= 0.01 ~ \"**\",\n p <= 0.05 ~ \"*\",\n TRUE ~ \"ns\"\n )\n}\n\ndunnet <- glht(anova_fit, mcp(species = \"Dunnet\")) %>% \n tidy() %>% \n mutate(contrast = str_split(contrast, \" - \"),\n stars = stars(adj.p.value))\n\nplt <- penguins %>% \n ggplot(aes(species, bill_length_mm)) +\n geom_boxplot(outlier.color = NA) +\n geom_jitter(alpha = 0.2, width = 0.2) +\n ggsignif::geom_signif(\n comparisons = dunnet$contrast,\n annotations = dunnet$stars,\n y_position = c(60, 65)\n )\n\nplt\n```\n\n::: {.cell-output-display}\n{width=100%}\n:::\n:::\n\n\n\n### `patchwork`\n\nI also saved the plot to a variable and will now create a second\none just to show you the `patchwork` package,\nwhich can combine plots into neat layouts:\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-12_63069b65485402115238123db3a825e5'}\n\n```{.r .cell-code}\nplt2 <- ggplot(penguins, aes(bill_length_mm, bill_depth_mm, color = species)) +\n geom_point()\n\n((plt | plt2) / plt2 ) + plot_layout(guides = 'collect')\n```\n\n::: {.cell-output-display}\n{width=100%}\n:::\n:::\n\n\n### `ggfortify`\n\n`ggfortiy` might not strictly be necessary but I want to mention it\nto talk about `autoplot`.\n`autoplot` is in `ggplot2` already by default.\nIt creates automatic plot for certain objects, like models for example,\nor an anova result.\n`ggfortify` makes more objects have the ability to generate an autoplot.\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-13_c3ca7fecf31b7e42378ec3bcadaa74ed'}\n\n```{.r .cell-code}\nlibrary(ggfortify)\nautoplot(anova_fit)\n```\n\n::: {.cell-output-display}\n{width=100%}\n:::\n:::\n\n\nI want to mention this here because it has an important implication\nfor communication.\nThere are two purposes too plots.\nThe first purpose is to generate insight for you, the data analyst.\nAutoplots are often very helpful for this.\nBut the second purpose is to communicate your findings to a reader!\nIt takes time and effort to refine a plot from something that generated\nand insight for you after having spent a lot of time with your data\nto also generating insights for a reader that sees the data for the first time.\nToo many people stop at the first step and publish their plots\nas is, without thinking much about the reader.\nKeep this in mind as you advance in your scientific career.\n\n> Communication is key!\n Both code and plots are means of communicating.\n\n### `esquisse`\n\nTwo more cool packages: The `esquisse` package let's you\ncreate ggplots interactively with a gui!\nBut make sure to always save the code this created to ensure\nreproducibility!\n\n### `gganimate`\n\nAnd `gganimate` extends `ggplot` with the ability to use time as a dimension:\n\n\n::: {.cell hash='08-freestyle_cache/html/unnamed-chunk-14_806c52eaab651699342d98da123cfaa0'}\n\n```{.r .cell-code}\ngapminder::gapminder %>% \n ggplot(aes(gdpPercap, lifeExp, size = pop, color = country)) +\n geom_point() +\n scale_x_log10() +\n transition_time(year) +\n scale_color_manual(values = gapminder::country_colors) +\n guides(color = \"none\",\n size = \"none\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nNULL\n```\n:::\n:::\n\n\n## Build Apps with `shiny`\n\nYou can find the code written during the lecture in: `example-app/`.\n\n## Exercises\n\n### The Whole Deal\n\nData analysis takes practice.\nFor this last exercise you get the option to show what you\nhave learned on a fresh dataset.\nBut people have different interests, so I am leaving\nthe choice open.\n\nChoose a dataset from the TidyTuesday project:\n\n<https://github.com/rfordatascience/tidytuesday#datasets>\n\nand write your data analysis report.\nAim to write down some questions you have about the\ntopic and answer them with the available data.\nExplore it with plots and tables and try\nto end up with 1 or 2 high quality plots\nthat clearly communicate you findings.\nAbove all, have fun!\n\n## Feedback\n\nI will send round a link for a feedback form.\nIt is anonymous.\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed
BIN
-24.7 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-11-1.png
Diff not rendered.
Binary file removed
BIN
-118 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-19-1.png
Diff not rendered.
Binary file removed
BIN
-48.3 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-22-1.png
Diff not rendered.
Binary file removed
BIN
-54.8 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-26-1.png
Diff not rendered.
Binary file removed
BIN
-42.4 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-26-2.png
Diff not rendered.
Binary file removed
BIN
-64 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-31-1.png
Diff not rendered.
Binary file removed
BIN
-64 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-36-1.png
Diff not rendered.
Binary file removed
BIN
-94 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-40-1.png
Diff not rendered.
Binary file removed
BIN
-88.3 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-45-1.png
Diff not rendered.
Binary file removed
BIN
-54.8 KB
...summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-47-1.png
Diff not rendered.
Binary file removed
BIN
-80.2 KB
...-summaries-and-dimensionality-reduction_files/figure-html/unnamed-chunk-7-1.png
Diff not rendered.
Oops, something went wrong.