This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | rm(list = ls()) | |
| # from http://projecteuler.net/index.php?section=problems&id=42 | |
| Text <- readLines("http://projecteuler.net/project/words.txt") | |
| TextString <- gsub("\"", "", unlist(strsplit(Text, "\",\""))) | |
| TriangleNumbers <- cumsum(1:100) | |
| StringLetters <- strsplit(TextString, "") | |
| LetterRank <- rank(LETTERS) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require(ggplot2) | |
| Data <- data.frame(Group = sample(c(1, 2), 100, replace = T)) | |
| Data$Value <- rnorm(100, Data$Group * 2 - 6, 1) | |
| Data$Group <- LETTERS[1:2][Data$Group] | |
| Plot1 <- qplot(Value, data = Data, geom = "density", fill = Group, alpha = I(1/2)) | |
| Plot1 <- Plot1 + scale_fill_manual(values = c("#3E6995", "#953E3E")) | |
| print(Plot1) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require(cluster) | |
| Polarizer <- function(group, data){ | |
| if((mean(is.na(group)) > 0.99) | length(group) <= 1){ | |
| Output <- c(NA, NA) | |
| } else { | |
| SameGroup <- try(as.matrix(daisy(data.frame(group))) == 0) | |
| diag(SameGroup) <- NA | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | PaletteMaker <- function(pid = "GG"){ | |
| pal <- colorRampPalette(c(gray(0), gray(1)))(5) | |
| if(pid == "GG") pal <- c("#69D2E7", "#A7DBD8", "#E0E4CC", "#F38630", "#FA6900") | |
| if(pid == "TP") pal <- rev(c("#ECD078", "#D95B43", "#C02942", "#542437", "#53777A")) | |
| if(pid == "cuek") pal <- c("#556270", "#4ECDC4", "#C7F464", "#FF6B6B", "#C44D58") | |
| if(pid == "OF") pal <- c("#00A0B0", "#6A4A3C", "#CC333F", "#EB6841", "#EDC951") | |
| if(pid == "SP") pal <- rev(c("#BCBDAC", "#CFBE27", "#F27435", "#F02475", "#3B2D38")) | |
| if(pid == "VM") pal <- c("#8C2318", "#5E8C6A", "#88A65E", "#BFB35A", "#F2C45A") | |
| if(pid == "MC") pal <- rev(c("#FAD089", "#FF9C5B", "#F5634A", "#ED303C", "#3B8183")) | |
| if(pid == "yab") pal <- c("#351330", "#424254", "#64908A", "#E8CAA4", "#CC2A41") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # See: http://stats.stackexchange.com/questions/12148/looking-for-a-name-for-a-mean-influencing-statistic | |
| # Somewhat personalized | |
| sdfBeta <- function(numer, denom = 1){ | |
| if(identical(1, denom)){denom <- rep(1, length(numer))} | |
| Bj <- sum(numer, na.rm = T) / sum(denom, na.rm = T) | |
| Bjni <- (sum(numer, na.rm = T) - numer) / (sum(denom, na.rm = T) - denom) | |
| StdError <- sd(Bjni, na.rm = T) | |
| Value <- (Bj - Bjni) / StdError | |
| names(Value) <- names(numer) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # http://en.wikipedia.org/wiki/Logit#Definition | |
| # Logit: From probability to normal | |
| # Logistic (inverse logit): From normal to probability | |
| Logit <- function(p){log(p / (1 - p))} | |
| Logistic <- function(x){exp(x) / (1 + exp(x))} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | library(ggplot2) | |
| x.centers <- c(-2, 1, 3) | |
| x.ses <- c(1, 2, 1/2) | |
| y.centers <- c(1/2, -2, 2) | |
| y.ses <- c(1/4, 3/2, 1) | |
| NN <- 5000#0 | |
| Sample1 <- cbind(rnorm(NN, x.centers[1], x.ses[1]), rnorm(NN, y.centers[1], y.ses[1])) | |
| Sample2 <- cbind(rnorm(NN, x.centers[2], x.ses[2]), rnorm(NN, y.centers[2], y.ses[2])) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Eddfinder <- function(v){ | |
| v=floor(v) | |
| possibles=1:max(v) | |
| count=function(w){length(v[v>w])} | |
| which.max(lapply(possibles,count)<=possibles) | |
| } | |
| Eddington <- function(value,name){ | |
| temp=lapply(split(value,name),eddfinder) | |
| unlist(temp) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
| toInstall <- c("foreign", "ggplot2", "reshape2", "plyr", "devtools") | |
| if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
| lapply(toInstall, library, character.only = TRUE) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | library(ggplot2) | |
| library(scales) | |
| # Generate data | |
| myData <- data.frame(x = rnorm(1000), | |
| y = rnorm(1000)) | |
| myData$z <- with(myData, x * y) | |
| # Make an untransformed plot | |
| badVersion <- ggplot(myData, |