Skip to content

Commit

Permalink
include example for quarto exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
archaeothommy committed Sep 15, 2024
1 parent ae0d5bf commit 5d92c79
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _freeze/assets/report/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "043ebefe1245c4fcad7c4f52d5bbb1d7",
"result": {
"markdown": "---\ntitle: \"Random report\"\nauthor: \n - name: Jane Doe\n orcid: 0000-0001-2345-6789\n corresponding: true\n email: [email protected]\n \n---\n\n\n<!-- \n\nInstructions for the exercise\n\n1. Move the file to the top level of your repository\n4. Update the file _quarto.yml in your repository to include the report in your webpage\n2. Load a dataset from https://github.com/Hezel2000/GeoCosmoChemDataAndTools/tree/main/csv\n3. Update the YAML header of this file\n3. Create a short report, including plots created from the dataset (they can be interactive if you want -- the result is a webpage)\n a. You can use the example code chunks below as inspiration and for reference for the chunk options\n b. You might the following pages useful for reference: \n Figures: https://quarto.org/docs/authoring/figures.html\n Tables: https://quarto.org/docs/authoring/tables.html\n\nThe remainder of the document is a small example of how it might look like and provides some help to get started. Compare the unrendered and the rendered version to learn how it looks like! \n\nBy the way, to include Python code, replace write `python` instead of `r` in the curly brackets at the top of a code chunk. \n\n--> \n\n## The randomness of R\n\nBecause there must be some content for inspiration, let's see how random random numbers in R really are. \n\n## Uniformly distributed random numbers\n\nUniformly distributed random number means that all number have the same chance to get drawn from the pool. There are multiple methods to produce such numbers. \n\nThe most common command to create a uniform distribution of random numbers in R is `runif()`, standing for **r**andom **unif**orm. There is also the command `sample()` which is a bit more complex and therefore not further discussed here. \n\nBy default, `runif()` samples the range from 0 to 1: \n\n\n::: {.cell}\n\n```{.r .cell-code}\nrunif(1)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 0.9265252\n```\n:::\n\n```{.r .cell-code}\nrunif(10)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n [1] 0.02101488 0.27730595 0.11794147 0.75370403 0.46413168 0.59671102\n [7] 0.47710212 0.38529248 0.45986743 0.45998668\n```\n:::\n:::\n\n\nThis range can be changed by providing additional arguments: \n\n\n::: {.cell}\n\n```{.r .cell-code}\nrunif(1, min = 6, max = 9)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 6.761828\n```\n:::\n\n```{.r .cell-code}\nrunif(10, min = 4, max = 20)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n [1] 9.600644 19.682894 19.497662 14.913211 11.988543 19.399974 6.373147\n [8] 14.364414 10.415595 15.042221\n```\n:::\n:::\n\n\nSometimes, integers are needed. This can be achieved with \n\n\n::: {.cell}\n\n```{.r .cell-code}\nfloor(runif(1, min = 1, max = 6))\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 2\n```\n:::\n:::\n\n\nWith this information, let's see how random R throws a D20! \n\n\n::: {.cell layout-ncol=\"2\"}\n::: {.cell-output-display}\n![10 rolls](report_files/figure-html/unnamed-chunk-4-1.png){width=672}\n:::\n\n::: {.cell-output-display}\n![100 rolls](report_files/figure-html/unnamed-chunk-4-2.png){width=672}\n:::\n\n::: {.cell-output-display}\n![1000 rolls](report_files/figure-html/unnamed-chunk-4-3.png){width=672}\n:::\n\n::: {.cell-output-display}\n![10000 rolls](report_files/figure-html/unnamed-chunk-4-4.png){width=672}\n:::\n:::\n\n\nAnd now let's check if the distribution is consistent within the same number of rolls: \n\n\n::: {.cell layout-ncol=\"5\"}\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-2.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-3.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-4.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-5.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-6.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-7.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-8.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-9.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-5-10.png){width=672}\n:::\n:::\n\n\n# Normally distributed random numbers\n\nR cannot also create numbers from a normal distribution with the command `rnorm()` (= **r**andom **normal**). The syntax of the function is similar to `runif()` but instead of defining minimum and maximum of a function, we give the mean and the standard deviation ($sd$) of the normal distribution: \n\n\n::: {.cell}\n\n```{.r .cell-code}\nrnorm(5)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 0.09820888 1.14904771 0.57652705 -0.50144593 -0.31721441\n```\n:::\n\n```{.r .cell-code}\nrnorm(5, mean = 50, sd = 5)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 44.05445 47.36258 55.18560 56.04320 54.03772\n```\n:::\n:::\n\n\nLet's repeat the same test as above: \n\n\n::: {.cell layout-ncol=\"2\"}\n::: {.cell-output-display}\n![10 draws](report_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n\n::: {.cell-output-display}\n![100 draws](report_files/figure-html/unnamed-chunk-7-2.png){width=672}\n:::\n\n::: {.cell-output-display}\n![1000 draws](report_files/figure-html/unnamed-chunk-7-3.png){width=672}\n:::\n\n::: {.cell-output-display}\n![10000 draws](report_files/figure-html/unnamed-chunk-7-4.png){width=672}\n:::\n:::\n\n\nAnd performance in repeated identical draws. However, this time we will draw 50 times because 10 is too few to make the normal distribution visible: \n\n\n::: {.cell layout-ncol=\"5\"}\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-1.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-2.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-3.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-4.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-5.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-6.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-7.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-8.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-9.png){width=672}\n:::\n\n::: {.cell-output-display}\n![](report_files/figure-html/unnamed-chunk-8-10.png){width=672}\n:::\n:::\n\n\n\nIf you forgot how the standard deviation is calculated (and because I wanted to include a more complex formula for instructive purposes): \n\n$$\n\\sigma = \\sqrt{\\frac{\\sum{(x_i-\\mu)^2}}{N}} \n$$\nwith: \n\n| Symbol || Explanation |\n|----:|----|:----|\n|$\\sigma$| = | Population standard deviation| \n|$N$| = | Size of population |\n|x~i~| = | each value from the population |\n|µ| = | mean of the population |\n\n# Conclusions\nAs expected, the number from random distributions are pretty random \n\nHave fun while doing the exercise and don't hesitate to ask for help! \n",
"supporting": [
"report_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions assets/report.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
title: "Random report"
author:
- name: Jane Doe
orcid: 0000-0001-2345-6789
corresponding: true
email: [email protected]

---

<!--
Instructions for the exercise
1. Move the file to the top level of your repository
4. Update the file _quarto.yml in your repository to include the report in your webpage
2. Load a dataset from https://github.com/Hezel2000/GeoCosmoChemDataAndTools/tree/main/csv
3. Update the YAML header of this file
3. Create a short report, including plots created from the dataset (they can be interactive if you want -- the result is a webpage)
a. You can use the example code chunks below as inspiration and for reference for the chunk options
b. You might the following pages useful for reference:
Figures: https://quarto.org/docs/authoring/figures.html
Tables: https://quarto.org/docs/authoring/tables.html
The remainder of the document is a small example of how it might look like and provides some help to get started. Compare the unrendered and the rendered version to learn how it looks like!
By the way, to include Python code, replace write `python` instead of `r` in the curly brackets at the top of a code chunk.
-->

## The randomness of R

Because there must be some content for inspiration, let's see how random random numbers in R really are.

## Uniformly distributed random numbers

Uniformly distributed random number means that all number have the same chance to get drawn from the pool. There are multiple methods to produce such numbers.

The most common command to create a uniform distribution of random numbers in R is `runif()`, standing for **r**andom **unif**orm. There is also the command `sample()` which is a bit more complex and therefore not further discussed here.

By default, `runif()` samples the range from 0 to 1:

``` {r}
runif(1)
runif(10)
```

This range can be changed by providing additional arguments:

``` {r}
runif(1, min = 6, max = 9)
runif(10, min = 4, max = 20)
```

Sometimes, integers are needed. This can be achieved with

``` {r}
floor(runif(1, min = 1, max = 6))
```

With this information, let's see how random R throws a D20!

``` {r}
#| layout-ncol: 2
#| fig-cap:
#| - "10 rolls"
#| - "100 rolls"
#| - "1000 rolls"
#| - "10000 rolls"
#| echo: false
hist(runif(10, min = 1, max = 20), breaks = seq(from = 0.5, to = 20.5), main = NULL)
hist(runif(100, min = 1, max = 20), breaks = seq(from = 0.5, to = 20.5), main = NULL)
hist(runif(1000, min = 1, max = 20), breaks = seq(from = 0.5, to = 20.5), main = NULL)
hist(runif(10000, min = 1, max = 20), breaks = seq(from = 0.5, to = 20.5), main = NULL)
```

And now let's check if the distribution is consistent within the same number of rolls:

``` {r}
#| layout-ncol: 5
#| echo: false
for (i in seq_along(1:10)) {
hist(runif(10, min = 1, max = 20), breaks = seq(from = 0.5, to = 20.5), main = NULL)
}
```

# Normally distributed random numbers

R cannot also create numbers from a normal distribution with the command `rnorm()` (= **r**andom **normal**). The syntax of the function is similar to `runif()` but instead of defining minimum and maximum of a function, we give the mean and the standard deviation ($sd$) of the normal distribution:

``` {r}
rnorm(5)
rnorm(5, mean = 50, sd = 5)
```

Let's repeat the same test as above:

``` {r}
#| layout-ncol: 2
#| fig-cap:
#| - "10 draws"
#| - "100 draws"
#| - "1000 draws"
#| - "10000 draws"
#| echo: false
hist(rnorm(10, mean = 50, sd = 5), main = NULL)
hist(rnorm(100, mean = 50, sd = 5), main = NULL)
hist(rnorm(1000, mean = 50, sd = 5), main = NULL)
hist(rnorm(10000, mean = 50, sd = 5), main = NULL)
```

And performance in repeated identical draws. However, this time we will draw 50 times because 10 is too few to make the normal distribution visible:

``` {r}
#| layout-ncol: 5
#| echo: false
for (i in seq_along(1:10)) {
hist(rnorm(50, mean = 50, sd = 5), main = NULL)
}
```


If you forgot how the standard deviation is calculated (and because I wanted to include a more complex formula for instructive purposes):

$$
\sigma = \sqrt{\frac{\sum{(x_i-\mu)^2}}{N}}
$$
with:

| Symbol || Explanation |
|----:|----|:----|
|$\sigma$| = | Population standard deviation|
|$N$| = | Size of population |
|x~i~| = | each value from the population |
|µ| = | mean of the population |

# Conclusions
As expected, the number from random distributions are pretty random

Have fun while doing the exercise and don't hesitate to ask for help!

0 comments on commit 5d92c79

Please sign in to comment.