Here you can download the available source code and other material for main posts as zip folders.

Available source code
  1. The birthday problem — Part 3: Calculating in steps
  2. The birthday problem — Part 2: The statistical shortcut
  3. How to get data from websites (fast)
  4. Football goals and coin flips: discovering the law of rare events
  5. The birthday problem — Part 1: When counting fails
  6. Drawing random biscuits: from probability to data

Prerequisites

  • The R language and the RStudio integrated development environment (IDE) must be installed. Find them following the links below:

  • R packages knitr and rmarkdown must be installed. Install them by running install.packages(c("knitr","rmarkdown")) in the RStudio console.

Description

Each zip folder contains a file named “index.Rmd”. This is an RMarkdown document with the main text and code chunks to recreate the full HTML document. Other contents may be:

  • A subfolder named “scripts”. This contains scripts with R code used during rendering of “index.Rmd”. Code chunks in “index.Rmd” may run code from these scripts.

  • Other possible data used for rendering the HTML page, for example images or data.

Instructions

  1. Download and unzip the zip folder.

  2. Open file “index.Rmd” with RStudio.

  3. Install R packages that are necessary for the code to run. These are noted in 1st code chunk. Run install.packages(c("package.1","package.2",...)) in the R console (substituting "package.1", "package.2",... with the actual package names). Make sure to add quote marks around each package name.

  4. Play around: Try your own modifications to the code chunks of “index.Rmd” or to the linked scripts. When finished, select File > Knit Document to render the RMarkdown document into HTML.

    Result: A file named “index.html” should be created in the same folder.

    Note: I try to optimize the code for minimal repetition of computationally-intensive tasks (within reason) during re-rendering to HTML. This means that once such a task is finished (e.g. creating a data set, image, or animation), its result is stored in a file for future reading. If such a file already exists during rendering, it is read and not created anew. If you want to create new such files, delete or rename the original ones, so they are not detected during rendering.

  5. View “index.html” with any HTML browser.