SlideShare a Scribd company logo
1 of 43
Download to read offline
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Reproducible Research
An Introduction to knitr
Sahir Rai Bhatnagar1
May 28, 2014
1https://github.com/sahirbhatnagar/knitr-tutorial
1 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Acknowledgements
• Dr. Erica Moodie
• Maxime Turgeon
(Windows)
• Kevin McGregor (Mac)
• Greg Voisin
• Don Knuth (TEX)
• Friedrich Leisch (Sweave)
• Yihui Xie (knitr)
• You
2 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Disclaimer #1
• Feel free to Ask questions
• Interrupt me often
• You don’t need to raise your hand to speak
3 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Disclaimer #2
I don’t work for, nor am I an author of any of these packages. I’m
just a messenger.
4 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Disclaimer #3
• Material for this tutorial comes from many sources. For a
complete list see:
https://github.com/sahirbhatnagar/knitr-tutorial
• Alot of the content in these slides are based on these two books
5 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Eat Your Own Dog Food
• These slides are reproducible
• Source code: https://github.com/sahirbhatnagar/knitr-
tutorial/tree/master/slides
6 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Main objective for today
7 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
What is Science Anyway?
8 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
What is Science Anyway?
According to the American Physical Society:
Science is the systematic enterprise of gathering knowledge about the
universe and organizing and condensing that knowledge into testable
laws and theories. The success and credibility of science are
anchored in the willingness of scientists to expose their ideas and
results to independent testing and replication by other scientists
8 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
RR: A Minimum Standard to Verify Scientific
Findings
9 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
RR: A Minimum Standard to Verify Scientific
Findings
Reproducible Research (RR) in Computational Sciences
The data and the code used to make a finding are available and they
are sufficient for an independent researcher to recreate the finding
9 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Why should we
care about RR?
For Science
Standard to judge
scientific claims
Avoid duplication
Cumulative
knowledge
development
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Why should we
care about RR?
For Science
Standard to judge
scientific claims
Avoid duplication
Cumulative
knowledge
development
For You
Better work
habits
Better teamwork
Changes
are easier
Higher re-
search impact
10 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
A Motivating Example
Demonstrate: 001-motivating-example
Survey: https://www.surveymonkey.com/s/CDVXW3C
11 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Tools for Reproducible Research2
Free and Open Source Software
• RStudio: Creating, managing, compiling documents
• LATEX: Markup language for typesetting a document
• R: Statistical analysis language
• knitr: Integrate LATEXand R code. Based on Prof. Friedrich
Leisch’s Sweave
2http://onepager.togaware.com/
12 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Comparison
Figure 1 : Comparison
• LATEX has a greater learning
curve
• Many tasks are very tedious
or impossible (most cases) to
do in MS Word or Libre Office
13 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
The Philosophy behind LATEX
Figure 2 : Adam Smith, author of
The Wealth of Nations (1776), in
which he conceptualizes the
notion of the division of labour
Division of Labour
Composition and logical structuring
of text is the author’s specific
contribution to the production of a
printed text. Matters such as the
choice of the font family, should
section headings be in bold face or
small capitals? Should they be flush
left or centered? Should the text be
justified or not? Should the notes
appear at the foot of the page or at
the end? Should the text be set in
one column or two? and so on, is the
typesetter’s business
14 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
The Genius Behind LATEX
Figure 3 : The TEX project was started in 1978 by Donald Knuth
(Stanford). He planned for 6 months, but it took him nearly 10 years to
complete. Coined the term “Literate programming”: mixture of code and
text segments that are “human” readable. Recipient of the Turing Award
(1974) and the Kyoto Prize (1996).
15 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Integrated Development Environment (IDE)
16 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Integrated Development Environment (IDE)
Demonstrate: Explore RStudio
16 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
What knitr does
LATEX example:
Report.Rnw
(contains both
code and markup)
Report.tex
knitr::knit(’Report.Rnw’)
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
What knitr does
LATEX example:
Report.Rnw
(contains both
code and markup)
Report.tex
knitr::knit(’Report.Rnw’)
Report.pdf
latex2pdf(’Report.tex’)
17 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Compiling a .Rnw document
The two steps on previous slide can be executed in one
command:
knitr::knit2pdf()
or in RStudio:
18 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Incorporating R code
• Insert R code in a Code Chunk starting with
<< >>=
and ending with
@
In RStudio:
19 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Example 1
<<example-code-chunk-name, echo=TRUE>>=
library(magrittr)
rnorm(50) %>% mean
@
produces
library(magrittr)
rnorm(50) %>% mean
## [1] 0.031
20 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Example 2
<<example-code-chunk-name2, echo=TRUE, tidy=TRUE>>=
for(i in 1:5){ (i+3) %>% print}
@
produces
for (i in 1:5) {
(i + 3) %>% print
}
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
21 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Example 2.2
<<example-code-chunk-name3, echo=FALSE>>=
for(i in 1:5){ (i+3) %>% print}
@
produces
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
22 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Example 2.3
<<example-code-chunk-name4, echo=FALSE, eval=FALSE>>=
for(i in 1:5){ (i+3) %>% print}
@
produces
Demonstrate: Try it yourself
23 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
R output within the text
• Include R output within the text
• We can do that with “S-expressions” using the command
Sexpr{. . .}
Example:
The iris dataset has Sexpr{nrow(iris)} rows and
Sexpr{ncol(iris)} columns
produces
The iris dataset has 150 rows and 5 columns
24 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Include a Figure
<<fig.ex, fig.cap='Linear Regression',fig.height=3,fig.width=3>>=
plot(mtcars[ , c('disp','mpg')])
lm(mpg ~ disp , data = mtcars) %>%
abline(lwd=2)
@
100 200 300 400
1025
disp
mpg
Figure 4 : Linear regression
25 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Include a Table
<<table.ex, results='asis'>>=
library(xtable)
iris[1:5,1:5] %>%
xtable(caption='Sample of Iris data') %>%
print(include.rownames=FALSE)
@
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.10 3.50 1.40 0.20 setosa
4.90 3.00 1.40 0.20 setosa
4.70 3.20 1.30 0.20 setosa
4.60 3.10 1.50 0.20 setosa
5.00 3.60 1.40 0.20 setosa
Table 1 : Sample of Iris data
26 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Minimum Working Example
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/002-
minimum-working-example
27 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Extracting output from Regression Models
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/003-
model-output
28 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Figures
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/004-
figures
29 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Beamer Presentations
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/005-
beamer-presentation
30 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Changing one Parameter in an Analysis
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/006-
sensitivity-analysis-one-parameter
31 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Changing Many Parameters in an Analysis
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/007-
sensitivity-analysis-many-parameters
32 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Large Documents
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/008-
large-documents
33 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
HTML Reports
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/009-
rmarkdown
34 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
HTML Presentations
https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/010-
rmarkdown-presentation
35 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
36 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Always Remember ...
Reproducibility ∝
1
copy paste
37 / 38
RR: Intro to
knitr
Reproducible
Research
What?
Why?
001-motivating-
example
Getting Started
LATEX
RStudio
knitr
Examples
002-minimum-
working-example
003-model-
output
004-figures
005-beamer-
presentation
006-sensitivity-
analysis-one-
parameter
007-sensitivity-
analysis-many-
parameters
008-large-
documents
009-rmarkdown
010-rmarkdown-
presentation
Final Remarks
Is the juice worth the squeeze?
38 / 38

More Related Content

Similar to Introduction to Reproducible Research with knitr

Quick Acting Couplers - Legris Parker นิวเมติก.com
Quick Acting Couplers - Legris Parker นิวเมติก.comQuick Acting Couplers - Legris Parker นิวเมติก.com
Quick Acting Couplers - Legris Parker นิวเมติก.comDNTMb Inc.
 
Design and Analysis of Electric Vehicle Battery Fixture
Design and Analysis of Electric Vehicle Battery FixtureDesign and Analysis of Electric Vehicle Battery Fixture
Design and Analysis of Electric Vehicle Battery FixtureIRJET Journal
 
Lightweight Design (Composites) - Americas ATC 2015 Workshop
Lightweight Design (Composites) - Americas ATC 2015 WorkshopLightweight Design (Composites) - Americas ATC 2015 Workshop
Lightweight Design (Composites) - Americas ATC 2015 WorkshopAltair
 
Xilinx vs Intel (Altera) FPGA performance comparison
Xilinx vs Intel (Altera) FPGA performance comparison Xilinx vs Intel (Altera) FPGA performance comparison
Xilinx vs Intel (Altera) FPGA performance comparison Roy Messinger
 
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016MLconf
 
MLConf 2016 SigOpt Talk by Scott Clark
MLConf 2016 SigOpt Talk by Scott ClarkMLConf 2016 SigOpt Talk by Scott Clark
MLConf 2016 SigOpt Talk by Scott ClarkSigOpt
 
IRJET- Spring Testing Machine
IRJET- Spring Testing MachineIRJET- Spring Testing Machine
IRJET- Spring Testing MachineIRJET Journal
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Craig Smith
 
2020 Sciencetech Presentation
2020 Sciencetech Presentation2020 Sciencetech Presentation
2020 Sciencetech PresentationScott Hafekost
 
Track g test strategy - delta
Track g   test strategy - deltaTrack g   test strategy - delta
Track g test strategy - deltachiportal
 
IRJET- Design and Development of a Bandsaw Machine Roller Bracket for Wei...
IRJET-  	  Design and Development of a Bandsaw Machine Roller Bracket for Wei...IRJET-  	  Design and Development of a Bandsaw Machine Roller Bracket for Wei...
IRJET- Design and Development of a Bandsaw Machine Roller Bracket for Wei...IRJET Journal
 
Design Optimization of Roller Chain Link Plate used in Sugar Industry
Design Optimization of Roller Chain Link Plate used in Sugar IndustryDesign Optimization of Roller Chain Link Plate used in Sugar Industry
Design Optimization of Roller Chain Link Plate used in Sugar IndustryIRJET Journal
 
Cnd labguide
Cnd labguideCnd labguide
Cnd labguideYahye159
 
Internal laboratory scope
Internal laboratory scopeInternal laboratory scope
Internal laboratory scopeTuan Anh Nguyen
 
Developments In Precision Positioning Stages with High Speed Range
Developments In Precision Positioning Stages with High Speed RangeDevelopments In Precision Positioning Stages with High Speed Range
Developments In Precision Positioning Stages with High Speed RangeDesign World
 
Evaluating Static Analysis of the Damper Grommets for Compressor
Evaluating Static Analysis of the Damper Grommets for CompressorEvaluating Static Analysis of the Damper Grommets for Compressor
Evaluating Static Analysis of the Damper Grommets for CompressorIRJET Journal
 

Similar to Introduction to Reproducible Research with knitr (20)

resumelrs_jan_2017
resumelrs_jan_2017resumelrs_jan_2017
resumelrs_jan_2017
 
To Mock or Not To Mock
To Mock or Not To MockTo Mock or Not To Mock
To Mock or Not To Mock
 
Quick Acting Couplers - Legris Parker นิวเมติก.com
Quick Acting Couplers - Legris Parker นิวเมติก.comQuick Acting Couplers - Legris Parker นิวเมติก.com
Quick Acting Couplers - Legris Parker นิวเมติก.com
 
Design and Analysis of Electric Vehicle Battery Fixture
Design and Analysis of Electric Vehicle Battery FixtureDesign and Analysis of Electric Vehicle Battery Fixture
Design and Analysis of Electric Vehicle Battery Fixture
 
Final Report SEC3
Final Report SEC3Final Report SEC3
Final Report SEC3
 
Lightweight Design (Composites) - Americas ATC 2015 Workshop
Lightweight Design (Composites) - Americas ATC 2015 WorkshopLightweight Design (Composites) - Americas ATC 2015 Workshop
Lightweight Design (Composites) - Americas ATC 2015 Workshop
 
Xilinx vs Intel (Altera) FPGA performance comparison
Xilinx vs Intel (Altera) FPGA performance comparison Xilinx vs Intel (Altera) FPGA performance comparison
Xilinx vs Intel (Altera) FPGA performance comparison
 
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016
Scott Clark, Co-Founder and CEO, SigOpt at MLconf SF 2016
 
MLConf 2016 SigOpt Talk by Scott Clark
MLConf 2016 SigOpt Talk by Scott ClarkMLConf 2016 SigOpt Talk by Scott Clark
MLConf 2016 SigOpt Talk by Scott Clark
 
IRJET- Spring Testing Machine
IRJET- Spring Testing MachineIRJET- Spring Testing Machine
IRJET- Spring Testing Machine
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!
 
2020 Sciencetech Presentation
2020 Sciencetech Presentation2020 Sciencetech Presentation
2020 Sciencetech Presentation
 
Track g test strategy - delta
Track g   test strategy - deltaTrack g   test strategy - delta
Track g test strategy - delta
 
bolts 8.8
bolts 8.8bolts 8.8
bolts 8.8
 
IRJET- Design and Development of a Bandsaw Machine Roller Bracket for Wei...
IRJET-  	  Design and Development of a Bandsaw Machine Roller Bracket for Wei...IRJET-  	  Design and Development of a Bandsaw Machine Roller Bracket for Wei...
IRJET- Design and Development of a Bandsaw Machine Roller Bracket for Wei...
 
Design Optimization of Roller Chain Link Plate used in Sugar Industry
Design Optimization of Roller Chain Link Plate used in Sugar IndustryDesign Optimization of Roller Chain Link Plate used in Sugar Industry
Design Optimization of Roller Chain Link Plate used in Sugar Industry
 
Cnd labguide
Cnd labguideCnd labguide
Cnd labguide
 
Internal laboratory scope
Internal laboratory scopeInternal laboratory scope
Internal laboratory scope
 
Developments In Precision Positioning Stages with High Speed Range
Developments In Precision Positioning Stages with High Speed RangeDevelopments In Precision Positioning Stages with High Speed Range
Developments In Precision Positioning Stages with High Speed Range
 
Evaluating Static Analysis of the Damper Grommets for Compressor
Evaluating Static Analysis of the Damper Grommets for CompressorEvaluating Static Analysis of the Damper Grommets for Compressor
Evaluating Static Analysis of the Damper Grommets for Compressor
 

More from sahirbhatnagar

Strong Heredity Models in High Dimensional Data
Strong Heredity Models in High Dimensional DataStrong Heredity Models in High Dimensional Data
Strong Heredity Models in High Dimensional Datasahirbhatnagar
 
Methods for High Dimensional Interactions
Methods for High Dimensional InteractionsMethods for High Dimensional Interactions
Methods for High Dimensional Interactionssahirbhatnagar
 
Analysis of DNA methylation and Gene expression to predict childhood obesity
Analysis of DNA methylation and Gene expression to predict childhood obesityAnalysis of DNA methylation and Gene expression to predict childhood obesity
Analysis of DNA methylation and Gene expression to predict childhood obesitysahirbhatnagar
 
Estimation and Accuracy after Model Selection
Estimation and Accuracy after Model SelectionEstimation and Accuracy after Model Selection
Estimation and Accuracy after Model Selectionsahirbhatnagar
 
Absolute risk estimation in a case cohort study of prostate cancer
Absolute risk estimation in a case cohort study of prostate cancerAbsolute risk estimation in a case cohort study of prostate cancer
Absolute risk estimation in a case cohort study of prostate cancersahirbhatnagar
 
Computational methods for case-cohort studies
Computational methods for case-cohort studiesComputational methods for case-cohort studies
Computational methods for case-cohort studiessahirbhatnagar
 
Factors influencing participation in cancer screening
Factors influencing participation in cancer screeningFactors influencing participation in cancer screening
Factors influencing participation in cancer screeningsahirbhatnagar
 
Methylation and Expression data integration
Methylation and Expression data integrationMethylation and Expression data integration
Methylation and Expression data integrationsahirbhatnagar
 

More from sahirbhatnagar (11)

Strong Heredity Models in High Dimensional Data
Strong Heredity Models in High Dimensional DataStrong Heredity Models in High Dimensional Data
Strong Heredity Models in High Dimensional Data
 
Methods for High Dimensional Interactions
Methods for High Dimensional InteractionsMethods for High Dimensional Interactions
Methods for High Dimensional Interactions
 
Atelier r-gerad
Atelier r-geradAtelier r-gerad
Atelier r-gerad
 
Analysis of DNA methylation and Gene expression to predict childhood obesity
Analysis of DNA methylation and Gene expression to predict childhood obesityAnalysis of DNA methylation and Gene expression to predict childhood obesity
Analysis of DNA methylation and Gene expression to predict childhood obesity
 
Estimation and Accuracy after Model Selection
Estimation and Accuracy after Model SelectionEstimation and Accuracy after Model Selection
Estimation and Accuracy after Model Selection
 
Absolute risk estimation in a case cohort study of prostate cancer
Absolute risk estimation in a case cohort study of prostate cancerAbsolute risk estimation in a case cohort study of prostate cancer
Absolute risk estimation in a case cohort study of prostate cancer
 
Computational methods for case-cohort studies
Computational methods for case-cohort studiesComputational methods for case-cohort studies
Computational methods for case-cohort studies
 
Factors influencing participation in cancer screening
Factors influencing participation in cancer screeningFactors influencing participation in cancer screening
Factors influencing participation in cancer screening
 
Introduction to LaTeX
Introduction to LaTeXIntroduction to LaTeX
Introduction to LaTeX
 
Methylation and Expression data integration
Methylation and Expression data integrationMethylation and Expression data integration
Methylation and Expression data integration
 
Reproducible Research
Reproducible ResearchReproducible Research
Reproducible Research
 

Recently uploaded

complex analysis best book for solving questions.pdf
complex analysis best book for solving questions.pdfcomplex analysis best book for solving questions.pdf
complex analysis best book for solving questions.pdfSubhamKumar3239
 
Q4-Mod-1c-Quiz-Projectile-333344444.pptx
Q4-Mod-1c-Quiz-Projectile-333344444.pptxQ4-Mod-1c-Quiz-Projectile-333344444.pptx
Q4-Mod-1c-Quiz-Projectile-333344444.pptxtuking87
 
Pests of Sunflower_Binomics_Identification_Dr.UPR
Pests of Sunflower_Binomics_Identification_Dr.UPRPests of Sunflower_Binomics_Identification_Dr.UPR
Pests of Sunflower_Binomics_Identification_Dr.UPRPirithiRaju
 
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer Zahana
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer ZahanaEGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer Zahana
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer ZahanaDr.Mahmoud Abbas
 
whole genome sequencing new and its types including shortgun and clone by clone
whole genome sequencing new  and its types including shortgun and clone by clonewhole genome sequencing new  and its types including shortgun and clone by clone
whole genome sequencing new and its types including shortgun and clone by clonechaudhary charan shingh university
 
Advances in AI-driven Image Recognition for Early Detection of Cancer
Advances in AI-driven Image Recognition for Early Detection of CancerAdvances in AI-driven Image Recognition for Early Detection of Cancer
Advances in AI-driven Image Recognition for Early Detection of CancerLuis Miguel Chong Chong
 
Gas-ExchangeS-in-Plants-and-Animals.pptx
Gas-ExchangeS-in-Plants-and-Animals.pptxGas-ExchangeS-in-Plants-and-Animals.pptx
Gas-ExchangeS-in-Plants-and-Animals.pptxGiovaniTrinidad
 
linear Regression, multiple Regression and Annova
linear Regression, multiple Regression and Annovalinear Regression, multiple Regression and Annova
linear Regression, multiple Regression and AnnovaMansi Rastogi
 
Measures of Central Tendency.pptx for UG
Measures of Central Tendency.pptx for UGMeasures of Central Tendency.pptx for UG
Measures of Central Tendency.pptx for UGSoniaBajaj10
 
Observational constraints on mergers creating magnetism in massive stars
Observational constraints on mergers creating magnetism in massive starsObservational constraints on mergers creating magnetism in massive stars
Observational constraints on mergers creating magnetism in massive starsSérgio Sacani
 
DETECTION OF MUTATION BY CLB METHOD.pptx
DETECTION OF MUTATION BY CLB METHOD.pptxDETECTION OF MUTATION BY CLB METHOD.pptx
DETECTION OF MUTATION BY CLB METHOD.pptx201bo007
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests GlycosidesNandakishor Bhaurao Deshmukh
 
Abnormal LFTs rate of deco and NAFLD.pptx
Abnormal LFTs rate of deco and NAFLD.pptxAbnormal LFTs rate of deco and NAFLD.pptx
Abnormal LFTs rate of deco and NAFLD.pptxzeus70441
 
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...Chayanika Das
 
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...Sérgio Sacani
 
Probability.pptx, Types of Probability, UG
Probability.pptx, Types of Probability, UGProbability.pptx, Types of Probability, UG
Probability.pptx, Types of Probability, UGSoniaBajaj10
 
Total Legal: A “Joint” Journey into the Chemistry of Cannabinoids
Total Legal: A “Joint” Journey into the Chemistry of CannabinoidsTotal Legal: A “Joint” Journey into the Chemistry of Cannabinoids
Total Legal: A “Joint” Journey into the Chemistry of CannabinoidsMarkus Roggen
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxMedical College
 
dll general biology week 1 - Copy.docx
dll general biology   week 1 - Copy.docxdll general biology   week 1 - Copy.docx
dll general biology week 1 - Copy.docxkarenmillo
 

Recently uploaded (20)

complex analysis best book for solving questions.pdf
complex analysis best book for solving questions.pdfcomplex analysis best book for solving questions.pdf
complex analysis best book for solving questions.pdf
 
Q4-Mod-1c-Quiz-Projectile-333344444.pptx
Q4-Mod-1c-Quiz-Projectile-333344444.pptxQ4-Mod-1c-Quiz-Projectile-333344444.pptx
Q4-Mod-1c-Quiz-Projectile-333344444.pptx
 
Pests of Sunflower_Binomics_Identification_Dr.UPR
Pests of Sunflower_Binomics_Identification_Dr.UPRPests of Sunflower_Binomics_Identification_Dr.UPR
Pests of Sunflower_Binomics_Identification_Dr.UPR
 
PLASMODIUM. PPTX
PLASMODIUM. PPTXPLASMODIUM. PPTX
PLASMODIUM. PPTX
 
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer Zahana
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer ZahanaEGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer Zahana
EGYPTIAN IMPRINT IN SPAIN Lecture by Dr Abeer Zahana
 
whole genome sequencing new and its types including shortgun and clone by clone
whole genome sequencing new  and its types including shortgun and clone by clonewhole genome sequencing new  and its types including shortgun and clone by clone
whole genome sequencing new and its types including shortgun and clone by clone
 
Advances in AI-driven Image Recognition for Early Detection of Cancer
Advances in AI-driven Image Recognition for Early Detection of CancerAdvances in AI-driven Image Recognition for Early Detection of Cancer
Advances in AI-driven Image Recognition for Early Detection of Cancer
 
Gas-ExchangeS-in-Plants-and-Animals.pptx
Gas-ExchangeS-in-Plants-and-Animals.pptxGas-ExchangeS-in-Plants-and-Animals.pptx
Gas-ExchangeS-in-Plants-and-Animals.pptx
 
linear Regression, multiple Regression and Annova
linear Regression, multiple Regression and Annovalinear Regression, multiple Regression and Annova
linear Regression, multiple Regression and Annova
 
Measures of Central Tendency.pptx for UG
Measures of Central Tendency.pptx for UGMeasures of Central Tendency.pptx for UG
Measures of Central Tendency.pptx for UG
 
Observational constraints on mergers creating magnetism in massive stars
Observational constraints on mergers creating magnetism in massive starsObservational constraints on mergers creating magnetism in massive stars
Observational constraints on mergers creating magnetism in massive stars
 
DETECTION OF MUTATION BY CLB METHOD.pptx
DETECTION OF MUTATION BY CLB METHOD.pptxDETECTION OF MUTATION BY CLB METHOD.pptx
DETECTION OF MUTATION BY CLB METHOD.pptx
 
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests GlycosidesGLYCOSIDES Classification Of GLYCOSIDES  Chemical Tests Glycosides
GLYCOSIDES Classification Of GLYCOSIDES Chemical Tests Glycosides
 
Abnormal LFTs rate of deco and NAFLD.pptx
Abnormal LFTs rate of deco and NAFLD.pptxAbnormal LFTs rate of deco and NAFLD.pptx
Abnormal LFTs rate of deco and NAFLD.pptx
 
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...
ESSENTIAL FEATURES REQUIRED FOR ESTABLISHING FOUR TYPES OF BIOSAFETY LABORATO...
 
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...
Observation of Gravitational Waves from the Coalescence of a 2.5–4.5 M⊙ Compa...
 
Probability.pptx, Types of Probability, UG
Probability.pptx, Types of Probability, UGProbability.pptx, Types of Probability, UG
Probability.pptx, Types of Probability, UG
 
Total Legal: A “Joint” Journey into the Chemistry of Cannabinoids
Total Legal: A “Joint” Journey into the Chemistry of CannabinoidsTotal Legal: A “Joint” Journey into the Chemistry of Cannabinoids
Total Legal: A “Joint” Journey into the Chemistry of Cannabinoids
 
Introduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptxIntroduction of Human Body & Structure of cell.pptx
Introduction of Human Body & Structure of cell.pptx
 
dll general biology week 1 - Copy.docx
dll general biology   week 1 - Copy.docxdll general biology   week 1 - Copy.docx
dll general biology week 1 - Copy.docx
 

Introduction to Reproducible Research with knitr

  • 1. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Reproducible Research An Introduction to knitr Sahir Rai Bhatnagar1 May 28, 2014 1https://github.com/sahirbhatnagar/knitr-tutorial 1 / 38
  • 2. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Acknowledgements • Dr. Erica Moodie • Maxime Turgeon (Windows) • Kevin McGregor (Mac) • Greg Voisin • Don Knuth (TEX) • Friedrich Leisch (Sweave) • Yihui Xie (knitr) • You 2 / 38
  • 3. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Disclaimer #1 • Feel free to Ask questions • Interrupt me often • You don’t need to raise your hand to speak 3 / 38
  • 4. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Disclaimer #2 I don’t work for, nor am I an author of any of these packages. I’m just a messenger. 4 / 38
  • 5. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Disclaimer #3 • Material for this tutorial comes from many sources. For a complete list see: https://github.com/sahirbhatnagar/knitr-tutorial • Alot of the content in these slides are based on these two books 5 / 38
  • 6. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Eat Your Own Dog Food • These slides are reproducible • Source code: https://github.com/sahirbhatnagar/knitr- tutorial/tree/master/slides 6 / 38
  • 7. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Main objective for today 7 / 38
  • 8. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks What is Science Anyway? 8 / 38
  • 9. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks What is Science Anyway? According to the American Physical Society: Science is the systematic enterprise of gathering knowledge about the universe and organizing and condensing that knowledge into testable laws and theories. The success and credibility of science are anchored in the willingness of scientists to expose their ideas and results to independent testing and replication by other scientists 8 / 38
  • 10. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks RR: A Minimum Standard to Verify Scientific Findings 9 / 38
  • 11. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks RR: A Minimum Standard to Verify Scientific Findings Reproducible Research (RR) in Computational Sciences The data and the code used to make a finding are available and they are sufficient for an independent researcher to recreate the finding 9 / 38
  • 12. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Why should we care about RR? For Science Standard to judge scientific claims Avoid duplication Cumulative knowledge development
  • 13. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Why should we care about RR? For Science Standard to judge scientific claims Avoid duplication Cumulative knowledge development For You Better work habits Better teamwork Changes are easier Higher re- search impact 10 / 38
  • 14. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks A Motivating Example Demonstrate: 001-motivating-example Survey: https://www.surveymonkey.com/s/CDVXW3C 11 / 38
  • 15. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Tools for Reproducible Research2 Free and Open Source Software • RStudio: Creating, managing, compiling documents • LATEX: Markup language for typesetting a document • R: Statistical analysis language • knitr: Integrate LATEXand R code. Based on Prof. Friedrich Leisch’s Sweave 2http://onepager.togaware.com/ 12 / 38
  • 16. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Comparison Figure 1 : Comparison • LATEX has a greater learning curve • Many tasks are very tedious or impossible (most cases) to do in MS Word or Libre Office 13 / 38
  • 17. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks The Philosophy behind LATEX Figure 2 : Adam Smith, author of The Wealth of Nations (1776), in which he conceptualizes the notion of the division of labour Division of Labour Composition and logical structuring of text is the author’s specific contribution to the production of a printed text. Matters such as the choice of the font family, should section headings be in bold face or small capitals? Should they be flush left or centered? Should the text be justified or not? Should the notes appear at the foot of the page or at the end? Should the text be set in one column or two? and so on, is the typesetter’s business 14 / 38
  • 18. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks The Genius Behind LATEX Figure 3 : The TEX project was started in 1978 by Donald Knuth (Stanford). He planned for 6 months, but it took him nearly 10 years to complete. Coined the term “Literate programming”: mixture of code and text segments that are “human” readable. Recipient of the Turing Award (1974) and the Kyoto Prize (1996). 15 / 38
  • 19. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Integrated Development Environment (IDE) 16 / 38
  • 20. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Integrated Development Environment (IDE) Demonstrate: Explore RStudio 16 / 38
  • 21. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks What knitr does LATEX example: Report.Rnw (contains both code and markup) Report.tex knitr::knit(’Report.Rnw’)
  • 22. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks What knitr does LATEX example: Report.Rnw (contains both code and markup) Report.tex knitr::knit(’Report.Rnw’) Report.pdf latex2pdf(’Report.tex’) 17 / 38
  • 23. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Compiling a .Rnw document The two steps on previous slide can be executed in one command: knitr::knit2pdf() or in RStudio: 18 / 38
  • 24. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Incorporating R code • Insert R code in a Code Chunk starting with << >>= and ending with @ In RStudio: 19 / 38
  • 25. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Example 1 <<example-code-chunk-name, echo=TRUE>>= library(magrittr) rnorm(50) %>% mean @ produces library(magrittr) rnorm(50) %>% mean ## [1] 0.031 20 / 38
  • 26. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Example 2 <<example-code-chunk-name2, echo=TRUE, tidy=TRUE>>= for(i in 1:5){ (i+3) %>% print} @ produces for (i in 1:5) { (i + 3) %>% print } ## [1] 4 ## [1] 5 ## [1] 6 ## [1] 7 ## [1] 8 21 / 38
  • 27. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Example 2.2 <<example-code-chunk-name3, echo=FALSE>>= for(i in 1:5){ (i+3) %>% print} @ produces ## [1] 4 ## [1] 5 ## [1] 6 ## [1] 7 ## [1] 8 22 / 38
  • 28. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Example 2.3 <<example-code-chunk-name4, echo=FALSE, eval=FALSE>>= for(i in 1:5){ (i+3) %>% print} @ produces Demonstrate: Try it yourself 23 / 38
  • 29. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks R output within the text • Include R output within the text • We can do that with “S-expressions” using the command Sexpr{. . .} Example: The iris dataset has Sexpr{nrow(iris)} rows and Sexpr{ncol(iris)} columns produces The iris dataset has 150 rows and 5 columns 24 / 38
  • 30. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Include a Figure <<fig.ex, fig.cap='Linear Regression',fig.height=3,fig.width=3>>= plot(mtcars[ , c('disp','mpg')]) lm(mpg ~ disp , data = mtcars) %>% abline(lwd=2) @ 100 200 300 400 1025 disp mpg Figure 4 : Linear regression 25 / 38
  • 31. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Include a Table <<table.ex, results='asis'>>= library(xtable) iris[1:5,1:5] %>% xtable(caption='Sample of Iris data') %>% print(include.rownames=FALSE) @ Sepal.Length Sepal.Width Petal.Length Petal.Width Species 5.10 3.50 1.40 0.20 setosa 4.90 3.00 1.40 0.20 setosa 4.70 3.20 1.30 0.20 setosa 4.60 3.10 1.50 0.20 setosa 5.00 3.60 1.40 0.20 setosa Table 1 : Sample of Iris data 26 / 38
  • 32. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Minimum Working Example https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/002- minimum-working-example 27 / 38
  • 33. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Extracting output from Regression Models https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/003- model-output 28 / 38
  • 34. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Figures https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/004- figures 29 / 38
  • 35. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Beamer Presentations https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/005- beamer-presentation 30 / 38
  • 36. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Changing one Parameter in an Analysis https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/006- sensitivity-analysis-one-parameter 31 / 38
  • 37. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Changing Many Parameters in an Analysis https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/007- sensitivity-analysis-many-parameters 32 / 38
  • 38. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Large Documents https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/008- large-documents 33 / 38
  • 39. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks HTML Reports https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/009- rmarkdown 34 / 38
  • 40. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks HTML Presentations https://github.com/sahirbhatnagar/knitr-tutorial/tree/master/010- rmarkdown-presentation 35 / 38
  • 41. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks 36 / 38
  • 42. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Always Remember ... Reproducibility ∝ 1 copy paste 37 / 38
  • 43. RR: Intro to knitr Reproducible Research What? Why? 001-motivating- example Getting Started LATEX RStudio knitr Examples 002-minimum- working-example 003-model- output 004-figures 005-beamer- presentation 006-sensitivity- analysis-one- parameter 007-sensitivity- analysis-many- parameters 008-large- documents 009-rmarkdown 010-rmarkdown- presentation Final Remarks Is the juice worth the squeeze? 38 / 38