% Setting Up R % DPI R Bootcamp Dec. 3rd to 5th, 2012 % Jared Knowles
ggplot2;knitr;plyrFirst, watch this tutorial
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')
install.packages(c('plyr','lmtest','ggplot2','gridExtra','stringr',
'knitr','quantreg','xtable','lme4','eeptools','caret'),
repos="http://cran.wustl.edu/")
library(lmtest)
example(gqtest)
##
## 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
Type in in the terminal (or copy and paste)
library(ggplot2)
y <- rt(200, df = 5)
qplot(sample = y, stat = "qq")
library(ggplot2)
y <- rt(200, df = 5)
qplot(sample = y, stat = "qq")
options(repos = c(RStudio = "http://rstudio.org/_packages", getOption("repos")))
install.packages("shiny")
library(shiny)
runExample("06_tabsets")
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!
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.