Skip to content

Instantly share code, notes, and snippets.

@rcquan
rcquan / global.R
Last active Sep 15, 2015 — forked from dempseydata/global.R
AB Test Alpha 2
View global.R
###############################################
##
## Attempt no 2 at building a shiny web app
## for AB Testing use - using global.R
##
## global.R - loading and defining variables for the global environment
##
###############################################
# Pallette used in some charts as a general indicator color for better or worse that the control group
@rcquan
rcquan / nyc_playgrounds_analysis.R
Created Feb 10, 2015
nyc_playgrounds_analysis
View nyc_playgrounds_analysis.R
#############################
# Ryan Quan
# GitHub Username: rcquan
# Twitter: @ryancquan
# Email: ryan.quan08@gmail.com
#
# The following code loads the NYC Playgrounds Data and
# shapefiles
#############################
View sleep_analysis.R
library(ggplot2)
library(scales)
library(dplyr)
library(grid)
hoursToMinutes <- function(hours) {
# converts character HH:MM data to total minutes
# Args:
# hours - a character vector in "HH:MM" format
# Returns:
View madHam.r
#############################
# Ryan Quan
# NLP and classifcation of the
# Federalist corpus
#############################
library(tm)
library(glmnet)
library(infotheo)
library(rpart)
library(ggplot2)
View interactiveViz.R
library(rCharts)
library(zoo)
# Data transformations
names(medMis_plot) <- c("Month", "MedicalMisconductCount")
medMis_plot$Month <- as.yearmon(medMis_plot$Month)
medMis_plot <- transform(medMis_plot, Month = as.character(Month))
# Morris Line Plot
m1 <- mPlot(x = "Month", y = colnames(medMis_plot)[2], data = medMis_plot, type = "Line")
View staticViz.R
# Time-series plot
library(ggplot2)
library(scales)
# By month
m = ggplot(data = medMis_month, aes(x = Time, y = Freq)) + geom_line()
m = m + scale_x_datetime(labels = date_format("%Y"), breaks = date_breaks("2 years"))
m = m + ylab("No. of Physicians Disciplined") +
ggtitle("Physicians Disciplined by NYS DOH from 1990-2013")
m
View preprocessMedMis.R
# Convert variable from factor into "Date" class
medMis$Effective.Date <- as.character(medMis$Effective.Date)
medMis$Effective.Date <- as.POSIXct(medMis$Effective.Date, format = "%m/%d/%Y")
# Order dataset by Effective.Date from 1990-2014
medMis <- (medMis[order(medMis$Effective.Date),])
# Create time-series data
medMis_month <- as.data.frame(table(format(medMis$Effective.Date, "%Y-%m-01")), stringsAsFactors = FALSE)
medMis_plot <- as.data.frame(table(format(medMis$Effective.Date, "%Y-%m")), stringsAsFactors = FALSE)
View loadData.R
# Check if file exists in working directory; if not, downloads
fileName = "medMis.csv"
if (!file.exists(fileName)){
url <- "https://health.data.ny.gov/api/views/ebmi-8ctw/rows.csv?accessType=DOWNLOAD"
fileName <- "medMis.csv"
download.file(url, fileName, method = "curl")
}
medMis <- read.csv(fileName)
View escapeAmpersands.R
library(RCurl)
library(XML)
escapeAmpersands <- function(url) {
doc <- getURL(url)
## escape ampersands in XML
validDoc <- gsub("&", "&amp;", doc)
validDoc
}
View readBedgraph.R
library(BiSeq)
readBedgraph <- function(inputDirectory, nSamples = 8) {
## get list of file names
fileNames <- list.files(path = inputDirectory, pattern = ".bedGraph")
## parse sample name from file name
sampleNames <- sapply(fileNames,function(fileName) {
gsub("_r123_R1_val_1.fq_bismark_bt2_pe.bedGraph", "", fileName)
}, USE.NAMES = FALSE)