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
| SmoothCoefficientPlot <- function(models, modelnames = "", removeintercept = FALSE){ | |
| # models must be a list() | |
| Alphas <- seq(1, 99, 2) / 100 | |
| Multiplier <- qnorm(1 - Alphas / 2) | |
| zzTransparency <<- 1/(length(Multiplier)/4) | |
| CoefficientTables <- lapply(models, function(x){summary(x)$coef}) | |
| TableRows <- unlist(lapply(CoefficientTables, nrow)) |
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
| a1 <- c(4.2,3.2,11.1,1.3,2.2,2.0) | |
| a2 <- c(3.9,3.2,10.0,0.8,3.1,3.1) | |
| a3 <- c(6.3,2.5,9.8,0.9,2.2,2.4) | |
| a4 <- c(4.4,3.1,9.8,0.8,3.3,2.7) | |
| a5 <- c(4.8,3.0,9.9,0.7,3.3,2.4) | |
| a6 <- c(4.0,3.4,10.5,0.7,3.3,2.1) | |
| a <- rbind(a1,a2,a3,a4,a5,a6) | |
| # Get data into tidy format, starting with a, defined above |
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
| # Usage: | |
| # source iterm2.zsh | |
| # iTerm2 tab color commands | |
| # https://iterm2.com/documentation-escape-codes.html | |
| if [[ -n "$ITERM_SESSION_ID" ]]; then | |
| tab-color() { | |
| echo -ne "\033]6;1;bg;red;brightness;$1\a" | |
| echo -ne "\033]6;1;bg;green;brightness;$2\a" |
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
| source('https://raw.github.com/gist/1606595/269d61dfcc7930f5275a212e11f3c43771ab2591/GoogleReader.R') | |
| rbloggers = getRSSFeed(feedURL="http://r-bloggers.com/feed", | |
| email="GOOGLE READER EMAIL", | |
| passwd="GOOGLE READER PASSWORD", | |
| posts=5000) | |
| entries = rbloggers[which(names(rbloggers) == "entry")] | |
| length(entries) | |
| saveXML(rbloggers, file='rbloggers.xml') |
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
| ##read in the libraries and set the working directory | |
| library(tm) | |
| library(corrplot) | |
| setwd("/path/to/") | |
| ##read in the data and subset it to the relevant categories | |
| data <- read.csv("indvandringPolitikken.csv", fileEncoding = "latin1") | |
| data <- data[data$kategori == "Politik" | data$kategori == "Debat" | data$kategori == "Kronikken" | data$kategori == "Leder", ] | |
| ##create the corpus and clean it |
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
| function h = plotDecision(dprime,sdnoise,criterion) | |
| % h = plotDecision(dprime, sdnoise, criterion) | |
| % | |
| % plotDecision makes a plot of two Gaussian functions, inspired by signal | |
| % detection theory. The inputs are given in terms of standard deviates of | |
| % the signal distribution: | |
| % | |
| % dprime - d', the distance between the means of the Gaussians | |
| % sdnoise - $\sigma$, the ratio of the standard deviation of the noise to | |
| % the standard deviation of the signal. |
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
| body { | |
| font-family: Helvetica, arial, sans-serif; | |
| font-size: 14px; | |
| line-height: 1.6; | |
| padding-top: 10px; | |
| padding-bottom: 10px; | |
| background-color: white; | |
| padding: 30px; } | |
| body > *:first-child { |
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
| term<-c("egypt","jordan","israel","saudi") | |
| term_vec<-foreach(i=1:length(all_score_frames),.combine=rbind) %do% | |
| { | |
| score_row<-rep(0,length(term)) | |
| for(z in 1:length(score_row)) | |
| { | |
| sel_score<-all_score_frames[[i]][all_score_frames[[i]]$term==term[z],"score"] | |
| sel_score[is.na(sel_score)]<-0 | |
| if(length(sel_score)==0) | |
| sel_score<-0 |
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
| # Randomly allocating observations into groups, for, e.g. cross-validation | |
| kk <- 10 # Number of partitions, as in "kk-fold cross-validation." | |
| # Here is a data.frame full of good data: | |
| nn <- 1003 | |
| myData <- data.frame(matrix(rnorm(nn * 3), ncol = 3)) | |
| colnames(myData) <- LETTERS[1:3] | |
| # This does not work: | |
| whichK <- sample(LETTERS[1:kk], nrow(myData), replace = T) |
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
| # A simple approach to visually-weighted regression plots | |
| doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
| toInstall <- c("ggplot2", "reshape2", "MASS") | |
| if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")} | |
| lapply(toInstall, library, character.only = TRUE) | |
| # Generate some data: | |
| nn <- 1000 | |
| myData <- data.frame(X = rnorm(nn), |
OlderNewer