Skip to content

Instantly share code, notes, and snippets.

ascvd_estimator = reactive({
female.risk <- 1.0 / (1.0 + exp( - (
-12.823110 +
0.106501 * as.numeric(input$age) +
0.432440 * as.numeric(input$black) +
0.000056 * (as.numeric(input$sysbp) ^ 2) +
0.017666 * as.numeric(input$sysbp) +
0.731678 * as.numeric(input$rxbp) +
0.943970 * as.numeric(input$dm) +
1.009790 * as.numeric(input$cursmoke) +
@johnschrom
johnschrom / gist:276a83f244ed8af21f83
Last active August 29, 2015 14:22
Predictive Genes
# Data frame for which genes to include by disease
excl <- data.frame('gene' = c(NA), 'round' = c(NA))
# Remove 30% of genes each round
while(nrow(excl) < nrow(d.qn)) {
cat('Running with', excl.n, 'genes excluded...\n')
# Run SVM
svm.model <- svm(t(as.matrix(d.qn[-excl$gene,])), # features, minus excluded genes
tc, # class of each sample
@johnschrom
johnschrom / gist:3f61097e78cedc7d5229
Created June 5, 2015 17:05
Quintile normalization
# Create a refernce distribution using the median of all samples
ref <- apply(apply(data.normalized[,3:ncol(data.normalized)],
2,
FUN=sort),
1,
FUN=median)
# Create a emperical cdf function for the reference distribution
ref.cdf <- ecdf(ref)
# Quintile normalize!
@johnschrom
johnschrom / map-my-moves.R
Created May 8, 2014 23:59
Map Moves Data
library(ggplot2)
library(maps)
library(mapproj)
# Thanks to Ernesto at Quantified Self
# http://quantifiedself.com/2014/03/map-moves-data/
# This is set up take data from the "Tracks" export, using:
# https://labs.traqs.me/moves/
@johnschrom
johnschrom / ggplot.R
Created May 2, 2014 04:26
Chart plot formats with ggplot2
library(ggplot2)
library(grid)
ggplot(data, aes(x=x, y=y)) +
geom_point() +
# geom_line() +
ylab('y label') +
xlab('x label') +
theme_bw() +
scale_color_manual(values = c('#023F8A', '#BF4D28')) +
@johnschrom
johnschrom / gist:8761604
Last active August 29, 2015 13:55
Map of flights (international version)
# Load Airports
# This comes from: http://openflights.org/data.html
airports <- read.csv('airports.dat', header=F);
colnames(airports) <- c('id', 'name', 'city', 'county', 'faa', 'icao', 'lat', 'lng', 'alt', 'timezone', 'dst')
airports$faa <- as.character(airports$faa)
# Load trips
# a file with: "source-airport,destination-airport,date"
# e.g., "MSP,SFO,2014-01-01"
trips <- read.csv('trips.csv', header=F);
@johnschrom
johnschrom / gist:8748603
Created February 1, 2014 06:00
Making a map of flights
# Load Airports
# This comes from: http://openflights.org/data.html
airports <- read.csv('airports.dat', header=F);
colnames(airports) <- c('id', 'name', 'city', 'county', 'faa', 'icao', 'lat', 'lng', 'alt', 'timezone', 'dst')
airports$faa <- as.character(airports$faa)
# Load trips
# a file with: "source-airport,destination-airport,date"
# e.g., "MSP,SFO,2014-01-01"
trips <- read.csv('trips.csv', header=F);
@johnschrom
johnschrom / gist:8638763
Last active January 5, 2021 21:20
Making a map of foursquare checkins
library(ggplot2)
library(maps)
library(mapproj)
###############################################################################
# Step 1: Get data from Foursquare
# If you already have it, then great :) Otherwise, you can use RPI. The source
# is listed below, and there are instructions for getting keys in the readme.
# RPI: https://github.com/johnschrom/RPI
@johnschrom
johnschrom / gist:4725269
Created February 6, 2013 19:54
Installing a package in R from source -- I don't know why I can never remember this command.
install.packages(file_name_and_path, repos = NULL, type="source")
@johnschrom
johnschrom / gist:4692841
Created February 1, 2013 17:43
Sometimes you want to block certain IP addresses from accessing your website. Add this snippet to your .htaccess, change "IP-ADDRESS" to be their IP address, and they'll get forwarded to your specified URL.
RewriteCond %{REMOTE_HOST} IP-ADDRESS
RewriteRule .* "http://www.google.com" [R=301,L]