% Setting Up R % DPI R Bootcamp Dec. 3rd to 5th, 2012 % Jared Knowles

Getting Ready for the DPI R Bootcamp

Materials

Step 1: Install R

Installing R on Windows

Installing R on a Mac

Installing R on Ubuntu or Debian Linux

Step 2: RStudio

Step 3: Install packages

First, watch this tutorial

Install Packages

Install Packages (2)

install_new<-function(mypkg){
  if (mypkg %in% installed.packages()) cat("Package already installed")
  else{cat("Package not found, so installing with dependencies...\n 
           Press CTRL C to abort.")
    Sys.sleep(5)
    install.packages(mypkg,repos="http://cran.wustl.edu/")
}
}

install_new('plyr')
install_new('lmtest')
install_new('ggplot2')
install_new('gridExtra')
install_new('eeptools')
install_new('stringr')
install_new('knitr')
install_new('quantreg')
install_new('xtable')
install_new('lme4')
install_new('caret')

Alternate Install

install.packages(c('plyr','lmtest','ggplot2','gridExtra','stringr',
                   'knitr','quantreg','xtable','lme4','eeptools','caret'),
                 repos="http://cran.wustl.edu/")

Run RStudio

library(lmtest)
example(gqtest)

And you should see…

## 
## gqtest> ## generate a regressor
## gqtest> x <- rep(c(-1,1), 50)
## 
## gqtest> ## generate heteroskedastic and homoskedastic disturbances
## gqtest> err1 <- c(rnorm(50, sd=1), rnorm(50, sd=2))
## 
## gqtest> err2 <- rnorm(100)
## 
## gqtest> ## generate a linear relationship
## gqtest> y1 <- 1 + x + err1
## 
## gqtest> y2 <- 1 + x + err2
## 
## gqtest> ## perform Goldfeld-Quandt test
## gqtest> gqtest(y1 ~ x)
## 
##  Goldfeld-Quandt test
## 
## data:  y1 ~ x 
## GQ = 2.542, df1 = 48, df2 = 48, p-value = 0.0007882
## 
## 
## gqtest> gqtest(y2 ~ x)
## 
##  Goldfeld-Quandt test
## 
## data:  y2 ~ x 
## GQ = 0.7892, df1 = 48, df2 = 48, p-value = 0.7924

And test the graphics…

Type in in the terminal (or copy and paste)

library(ggplot2)
y <- rt(200, df = 5)
qplot(sample = y, stat = "qq")

Results


library(ggplot2)
y <- rt(200, df = 5)
qplot(sample = y, stat = "qq")

plot of chunk unnamed-chunk-6

That's all

Optional

options(repos = c(RStudio = "http://rstudio.org/_packages", getOption("repos")))
install.packages("shiny")

Optional Cont.

library(shiny)
runExample("06_tabsets")

You are ready to go!

See you on December 3rd to the 5th to find out how to go from these basic steps to using R to learn from your data.

Can't wait to see you in Madison!

Attribution and License

This work (R Tutorial for Education, by Jared E. Knowles), in service of the Wisconsin Department of Public Instruction, is free of known copyright restrictions.

Public Domain Mark