2. Introduction!
• R is a free, open-source statistical and data visualization
software application
• Open source = large community of developers
• Increasing in popularity
(Muenchen, 2012)
Aaron R. Baggett | 02/15/2013! 2!
R!
3. Introduction!
• Programming language
• Can interface with many other programs
• Object oriented language
a <- 15
b <- 15
a + b
[1] 30
Aaron R. Baggett | 02/15/2013! 3!
R!
5. Introduction!
• Flexible and versatile
• 4,336 user contributed packages
o Statistics and data analysis
o Psychometrics
o Graphics
o Economics and finance
Aaron R. Baggett | 02/15/2013! 5!
R!
6. Introduction!
• Free graphical user interface (GUI) for R
o http://www.rstudio.com/
o https://twitter.com/rstudioapp
• Still requires use of syntax
o e.g., reg.fit <- lm(y ~ x1 + x2 + x3, data = df)
• Not limited by point and click interface
Aaron R. Baggett | 02/15/2013! 6!
RStudio!
7. Introduction!
• Consolidated work environment
o Four window panes
1. R Console
2. Script
3. Workspace
4. Utility tabs
a. Files
b. Plots
c. Packages
d. R Help
Aaron R. Baggett | 02/15/2013! 7!
Advantages of RStudio!
8.
9. Introduction!
• Templates for document preparation
o knitr: http://yihui.name/knitr/
o Sweave: http://goo.gl/gMkqo
o R Markdown: http://goo.gl/YHBB1
• LaTeX integration
o knitr works best for me
Aaron R. Baggett | 02/15/2013! 9!
Advantages of RStudio!
10. Document Preparation!
• Pronounced “Lah-Tek”
• Document preparation system
• Sections, cross-references, bibliographies
• Equation/math typesetting
• Stability
• Like R, large, active community
Aaron R. Baggett | 02/15/2013! 10!
LaTeX http://www.latex-project.org/
13. Document Preparation!
• Comprehensive package for generating “Elegant,
flexible and fast, dynamic report generation with R.”
• Easily handles embedding R code directly in LaTeX
documents
• Tutorial video from knitr developers:
http://www.screenr.com/qcv8
Aaron R. Baggett | 02/15/2013! 13!
knitr!
14.
15. knitr!
• All inline R code begins with: <<>>=
• And ends with: @
Aaron R. Baggett | 02/15/2013! 15!
knitr Code!
<<tidy = TRUE>>=
library(ggplot2)
names(diamonds) #Returns variable names
head(diamonds) #Returns first six rows of dataset
with(diamonds, summary(carat)) #Summarize 'carat' variable
with(diamonds, cor(carat, price)) #Correlate 'carat' and 'price’.
@
<<fig.width = 6, fig.height = 6, tidy = FALSE>>=
qplot(carat, data = diamonds, fill = color, geom = ‘histogram’,
binwidth = 0.4, xlim = c(0,3),
main = ‘Stacked Histogram of Diamond Carat Weight by Color’,
xlab = ‘Carat Weight’, ylab = ‘Count’)
@
16. knitr!
Aaron R. Baggett | 02/15/2013! 16!
knitr Code!
<<box, fig.width=5.5, fig.height=5.5, fig.align='center', tidy=FALSE>>=
plot(Sex, Extrov, main =
"Box-Whisker Plot of Variancen(Extroversion by Sex)”,
col = "dodgerblue3", ylab = "Extroversion")
@
newpage
setlengthparindent{0pt}textbf{large{5). Test to see if there is a
mean difference in Extroversion between males and females (make sure
you test the assumption of homogeneity of variance and set up your t-
test appropriately)}}
vspace*{-.55in}