SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler 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

Mais conteúdo relacionado

Semelhante a 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
 
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
 
Bayside ps gearheads_catalog
Bayside ps gearheads_catalogBayside ps gearheads_catalog
Bayside ps gearheads_catalogElectromate
 

Semelhante a 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...
 
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
 
Bayside ps gearheads_catalog
Bayside ps gearheads_catalogBayside ps gearheads_catalog
Bayside ps gearheads_catalog
 

Mais de 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
 

Mais de 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
 

Último

Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)PraveenaKalaiselvan1
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)Areesha Ahmad
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfSumit Kumar yadav
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxAArockiyaNisha
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencySheetal Arora
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyDrAnita Sharma
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 

Último (20)

Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
fundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomologyfundamental of entomology all in one topics of entomology
fundamental of entomology all in one topics of entomology
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 

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