9 Reporting
9.1 R and R-Markdown
We will use R Markdown for communicating results to each other. Note that R and R Markdown are both languages. R studio interprets R code make statistical computations and interprets R Markdown code to produce pretty documents that contain both writing and statistics. Altogether, your project will use
- R: does statistical computations
- R Markdown: formats statistical computations for sharing
- Rstudio: graphical user interface that allows you to easily use both R and R Markdown.
Homework reports are probably the smallest document you can create. These little reports are almost entirely self-contained (showing both code and output). To make them, you will need to
First install Pandoc on your computer.
Then install any required packages
9.2 Simple Reports
We will create reproducible reports via R Markdown.
Example 1: Data Scientism.
See DataScientism.html and then create it by
- Clicking the “Code” button in the top right and then “Download Rmd”
- Open with Rstudio
- Change the name and title to your own, make other edits
- Then point-and-click “knit”
Alternatively,
- Download the source file from DataScientism.Rmd
- Change the name and title to your own, make other edits
- Use the console to run
Example 2: Homework Assignment. Below is a template of what homework questions (and answers) look like. Create a new .Rmd file from scratch and produce a .html file that looks similar to this:
Problem: Simulate 100 random observations of the form y=xβ+ϵ and plot the relationship. Plot and explore the data interactively via plotly, https://plotly.com/r/line-and-scatter/. Then play around with different styles, https://www.r-graph-gallery.com/13-scatter-plot.html, to best express your point.
Solution: I simulate 400 observations for ϵ∼2×N(0,1) and β=4, as seen in this single chunk. Notice an upward trend.
9.3 Posters and Slides
Posters and presentations are another important type of scientific document. R markdown is good at creating both of these, and actually very good with some additional packages. So we will also use flexdashboard for posters and beamer for presentations.
Poster.
See DataScientism_Poster.html and recreate from the source file DataScientism_Poster.Rmd. Simply change the name to your own, and knit the document.
Slides.
Since beamer is a pdf output, you will need to install Latex. Alternatively, you can install a lightweight version TinyTex from within R
Then download source file DataScientism_Slides.Rmd, change the name to your own, and knit the document.
If you cannot install Latex, then you must specify a different output. For example, change output: beamer_presentation
to output: ioslides_presentation
on line 6 of the source file.
9.4 More Literature
For more guidance on how to create Rmarkdown documents, see
- https://github.com/rstudio/cheatsheets/blob/main/rmarkdown.pdf
- https://cran.r-project.org/web/packages/rmarkdown/vignettes/rmarkdown.html
- http://rmarkdown.rstudio.com
- https://bookdown.org/yihui/rmarkdown/
- https://bookdown.org/yihui/rmarkdown-cookbook/
- https://dept.stat.lsa.umich.edu/~jerrick/courses/stat701/notes/rmarkdown.html
- An Introduction to the Advanced Theory and Practice of Nonparametric Econometrics. Raccine 2019. Appendices B & D.
- https://rmd4sci.njtierney.com/using-rmarkdown.html
- https://alexd106.github.io/intro2R/Rmarkdown_intro.html
If you are still lost, try one of the many online tutorials (such as these)
- https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf
- https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
- https://www.neonscience.org/resources/learning-hub/tutorials/rmd-code-intro
- https://m-clark.github.io/Introduction-to-Rmarkdown/
- https://www.stat.cmu.edu/~cshalizi/rmarkdown/
- http://math.wsu.edu/faculty/xchen/stat412/HwWriteUp.Rmd
- http://math.wsu.edu/faculty/xchen/stat412/HwWriteUp.html
- https://holtzy.github.io/Pimp-my-rmd/
- https://ntaback.github.io/UofT_STA130/Rmarkdownforclassreports.html
- https://crd150.github.io/hw_guidelines.html
- https://r4ds.had.co.nz/r-markdown.html
- http://www.stat.cmu.edu/~cshalizi/rmarkdown
- http://www.ssc.wisc.edu/sscc/pubs/RFR/RFR_RMarkdown.html
- http://kbroman.org/knitr_knutshell/pages/Rmarkdown.html
Some other good packages for posters/presenting you should be aware of
- https://github.com/mathematicalcoffee/beamerposter-rmarkdown-example
- https://github.com/rstudio/pagedown
- https://github.com/brentthorne/posterdown
- https://odeleongt.github.io/postr/
- https://wytham.rbind.io/post/making-a-poster-in-r/
- https://www.animateyour.science/post/How-to-design-an-award-winning-conference-poster