Skip to content

Instantly share code, notes, and snippets.

# Define the function
ggd.qqplot = function(pvector, main=NULL, ...) {
o = -log10(sort(pvector,decreasing=F))
e = -log10( 1:length(o)/length(o) )
plot(e,o,pch=19,cex=1, main=main, ...,
xlab=expression(Expected~~-log[10](italic(p))),
ylab=expression(Observed~~-log[10](italic(p))),
xlim=c(0,max(e)), ylim=c(0,max(e)))
lines(e,e,col="red")
}
# Define the function
ggd.qqplot = function(pvector, main=NULL, ...) {
o = -log10(sort(pvector,decreasing=F))
e = -log10( 1:length(o)/length(o) )
plot(e,o,pch=19,cex=1, main=main, ...,
xlab=expression(Expected~~-log[10](italic(p))),
ylab=expression(Observed~~-log[10](italic(p))),
xlim=c(0,max(e)), ylim=c(0,max(e)))
lines(e,e,col="red")
}
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
@jaehyeon-kim
jaehyeon-kim / downloadStockData
Created November 19, 2014 01:54
download NASDAQ stock data
# assumes codes are known beforehand
codes <- c("MSFT", "1234")
urls <- paste0("http://www.google.com/finance/historical?q=NASDAQ:",
codes,"&output=csv")
paths <- paste0(codes,"csv")
missing <- !(paths %in% dir(".", full.name = TRUE))
missing
# simple error handling in case file doesn't exists
downloadFile <- function(url, path, ...) {
@jaehyeon-kim
jaehyeon-kim / downloadMergeStockData
Created November 19, 2014 09:54
download and merge NASDAQ stock data
library(lubridate)
library(data.table)
library(plyr)
library(dplyr)
# create data folder
dataDir <- paste0("data",format(Sys.Date(),"_%Y_%m_%d"))
if(file.exists(dataDir)) {
unlink(dataDir, recursive = TRUE)
dir.create(dataDir)
library(lubridate)
library(stringr)
library(reshape2)
library(plyr)
library(dplyr)
# read all csv files and merge
# assumes files exist in data folder
dataDir <- "data"
files <- dir(dataDir, full.name = TRUE)
library(lubridate)
library(stringr)
library(reshape2)
library(plyr)
library(dplyr)
# create data folder
dataDir <- paste0("data","_",format(Sys.Date(),"%Y-%m-%d"))
if(file.exists(dataDir)) {
unlink(dataDir, recursive = TRUE)
library(knitr)
library(lubridate)
library(stringr)
library(reshape2)
library(plyr)
# create data folder
dataDir <- paste0("data","_",format(Sys.Date(),"%Y-%m-%d"))
if(file.exists(dataDir)) {
unlink(dataDir, recursive = TRUE)
## set up variables
size <- 36000
numUsers <- 4900
# roughly each user has 7 sessions
numSessions <- (numUsers / 7) - ((numUsers / 7) %% 1)
## create data frame
set.seed(123457)
userIds <- sample.int(numUsers, size=size, replace=TRUE)
ssIds <- sample.int(numSessions, size=size, replace=TRUE)
MyData <- data.frame(Year=seq(2000,2009))
# year variables
dim <- length(MyData$Year)
yMat <- matrix(NA, nrow=dim, ncol=dim)
for(i in 1:dim) {
yMat[i,] <- rbind(t(MyData)) # transpose
}
yMat