Overview

Teaching: 20 min
Exercises: 20 min
Questions
  • What is reproducible research?

  • What are the keys to reproducible research?

Objectives
  • Learn the four facets of reproducibility.

As you arrive, please make sure the following R packages are installed:

install.packages("tidyverse")

Motivating Reproducibility

Science retracts paper without agreement of lead author.

Retracted, but not fraud

Seizure study retracted after authors realized data were “Terribly mixed”

Bad spreadsheet merge kills depression paper, quick fix resurrects it

Exercise: Motivating reproducibility

This is a two-part exercise:

Part 1: Analyze + Document

Complete the following tasks and write instructions / documentation for your collaborator to reproduce your work starting with the original dataset (data/gapminder-5060.csv): 1. Visualize life expectancy over time for Canada in the 1950s and 1960s using a line plot.

  1. Something is clearly wrong with this plot! Turns out there’s a data error in the data file: life expectancy for Canada in the year 1957 is coded as 999999, it should actually be 69.96. Make this correction.

  2. Visualize life expectancy over time for Canada again, with the corrected data.

Stretch goal: Add lines for Mexico and United States.

Solution

  1. Import Data
gap_5060 <- read.csv("../data/gapminder-5060.csv")
  1. Load required pacakges
library("tidyverse")
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
  1. Task 1 - Filter the data for Canada only:
gap_5060_CA <- gap_5060 %>% filter(country == "Canada")
  1. Task 1 - Visaualize:
ggplot(data = gap_5060_CA, aes(x = year, y = lifeExp)) +
   geom_line()

plot of chunk task_2_visualize Task 2. Something is clearly wrong with this plot! Turns out there’s a data error in the data file: life expectancy for Canada in the year 1957 is coded as 999999, it should actually be 69.96. Make this correction: - mutate for creating a new variables - replace for replacing a data entry in a specific location as determined by the logical statement (country == "Canada" & year == 1957)

gap_5060 <- gap_5060 %>%
  mutate(lifeExp = replace(lifeExp, (country == "Canada" & year == 1957), 69.96)) %>%
  as.data.frame()

Task 3. Visualize life expectancy over time for Canada again, with the corrected data. Exact same code as before, but note that the contents of gap_5060 are different as it has been updated in the previous task.

gap_5060_CA <- gap_5060 %>%
filter(country == "Canada")

ggplot(data = gap_5060_CA, aes(x = year, y = lifeExp)) +
  geom_line()

plot of chunk task_3 Task 3 - Stretch goal: Add lines for Mexico and United States. - %in% for logical operator testing if a country’s name is in the list provided - Same visualization code as before, only difference is the input dataset

gap_5060_NA <- gap_5060 %>%
  filter(country %in% c("Canada", "Mexico", "United States"))

ggplot(data = gap_5060_NA, aes(x = year, y = lifeExp, color = country)) +
  geom_line()

plot of chunk more_task_3

Part 2: Swap + discuss

Introduce yourself to your collaborator and tell them why you’re here.

  1. Swap instructions / documentation with your collaborator, and try to reproduce their work, first without talking to each other. If your collaborator does not have the software they need to reproduce your work, we encourage you to either help them install it or walk them through it on your computer in a way that would emulate the experience. (Remember, this could be part of the irreproducibility problem!)

  2. Then, talk to each other about challenges you faced (or didn’t face) or why you were or weren’t able to reproduce their work.

Reflection

Summary

Why we care

It is vital that scientific research be reproducible. This improves communication, openness, and transparency. We consider that there are four facets required to maximize reproducibility.

Four facets of reproducibility:

  1. Documentation: difference between binary files (e.g. docx) and text files and why text files are preferred for documentation.

  2. Organization: tools to organize your projects so that you don’t have a single folder with hundreds of files.

  3. Automation: the power of scripting to create automated data analyses.

  4. Dissemination: publishing is not the end of your analysis, rather it is a way station towards your future research and the future research of others.

Key Points