"The goal of reproducible research is to tie specific instructions to data analysis and experimental data so that scholarship can be recreated, better understood and verified." Max Kuhn, CRAN Task View: Reproducible Research
- Mathematics (400 BC?)
- Write scientific paper, Galileo, Pasteur, etc. (1660s?)
- Publish a pidgin algorithm and describe simulation datasets (1950s?)
- Sell magtape of code and data (1970s?)
- Place idiosyncratic dataset & software at website (1990s?)
- Publish datasets and scripts at website, eg. biology, political science, genetics, statistics (2000s?)
- Hosted integrated code and data (2020s?)
Gavish & Gonoho AAAS 2011, Oxberry 2013
"An article about computational result is advertising, not scholarship. The actual scholarship is the full software environment, code and data, that produced the result." Claerbout and Karrenbach, Proceedings of the 62nd Annual International Meeting of the Society of Exploration Geophysics. 1992
- Verification & Reliability: Find and fix bugs. Today's results == tomorrow's.
- Transparency: increased citation count, broader impact, improved institutional memory
- Efficiency: Reduces duplication of effort. Payoff in the (not so) long run
- Flexibility: When you don’t 'point-and-click' you gain many new analytic options.
Technical
- Classified/sensitive/big data
- Nondisclosure agreements & intellectual property
- Software licensing issues
- Competition
- Neither necessary nor sufficient for correctness (but useful in disputes)
Cultural & personal
- Few follow even minimal reproducibility standards.
- Few expect reproducibility
- No uniform standards
- Inertia & embarassment
Peng 2011, Science 334(6060) pp. 1226-1227
http://www.stodden.net/AMP2011/slides/pengslides.pdf
- Enter data in Excel
- Use Excel for data cleaning & descriptive statistics
- Import data into SPSS/SAS/Stata for further analysis
- Use point-and-click options to run statistical analyses
- Copy & paste output to Word document, repeatedly
- Version control is ad hoc
- Excel handles missing data inconsistently and sometimes incorrectly
- Excel uses poor algorithms for many functions
- Scripting is possible but rare
- Lots of human effort for tedious & time-wasting tasks
- Error-prone due to manual & ad hoc data handling
- Difficult to record - hard to reconstruct a 'click history'
- Tiny changes in data or method require extensive reworking
- 2010: Claimed high debt-to-GDP ratios led to low GDP growth
- Threshold to growth at a debt-to-GDP ratio of >90%
- Substantial popular impact on autsterity politics
Excel coding error sliced several countries out of the data set.... The Economist
In May 2015 Science retracted a study of how canvassers can sway people's opinions about gay marriage published just 5 months ago.
- Original survey data not made available for independent reproduction of results
- Survey incentives misrepresented
- Sponsorship statement false.
- Science Editor-in-Chief Marcia McNutt
Two Berkeley grad students who attempted to replicate the study quickly discovered that the data must have been faked.
"The article has been retracted at the request of the authors. After carefully re-examining the data presented in the article, they identified that data of two different hospitals got terribly mixed. The published results cannot be reproduced in accordance with scientific and clinical correctness."" Authors of Low Dose Lidocaine for Refractory Seizures in Preterm Neonates
Authors informed the journal that the merge of lab results and other survey data used in the paper resulted in an error regarding the identification codes. Results of the analyses were based on the data set in which this error occurred.
"Lower levels of CSF IL-6 were associated with current depression and with future depression […]" Original conclusion
"Higher levels of CSF IL-6 and IL-8 were associated with current depression […]" Revised conclusion
- Plain text files readable for a long time
- Improved transparency, automation, maintanability, accessibility, standardisation, modularity, portability, efficiency, communicability of process (what more could we want?)
- Steeper learning curve
"Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do." Donald E. Knuth, Literate Programming, 1984
For example... Let's calculate the current time in R.
time <- format(Sys.time(), "%a %d %b %X %Y")The text and R code are interwoven in the output:
The time is `r time`
The time is Mon 28 Nov 12:51:26 2016
For
- Text & code in one place, in logical order
- Tables and figures automatically updated
- Automatic test when building document
Against
- Text and code in one place; can be hard to read
- Can slow down the processing of documents (use caching!)
The machine-readable part: R
- R: Free, open source, cross-platform, highly interactive, huge user community in academica and private sector
- R packages an ideal 'Compendium'?
- Scriptability → R
- Literate programming → R Markdown
- Version control → Git / GitHub
"both a container for the different elements that make up the document and its computations (i.e. text, code, data, etc.), and as a means for distributing, managing and updating the collection... allow us to move from an era of advertisement to one where our scholarship itself is published" Gentleman and Temple Lang 2004
Markdown: lightweight document formatting syntax. Easy to write, read and publish as-is.
The human-readable part
rmarkdown:
- minor extensions to allow R code display and execution
- embed images in html files (convenient for sharing)
- equations
e.g.
*for bullet_for underline
knitr - descendant of Sweave
Engine for dynamic report generation in R
- Narrative and code in the same file or explicitly linked
- When data or narrative are updated, the document is automatically updated
- Data treated as 'read only'
- Output treated as disposable
A universal document converter, open source, cross-platform
- Write code and narrative in rmarkdown
- knitr->markdown (with computation)
- use pandoc to get HTML/PDF/DOCX
Payoffs
- Eases collaboration
- Can track changes in any file type (ideally plain text)
- Can revert file to any point in its tracked history
Costs
- Learning curve
- integrated R console
- deep support for markdown and git
- package development tools, etc. etc.
RStudio 'projects' make version control & document preparation simple
Payoffs
- Free space for hosting (and paid options)
- Assignment of persistent DOIs
- Tracking citation metrics
Costs
- Sometimes license restrictions (CC-BY & CC0)
- Limited or no private storage space
- Good: Use code with an integrated development environment (IDE). Minimize pointing and clicking (RStudio)
- Better: Use version control. Help yourself keep track of changes, fix bugs and improve project management (RStudio & Git & GitHub or BitBucket)
- Best: Use embedded narrative and code to explicitly link code, text and data, save yourself time, save reviewers time, improve your code. (RStudio & Git & GitHub or BitBucket & rmarkdown & knitr & data repository)
Reproducible Research Standard (Stodden 2009)
- The full compendium on the internet
- Media such as text, figures, tables with Creative Commons Attribution license (CC-BY)
- Code with one of Apache 2.0, MIT, LGPL, BSD, etc.
- Original "selection and arrangement" of data with CC0 or CC-BY
Promote culture change through positive attribution
Implement mechanisms to indicate & encourage degrees of compliance (ie. clear definitions for different levels of reproducibility), cf. Stodden's:
- 'Reproducible': compendium of text-code-data online
- 'Reproduced': compendium available and independently reproduced
- 'Semi-Reproducible': when the full compendium is not released
- 'Semi-Reproduced': independent reproduction with other data
- 'Perpetually Reproducible': streaming data
- Train students by putting homework, assignments & dissertations on the reproducible research spectrum
- Publish examples of reproducible research in our field
- Request code & data when reviewing
- Submit to & review for journals that support reproducible research
- Critically review & audit data management plans in grant proposals
- Consider reproducibility wherever possible in hiring, promotion & reference letters.
The R Script associated with this page is available here. Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.
Cheatsheet:
https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf
File -> New File -> RMarkdown -> Document -> HTML
All R code to be run must be in a code chunk like this:
#```{r,eval=F}
CODE HERE
#```Load these packages in a code chunk (you may need to install some packages):
library(dplyr)
library(ggplot2)
library(maps)
library(spocc)Do you think you should put
install.packages()calls in your script?
Now use the occ() function to download all the occurrence records for the American robin (Turdus migratorius) from the Global Biodiversity Information Facility.
Licensed under CC BY-SA 3.0 via Wikimedia Commons
## define which species to query
sp='Turdus migratorius'
## run the query and convert to data.frame()
d = occ(query=sp, from='ebird',limit = 1000) %>% occ2df()This can take a few seconds.
# Load coastline
map=map_data("world")
ggplot(d,aes(x=longitude,y=latitude))+
geom_polygon(aes(x=long,y=lat,group=group,order=order),data=map)+
geom_point(col="red")+
coord_equal()## Warning: Ignoring unknown aesthetics: order
Update the YAML header to keep the markdown file
From this:
title: "Untitled"
author: "Adam M. Wilson"
date: "October 31, 2016"
output: html_documentTo this:
title: "Demo"
author: "Adam M. Wilson"
date: "October 31, 2016"
output:
html_document:
keep_md: trueAnd click knit HTML to generate the output
- Use the Cheatsheet to add sections and some example narrative.
- Try changing changing the species name to your favorite species and re-run the report.
- Add more figures or different versions of a figure
- Check out the
kable()function for tables (e.g.kable(head(d)))
Abandoning the habit of secrecy in favor of process transparency and peer review was the crucial step by which alchemy became chemistry.Raymond, E. S., 2004, The art of UNIX programming: Addison-Wesley.
- Slides based on Ben Marwick's presentation to the UW Center for Statistics and Social Sciences (12 March 2014) (OrcID)
See Rmd file for full references and sources
























