Skip to content

Instantly share code, notes, and snippets.

View epijim's full-sized avatar

James Black epijim

View GitHub Profile
geom_glowing_area <- function(
alpha = 1,
size = 1.5,
glow_alpha = 0.05,
layers = 10,
glow_size = .65){
geoms <- list(ggplot2::geom_area(alpha = .5, position = "identity",color = "#08f7fe"))
for(i in (layers+1):1){
score_cindex <- function(
zip_path, # zip file path
truth # in memory R object
){
library("pec") # pec functions don't work without the lib loaded :(
files_present <- zip::zip_list(zip_path)$filename
# Check files present
@epijim
epijim / score_auc.R
Last active September 8, 2022 12:52
score_auc <- function(
predictions,
truth
){
if (!"patientid" %in% names(predictions)) stop("patientid missing from predictions")
if (!"prediction" %in% names(predictions)) stop("prediction missing from predictions")
if (!"patientid" %in% names(truth)) stop("patientid missing from truth")
if (!"has_long_covid_diag" %in% names(truth)) stop("has_long_covid_diag missing from truth")
@epijim
epijim / c-index.R
Created August 23, 2022 08:27
Score a c-index
get_cindex <- function(
predictions = NULL,
test_truth = NULL
){
start_time <- Sys.time()
# Prep data
predictions_names <- c("patientid","prediction" )
if(!identical(predictions_names,names(predictions))) stop(paste(
# go to https://github.com/FortAwesome/Font-Awesome/tree/master/webfonts
# and install fa-solid-900.ttf, fa-regular-400.ttf and fa-brands-400.ttf
# then run extrafont::font_import()
library(tidyverse)
library(ggplot2)
library(waffle)
extrafont::loadfonts()
# From LEAP supplemental appendix
@epijim
epijim / weight.ipynb
Created February 18, 2016 07:46 — forked from anixdorf/weight.ipynb
Personal IPython Weight Notebook (http://nbviewer.ipython.org/gist/anixdorf/9769238)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# This is the server logic for a Shiny web application.
#
# Google sheets connection
## prepare the OAuth token and set up the target sheet:
## - do this interactively
## - do this EXACTLY ONCE
# shiny_token <- gs_auth() # authenticate w/ your desired Google identity here
@epijim
epijim / campubdistances.csv
Created October 11, 2014 15:12
Cambridge pub_distances
latlon_1 latlon_2 minutes metres
52.209025,0.118255 52.204115,0.11827 8.5 692
52.209025,0.118255 52.213738,0.124159 9.4 771
52.209025,0.118255 52.204222,0.120324 8.2 658
52.209025,0.118255 52.207309,0.124159 7.8 650
52.209025,0.118255 52.204932,0.127807 13.7 1130
52.209025,0.118255 52.198334,0.142623 28.1 2308
52.209025,0.118255 52.193371,0.133181 25.5 2080
52.209025,0.118255 52.21817,0.146081 30.4 2453
52.209025,0.118255 52.230666,0.138805 41.3 3348
@epijim
epijim / jb_pubdistance.r
Last active August 29, 2015 14:07
Pub distance and TSP solver
jb_pubdistance <- function(
v_pubs=c("The Cambridge Brew House","The Cambridge Blue",
"King Street Run P.H.","The Elm Tree","The Regal"),
v_location="Cambridge, UK",
v_zoom=13,
listpubs=FALSE,
cam_pubs=TRUE,
crow_distances=FALSE,
units="minutes"){
@epijim
epijim / cam_pubs.csv
Last active August 29, 2015 14:07
Cambridge pubs - scraped from FSA site
name type rating lat lon
Baron Of Beef Pub/bar/nightclub 4 52.209025 0.118255
Bath House Pub/bar/nightclub 4 52.204115 0.11827
Boathouse P.H. Pub/bar/nightclub 4 52.213738 0.124159
BRB The Cow Pub/bar/nightclub 4 52.204222 0.120324
Champion Of The Thames Pub/bar/nightclub 5 52.207309 0.124159
Clarendon Arms Pub/bar/nightclub 5 52.204932 0.127807
Earl of Beaconsfield Pub/bar/nightclub 5 52.198334 0.142623
Earl Of Derby Pub/bar/nightclub 5 52.193371 0.133181
Green Dragon Public House Pub/bar/nightclub 5 52.21817 0.146081