R for Statistics

Chester Ismay (cismay@reed.edu)

Lewis & Clark FTI 2016
Tuesday, May 17, 2016

Slides available at http://rpubs.com/cismay/r_FTI_2016

Schedule for session

  • Why R?

  • What is R Markdown?

  • How should we conduct statistical analyses?

    • Data visualization
    • Data manipulation/summarizing
    • Data analysis/modeling
    • Interpretation of results
    • Reproducible research

Why R?

The traditional approach to reports / analysis in the sciences

  • Import data set into statistical software package
  • Run the procedure to get results
  • Copy and paste appropriate pieces from the analysis into document editor
  • Add descriptions
  • Finish/submit report

Disadvantages of this process

  • Lots of manual work (prone to make errors)
  • Tedious (who likes to carefully copy-and-paste?)
  • Likely not recordable (did you write down all the steps you followed to get your analysis?)
  • What if you made an error at the beginning of your analysis? If your data had an error?

What is R?

  • R is a completely free software package and language for statistical analysis and graphics.
  • It excels in helping you with
    • data manipulation
    • automation
    • reproducibility
    • improved accuracy
    • error finding
    • customizability
    • beautiful visualizations
  • Any downsides?

Learning how to use R

RStudio and R Markdown

  • RStudio is a powerful user interface that helps you get better control of your analysis.
  • It is also completely free.
  • It comes in both a desktop version and a server version (on the cloud).
  • You can write your entire paper/report (text, code, analysis, graphics, etc.) all in R Markdown.
  • If you need to update any of your code, R Markdown will automatically update your plots and output of your analysis and will create an updated PDF/HTML file.
  • No more copy-and-paste!

What is Markdown?

  • A “plaintext formatting syntax”
  • Type in plain text, render to more complex formats
  • One step beyond writing a txt file
  • Render to HTML, PDF, DOCX, etc.

What does it look like?

  # Header 1
  ## Header 2
  Normal paragraphs of text go here.
  **I'm bold**
   * Unordered
   * Lists   
  And  Tables
  ---- -------
  Like This

What is R Markdown?

  • “Literate programming”
  • Embed R code in a Markdown document
  • Renders textual output along with graphics

```{r chunk_name}
x <- rnorm(1000)
qplot(x, bins = 10, 
      fill = I("orange"), 
      color = I("black"))
## [1] 1000