class: center, middle, inverse, title-slide # Reproducible research from project inception through publication: best practices for managing research data ### 2018-10-31 --- #### research data workflow: this is your world (or it will be soon) <img src="reproducibility_assets/figure-html/workflow.png" width="100%"> .footnote[J. Bryan from http://stat545.com/] --- * how do you keep that up-to-date? -- * what if something changes, what if something needs to be redone - how do you manage that? -- * why do the results in table 1 not seem to correspond to the results in figure 1? -- * why were those particular samples omitted? -- * where did I get these data? -- * how did I make that figure? --- #### research data workflow: this is your world (or it will be soon) - .light-blue[now add to that publishing your data and code] <img src="reproducibility_assets/figure-html/workflow_with_data.png" width="100%"> .footnote[J. Bryan from http://stat545.com/] --- background-image: url(https://media.giphy.com/media/MEtSuIu6qu0HC/giphy.gif) background-position: 50% 50% background-size: 50% class: inverse <br> basically, if the thought of redoing your analyses is terrifying 😱 then you are doing it wrong (paraphrasing Jenny Bryan) --- #### reproducibility * Replication is the cornerstone of scientific research, with consistent findings from independent investigators the primary means by which scientific evidence accumulates for or against a hypothesis. * The **replicability** of a study is related to the chance that an independent experiment targeting the same scientific question will produce a result consistent with the original study. * A variation of this concept, referred to as reproducibility, has emerged as a key minimum acceptable standard, especially for heavily computational research. * **Reproducibility** is defined as the ability to recompute data analytic results, given an observed data set and knowledge of the data analysis pipeline. .footnote[R. Peng [The reproducibility crisis in science: A statistical counterattack](10.1111/j.1740-9713.2015.00827.x)] --- #### reproducibility, for scientific reasons ##### given your data, someone else can reproduce your exact results * increased trustworthiness * more rigorous, reliable science * learning more from one another's work "Science should be 'show me', not 'trust me'; it should be 'help me if you can', not 'catch me if you can'." *-- Philip B. Stark, <a href="https://www.nature.com/articles/d41586-018-05256-0" target="_blank">Nature 2018</a>* .footnote[J. Thompson [bit.ly/jlt-rmed2018](bit.ly/jlt-rmed2018)] --- #### reproducibility, for personal reasons * Did I mention that subjects with IDs > 100 are actually kangaroos and should be excluded? * How does that patient have 15 months of treatment when we only followed people for 12 months? * I won the lottery 👏 - now my coworker is taking over * Journal reviews back after 8 months! Time for revisions! .footnote[J. Thompson [bit.ly/jlt-rmed2018](bit.ly/jlt-rmed2018)] --- #### what we will cover (okay, touch on) today * best practices + naming + open file formats + organization + thoughtful curation + scripting + spreadsheets (and other pointy, clicky stuff) + version control * data management plans * publishing data ... * literate programming --- #### BP [Best Practice] --- #### BP: naming things - principles for file (and other things) names -- * machine readable - regular expression and globbing friendly + avoid spaces, punctuation, accented characters, case sensivity - easy to compute on with deliberate use of delimiters + example: *2017-11-17_berneilwash_oxygen_day_1.csv* .footnote[J. Bryan [Naming things](https://speakerdeck.com/jennybc/how-to-name-files)] -- * human readable - names contain info about the content - easy to figure out what what something is based on the name + *2016_salmon_counts.csv* conveys a lot of information about the object, and has far more meaning than *fishData.csv* -- * play well with default ordering .pull-left[ - 1_file_name.csv - 11_file_name.csv - 2_file_name.csv ] .pull-right[ - 01_file_name.csv - 02_file_name.csv - 11_file_name.csv ] --- class: inverse #### BP: naming - names matter in times of stress which set of file(names)s would you prefer at 3 a.m. before a dealine? .center[ <img src="reproducibility_assets/figure-html/good_bad_names.png" width="85%"> ] .footnote[J. Bryan [Naming things](https://speakerdeck.com/jennybc/how-to-name-files)] --- #### BP: employ sound project organization *your closest collaborator is you six months ago, but you do not reply to emails (K. Broman paraphrasing M. Holder)* .pull-left[ <img src="reproducibility_assets/figure-html/projectOrganizationCropped.png" width="95%"> ] .pull-right[ .small[ * segregate all materials for a project in one directory * organize according to prevailing conventions (e.g., R package structure) * maintain a clear separation of data, method, and output while unambiguously expressing the relationship among them * specify the computational environment used for the original analysis * organize such that another person can know what to expect from the plain meaning of the file and directory names * include README files ]] .footnote[K. Broman [Steps toward reproducible research](bit.ly/jsm2016)] --- #### BP: keep the raw data raw * save the raw data .center[ <img src="reproducibility_assets/figure-html/Fleetwood-Mac-Cant-Go-Back-Love.jpg" width="70%"> ] .footnote[Wilson et al. (2017) [Good enough practices in scientific computing](https://doi.org/10.1371/journal.pcbi.1005510)] --- #### BP: thoughtful curation * curate your data in a way that you would like to receive it .center[ <img src="reproducibility_assets/figure-html/usgs.png" width="80%"> ] .footnote[Wilson et al. (2017) [Good enough practices in scientific computing](https://doi.org/10.1371/journal.pcbi.1005510)] --- #### BP: open file formats * use open file formats (e.g., csv not xlsx) <br> <br> .center[ <img src="reproducibility_assets/figure-html/paperclip.jpeg" width="45%"> ] .footnote[Wilson et al. (2017) [Good enough practices in scientific computing](https://doi.org/10.1371/journal.pcbi.1005510)] --- background-image: url(https://media.giphy.com/media/3orif8zlUQh32KTURy/giphy.gif) background-position: 50% 50% background-size: 50% class: inverse #### BP: record everything * record all the steps of the data process --- #### BP: everything in a script .light-blue[The most basic principle for reproducible research is: **do everything via code**] * downloading data from the web * converting an Excel file to CSV * renaming columns or variables * omitting bad samples or data points * *...do all of these with programatically* You will be tempted to open up a data file and hand-edit. But if you get a revised version of that file, you will need to do it again, and it will be harder to figure out what it was that you did. Some things are more cumbersome via code but you will save time in the long run. .footnote[K. Broman [Steps toward reproducible research](bit.ly/jsm2016)] --- #### BP: learn a language, any language, just do it .pull-left[ <img src="reproducibility_assets/figure-html/rlogo.jpg" width="100%"> ] .pull-right[ <img src="reproducibility_assets/figure-html/python-logo.png" width="70%"> ] --- #### spreadsheets: the dark side .center[ <img src="reproducibility_assets/figure-html/excel_errors_wash_post.png" width="80%"> ] --- #### spreadsheets: the 2nd best tool for everything .pull-left[ <img src="reproducibility_assets/figure-html/spreadsheet_hidden_data.png" width="100%"> ] .pull-right[ the beauty and the travesty of spreadsheets is that they allow you to do just about anything * data in merged cells * data in formatting * small multiples * data in formulas ] -- **BP: use open file formats (e.g., CSV, not XLSX)** .footnote[J. Bryan [Spreadsheets](https://speakerdeck.com/jennybc/spreadsheets)] --- #### spreadsheets versus scripting consider, we want to remove samples that we feel may have been contaminated... .pull-left[ **in a R script** <hr> ```r some work... ``` .small[*comment code:* .light-blue[remove samples 4 and 5 that may have been compromised due to wading upstream during sampling]] ```r chemistry_data %>% filter(!sampleID %in% c(4,5)) ``` ```r ...more work ``` ] .pull-right[ **in a spreadsheet** <hr> <img src="reproducibility_assets/figure-html/spreadsheet_remove_samples.png" width="105%"> ] --- class: inverse #### BP: version control .center[ <img src="reproducibility_assets/figure-html/CAP_renewal_screenshot.png" width="100%"> ] --- #### version control::git * git watches repositories (like a directory) for changes * git asks that you describe changes when they are made * git remembers old versions if you need them * git also keeps an eye out for conflicts, and forces you to resolve them .footnote[Jeff Goldsmith ["Git"](https://speakerdeck.com/jeffgoldsmith/dsi-git-and-github)] --- #### git + GitHub when combined with a service such as GitHub * ...allows multiple people to contribute to the same repository, and does all of the aforementioned for everyone at once .center[ <img src="reproducibility_assets/figure-html/git_collaboration.png" width="65%"> ] .footnote[Jeff Goldsmith ["Git"](https://speakerdeck.com/jeffgoldsmith/dsi-git-and-github)] --- #### version control: git .light-blue[tame the chaos] 👏 .center[ <img src="reproducibility_assets/figure-html/git_flow.png" width="80%"> ] --- class: inverse #### version control: git .center[ <img src="reproducibility_assets/figure-html/bokis_on_git.png" width="80%"> ] --- background-image: url(https://media.giphy.com/media/PnXRAFOJFCt3i/giphy.gif) background-position: 50% 50% background-size: 50% class: inverse #### I am not saying it is easy --- #### OHI: nature ecology & evolution .center[ <img src="reproducibility_assets/figure-html/lowndes_title.png" width="90%"> ] .footnote[Lowndes et al. (2017) [Our path to better science in less time using open data science tools](https://www.nature.com/articles/s41559-017-0160)] --- #### OHI: framework .center[ <img src="reproducibility_assets/figure-html/ohi_framework.png" width="90%"> ] .footnote[Lowndes et al. (2017) [Our path to better science in less time using open data science tools](https://www.nature.com/articles/s41559-017-0160)] --- #### OHI: evolution of a workflow .center[ <img src="reproducibility_assets/figure-html/lowndes_figure1.jpg" width="80%"> ] .footnote[Lowndes et al. (2017) [Our path to better science in less time using open data science tools](https://www.nature.com/articles/s41559-017-0160)] --- #### BP: forethought strive for reproducibility from the outset "It's not thinking, 'This is easiest for myself right now.' It's thinking, 'When I'm working on this next week, next month, right before I graduate — how do I set myself up so that it's easier later?' *-- Julia Stewart Lowndes in "A toolkit for data transparency takes shape", [Nature 2018](https://www.nature.com/articles/d41586-018-05256-0)* .footnote[J. Thompson [bit.ly/jlt-rmed2018](bit.ly/jlt-rmed2018)] --- #### Data Management Plan (DMP) "...a written document that describes the data you expect to acquire or generate during the course of a research project, how you will manage, describe, analyze, and store those data, and what mechanisms you will use at the end of your project to share and preserve your data." Stanford Libraries [Data Management Plans](https://library.stanford.edu/research/data-management-services/data-management-plans) * Describes how data will be: - Collected - Managed during the project - Preserved after completion .center[ <img src="reproducibility_assets/figure-html/dmp_tool.JPG" width="80%"> ] --- #### research data workflow: this is your world (or it will be soon) - .light-blue[now add to that publishing your data and code] <img src="reproducibility_assets/figure-html/workflow_with_data.png" width="100%"> .footnote[J. Bryan from http://stat545.com/] --- <!-- this starts the metadata + publishing lecture --> #### why publish data * big picture + increasingly a requirement + advancement of science * researcher perspective + papers with publicly available data receive a higher number of citations than similar studies lacking available data<sup>1</sup> + data sharing is associated with higher productivity<sup>1</sup> + [citeable product](https://portal.lternet.edu/nis/mapbrowse?packageid=knb-lter-cap.621.1) .footnote[<sup>1</sup>[Marwick et al. 2017](https://doi.org/10.7287/peerj.preprints.3192v1)] --- #### concerns about sharing data most common concerns can be addressed *with metadata* .pull-left[ .center[**concern**] <hr> * inappropriate use due to misunderstanding of research purpose or parameters * security and confidentiality of sensitive data * lack of acknowledgement / credit ] .pull-right[ .center[**solution**] <hr> * provide rich abstract, purpose, use constraints, and supplemental information * use constraints to specify who may access the data and how * specify a required data citation within the use constraints ] .footnote[[DataONE education modules](https://www.dataone.org/education-modules)] --- class: inverse <br> <br> <br> "Without clear instructions, many researchers struggle to avoid chaos in their file structures, and so are understandably reluctant to expose their workflow for others to see. This may be one of the reasons that so many requests for details about method, including requests for data and code, are turned down or go unanswered (Collberg & Proebsting 2016)." .footnote[[Marwick et al. 2017](https://doi.org/10.7287/peerj.preprints.3192v1)] --- #### what do we mean by data repository? <table> <thead> <tr> <th style="text-align:left;"> system </th> <th style="text-align:left;"> long.term </th> <th style="text-align:left;"> versioned </th> <th style="text-align:left;"> citable </th> <th style="text-align:left;"> discoverable </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Google Drive </td> <td style="text-align:left;"> maybe </td> <td style="text-align:left;"> maybe </td> <td style="text-align:left;"> no </td> <td style="text-align:left;"> no </td> </tr> <tr> <td style="text-align:left;"> GitHub </td> <td style="text-align:left;"> yes </td> <td style="text-align:left;"> yes </td> <td style="text-align:left;"> no </td> <td style="text-align:left;"> no </td> </tr> <tr> <td style="text-align:left;"> University Server </td> <td style="text-align:left;"> maybe </td> <td style="text-align:left;"> no </td> <td style="text-align:left;"> no </td> <td style="text-align:left;"> maybe </td> </tr> <tr> <td style="text-align:left;"> KNB* </td> <td style="text-align:left;"> yes </td> <td style="text-align:left;"> yes </td> <td style="text-align:left;"> yes </td> <td style="text-align:left;"> yes </td> </tr> </tbody> </table> .small[\*KNB (the Knowledge Network for Biocomplexity) is an international repository intended to facilitate ecological and environmental research] .footnote[[NCEAS crescynt-training](https://nceas.github.io/crescynt-training/)] --- #### where to publish? .center[ <img src="reproducibility_assets/figure-html/r3data.png" width="60%"> ] is wonderful but I would start with... * institutional resources * lab, colleagues * conferences --- #### metadata: the who, what, why, where, when - principal investigator - funding sources - data collector/producer - project description - sample and sampling procedures - weighting - substantive, temporal, and geographic coverage of the data collection - data source(s) - unit(s) of analysis/observation - variables - technical information on files - data collection instruments .footnote[B. Marshall [Metadata for Research Data](https://speakerdeck.com/bmarshall/metadata-for-research-data)] --- class: inverse <br> <br> <br> <br> "data without the contextual information needed to interpret it (and ultimately reproduce the results) is useless" .footnote[B. Marshall [Metadata for Research Data](https://speakerdeck.com/bmarshall/metadata-for-research-data)] --- #### what makes good metatadata? .light-grey[ - consistency with commonly used fields (e.g., YYYY-MM-DD) - use a standard vocabulary - spell out acronyms - provide all the critical information for: *identification; entities and attributes; data quality; data lineage; access, use, and liability constraints; accessing the data; spatial reference* - complete title: who, what, when, where, and scale - be specific, and quantify where possible - use descriptive and clear writing - fully document geographic locations - use keywords wisely (use a thesaurus when possible) - remember that a computer will read this: + avoid special characters + avoid tabs, indents, carriage returns + copy from a text file (not a file with rich text like Word or RTF) ] .light-blue[**detail, there is no such thing as too much!**] .footnote[[DataONE education modules](https://www.dataone.org/education-modules)] --- #### license .light-grey["...have a license file in the project's home directory that clearly states what license(s) apply to the project's software, data, and manuscripts. Lack of an explicit license does not mean there isn't one; rather, it implies the author is keeping all rights and others are not allowed to reuse or modify the material.] We recommend Creative Commons licenses for data and text, either CC-0 (the "No Rights Reserved" license) .light-grey[or CC-BY (the "Attribution" license, which permits sharing and reuse but requires people to give appropriate credit to the creators). For software, we recommend a permissive open source license such as the MIT, BSD, or Apache license..."] .footnote[Wilson et al. (2017) [Good enough practices in scientific computing](https://doi.org/10.1371/journal.pcbi.1005510)] --- #### literate programming a common approach <img src="reproducibility_assets/figure-html/literateProgramming.png"> .footnote[K. Healy [The Plain Person's Guide to Plain Text Social Science](https://kieranhealy.org/files/papers/plain-person-text.pdf)] --- #### literate programming * the problem is that the gaps are particularly prone to errors * literate programming is essentially the integration of code and text <small>Knuth, D. E. (1992), Literate programming, CSLI Lecture Notes, Stanford, CA: Center for the Study of Language and Information (CSLI), 1992</small> <img src="reproducibility_assets/figure-html/literateProgramming.png"> .footnote[K. Healy [The Plain Person's Guide to Plain Text Social Science](https://kieranhealy.org/files/papers/plain-person-text.pdf)] --- #### literate programming .pull-left[ <img src="reproducibility_assets/figure-html/Rmarkdown.png" width="90%"> ] .pull-left[ <img src="reproducibility_assets/figure-html/Rmd_to_Word.png" width="90%"> ] --- #### orcid .center[ <img src="reproducibility_assets/figure-html/orcid.png" width="50%"> ] [orcid.org](https://orcid.org/) <!-- #### BP: analysis-friendly data * create analysis-friendly data: + each column a variable + each row an observation .pull-left[ <table class="table" style="font-size: 12px; width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:right;"> Sepal.Length </th> <th style="text-align:right;"> Sepal.Width </th> <th style="text-align:right;"> Petal.Length </th> <th style="text-align:right;"> Petal.Width </th> <th style="text-align:left;"> Species </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 5.1 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.9 </td> <td style="text-align:right;"> 3.0 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.7 </td> <td style="text-align:right;"> 3.2 </td> <td style="text-align:right;"> 1.3 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.6 </td> <td style="text-align:right;"> 3.1 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> 3.6 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.4 </td> <td style="text-align:right;"> 3.9 </td> <td style="text-align:right;"> 1.7 </td> <td style="text-align:right;"> 0.4 </td> <td style="text-align:left;"> setosa </td> </tr> </tbody> </table> ] .pull-right[ <table class="table" style="font-size: 12px; width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> Species </th> <th style="text-align:left;"> metric </th> <th style="text-align:right;"> value </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 5.1 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 4.9 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 4.7 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 4.6 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 5.0 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Length </td> <td style="text-align:right;"> 5.4 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Width </td> <td style="text-align:right;"> 3.5 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Width </td> <td style="text-align:right;"> 3.0 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Width </td> <td style="text-align:right;"> 3.2 </td> </tr> <tr> <td style="text-align:left;"> setosa </td> <td style="text-align:left;"> Sepal.Width </td> <td style="text-align:right;"> 3.1 </td> </tr> </tbody> </table> ] .footnote[Wilson et al. (2017) [Good enough practices in scientific computing](https://doi.org/10.1371/journal.pcbi.1005510)] --> <!-- #### I am not saying it is easy Kieran Healy on two revolutions in computing: "On one side, the mobile, cloud-centered, touch-screen, phone-or-tablet model has brought powerful computing to more people than ever before." "On the other side, tools for coding, data analysis, and writing are also revolutionary but mostly work by gluing together separate, specialized widgets that do much less to hide the operation system layer, and require knowledge of things like the file system." .footnote[K. Healy [The Plain Person's Guide to Plain Text Social Science](https://kieranhealy.org/files/papers/plain-person-text.pdf)] --> <!-- #### I am not saying it is easy Very few people are trained in both data analysis and biology. The practical and pragmatic issues of data analysis and data interpretation are not something that is taught at undergrad or graduate school level. Most senior faculty do not know how to do this. Nor do many junior faculty. But our field increasingly *depends* on skilled interpretation of private + public data. So how do we address this? Many layers, many approaches… .footnote[Brown, C. Titus et al. [“2017 - Data Intensive Biology Summer Institute.”](https://osf.io/pyvfg/)] -->