Skip to content

Instantly share code, notes, and snippets.

View cdesante's full-sized avatar

Christopher DeSante cdesante

  • Indiana University
View GitHub Profile
@cdesante
cdesante / plottext2.r
Created November 14, 2012 05:48
plottext2
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
text.plots <- data.frame(
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) ,
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3),
LENGTH = c(rnorm(500, 4, 2),
rnorm(500, 7, 1.2),
@cdesante
cdesante / plottext1.r
Created November 14, 2012 04:57
plottext1
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
text.plots <- data.frame(
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) ,
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3),
LENGTH = c(rnorm(500, 4, 2),
rnorm(500, 7, 1.2),
@cdesante
cdesante / plottext3.r
Created November 14, 2012 04:53
plottext3
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
text.plots <- data.frame(
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) ,
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3),
LENGTH = c(rnorm(500, 4, 2),
rnorm(500, 7, 1.2),
@cdesante
cdesante / breaks.r
Created November 12, 2012 23:15
custom breaks
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
text.plots <- data.frame(
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) ,
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3),
LENGTH = c(rnorm(500, 4, 2),
rnorm(500, 7, 1.2),
@cdesante
cdesante / legends2.r
Created November 11, 2012 23:46
legends2
toInstall <- c("ggplot2", "reshape")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
library(reshape)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
party.and.region <- ANES[,c(1, 12, 16)]
party.and.region.year <- melt(party.and.region, id=c("year", "south"), na.rm=TRUE)
party.region.time <- (cast(party.and.region.year, year+south~variable, mean, na.rm=T) )
@cdesante
cdesante / legends1.r
Created November 11, 2012 23:35
legends1
toInstall <- c("ggplot2", "reshape")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
library(reshape)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
party.and.region <- ANES[,c(1, 12, 16)]
party.and.region.year <- melt(party.and.region, id=c("year", "south"), na.rm=TRUE)
party.region.time <- (cast(party.and.region.year, year+south~variable, mean, na.rm=T) )
@cdesante
cdesante / 53free.r
Created November 8, 2012 00:35
five.thirty.free
library(plyr)
library(ggplot2)
library(grid)
election.data <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/election2012.csv")
five.thirty.free <- function (SIMS) {
Mode <- function(X) {
@cdesante
cdesante / election3.r
Created November 8, 2012 00:30
election3
Ohio <- c()
California <- c()
Alabama <- c()
for ( i in 1:1000) {
Ohio[i] <- sample (c("Obama", "Romney"), 1)
California[i] <- sample(c(rep("Obama", 9), "Romney"))
Alabama[i] <- sample( c(rep("Obama", 1), rep("Romney", 9)), 1)
}
@cdesante
cdesante / confidence.r
Created November 7, 2012 23:42
3 Point Shooting
N <- 1:3
SE <- c(.272, .19, .16)
HI <- c(1.2, 1.0, .98)
LO <- c( .13, .29, .36)
AVG <- c(.667, .667, .667)
Shots <- c(1,0,1)
for (i in 4:50) {
Shots[i] <- sample(c(1,0,1), 1)
N[i] <- i
SE[i] <- sqrt(mean(Shots)/N[i])
@cdesante
cdesante / joint2.r
Created November 7, 2012 23:02
Tiger and LeBron
Tiger <- c()
LeBron <- c()
for (i in 1:1000) {
LeBron[i] <- sample(c( rep("Makes FT", 77), rep("Misses FT", 23)), 1)
Tiger[i] <- sample(c( rep("Fairway", 49), rep("Not FW", 51)), 1)
}
table(LeBron, Tiger)