Introduction to R
Andrew Jaffe
January 4, 2016
Welcome to class!
1. Introductions
2. Class overview
3. Getting R up and running
About Me
Investigator, Lieber Institute for Brain Development Assistant
Professor, Department of Mental Health, JHSPH
PhD in Epidemiology, MHS in Bioinformatics
Email:
[email protected]Other Instructor
John Muschelli
5th year PhD student in Biostatistics
Email: [email protected]
Introductions
What do you hope to get out of the class?
Why R?
Course Website
http://www.aejaffe.com/winterR_2016/
Materials will be uploaded the night before class
Learning Objectives
I Reading data into R
I Recoding and manipulating data
I Writing R functions and using add-on packages
I Making exploratory plots
I Understanding basic programming syntax
I Performing basic statistical tests
Course Format
I 3 modules per class session, each approximately 1 hour
I “Interactive” Lecture with RStudio + slides
I Lab/Practical experience
Grading
1. Attendance/Participation: 20%
2. Nightly Homework: 3 x 15%
3. Final “Project”: 35%
Grading
I Homework 1: Due Monday 1/4 by midnight
I Homework 2: Due Wednesday 1/6 by class
I Homework 3: Due Thursday 1/7 by class
I Project: Due Friday 1/22 by 5pm
What is R?
I R is a language and environment for statistical computing and
graphics
I R is the open source implementation of the S language, which
was developed by Bell laboratories
I R is both open source and open development
(source: http://www.r-project.org/)
Why R?
I Powerful and flexible
I Free (open source)
I Extensive add-on software (packages)
I Designed for statistical computing
I High level language
Why not R?
I Fairly steep learning curve
I “Programming” oriented
I Minimal interface
I Little centralized support, relies on online community and
package developers
I Annoying to update
I Slower, and more memory intensive, than the more traditional
programming languages (C, Java, Perl, Python)
Installing R
Install the latest version from: http://cran.r-project.org/
If you have an older version of R, you may not need to update. If
you do want to update, re-install and run
update.packages(ask=FALSE)
R Studio
(Makes R easier)
I Integrated Development Environment (IDE) for R
I Syntax highlighting, code completion, and smart indentation
I Execute R code directly from the source editor
I Easily manage multiple working directories using projects
I Workspace browser and data viewer
I Plot history, zooming, and flexible image and PDF export
I Integrated R help and documentation
I Searchable command history
I http://www.rstudio.com/
Working with R
I The R Console “interprets” whatever you type
I Calculator
I Creating variables
I Applying functions
I “Analysis” Script + Interactive Exploration
I Static copy of what you did (reproducability)
I Try things out interactively, then add to your script
I R revolves around functions
I Commands that take input, performs computations, and returns
results
I Many come with R, but people write external functions you can
download and use
Useful R Studio Shortcuts
I Ctrl + Enter (Cmd + Enter on OS X) in your script
evaluates that line of code
I It’s like copying and pasting the code into the console for it to
run.
I Ctrl+1 takes you to the script page
I Ctrl+2 takes you to the console
I http://www.rstudio.com/ide/docs/using/keyboard_
shortcuts
Useful (+Free) Resources
I Homework will involve working through:
http://tryr.codeschool.com/
I DataCamp http://www.datacamp.com
I UCLA Institute for Digital Research and Education:
http://www.ats.ucla.edu/stat/r/
I R reference card: http://cran.r-project.org/doc/
contrib/Short-refcard.pdf
I Undergrad Guide to R: https:
//sites.google.com/site/undergraduateguidetor/
I Quick R: http://statmethods.net/