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
# calculate average number of drug doses per patient | |
col.names.drugs <- names(Filter(function(y) (!is.null(y) && y=="Drugs") , map(dict, "Classification1"))) | |
tdt <- copy(data2d.wide) | |
tdt[, id:= paste0(site, "_", episode_id)] | |
setkey(tdt, id) | |
dim(tdt) | |
names(tdt) | |
col.names <- col.names.drugs[col.names.drugs %in% names(tdt)] | |
tdt[1:10,print(.SD), by=id, .SDcols=col.names] | |
drug.doses <- tdt[,lapply(.SD, function(x) sum(ifelse(x=="NA",as.integer(NA),1L), na.rm=TRUE)), by=.(site, id), .SDcols=col.names] |
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
#' @title Mosaic plot using ggplot. | |
#' | |
#' @description | |
#' Creates a mosaic plot where the dimensions of the cells of a | |
#' confusion matrix represent their marginal proportions. | |
#' | |
#' @details | |
#' Credit for initial iteration to | |
#' [Edwin](http://stackoverflow.com/a/19258045/992999) | |
#' This version adds color brewer options and tidies the labelling |
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
# via https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q2/000874.html | |
# Calculate the median odds ratio | |
# ------------------------------- | |
MOR <- function(my.var, digits = 2) | |
{ # MOR arguments: my.var = variance associated with level 2 clustering variable | |
# digits = number of decimal places to which MOR value will be rounded. | |
Median.OR <- round(exp(sqrt(2*my.var)*qnorm(.75)), digits) | |
paste("Median Odds-Ratio (MOR) = ", Median.OR) } |
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
/* | |
## Create a rug plot | |
_____________________ | |
CreatedBy: Steve Harris | |
CreatedAt: 111291 | |
ModifiedAt: 120701 | |
Log |
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
gen.sofa.c <- function(bpsys, bpdia, rxcvs_drug=NULL, rxcvs_dose=NULL) { | |
rx1 <- c("Adrenaline", "Noradrenaline") | |
rx2 <- c("Dopamine") | |
rx3 <- c("Vasopressin") | |
rx <- c(rx1, rx2, rx3, "Other") | |
# Print these descriptions so you know what you have passed to the function | |
bpmap <- round(bpdia + (bpsys - bpdia) / 3) |
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
score.charlson <- function(data) { | |
# data is a datatable containing the columns you need | |
# identify the columns with pmh in the name | |
require(data.table) | |
charlson.values <- data[,.(pmhmi, pmhhf, pmhpvd, pmhcvd, pmhdem, pmhcopd, pmhcopd, pmhctd, pmhud, pmhmld, pmhdm, pmhhemi, pmhckd, pmhdmend, pmhtumour, pmhleuk, pmhlymph, pmhsld, pmhmets, pmhaids)] | |
charlson.matrix <- as.matrix(charlson.values) | |
# Now I need to convert the NA's to 0 and >0 to 1 in matrix | |
charlson.matrix <- apply(charlson.matrix, 2, function(x) ifelse(is.na(x), 0, ifelse(x>=1,1, 0))) | |
# Now create a vector of scores | |
# Note that the order of the columns selected above *must* match the order of the scores here |
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
# Test data: 1000 patients with two different age distributions | |
tdt <- data.table(age.old=rnorm(1000, mean=65, sd=15), age.young=rnorm(1000,mean=55,sd=10)) | |
# Function to compare two distributions using qplot | |
qqplot <- function(x,y, data=wdt, n=100) { | |
lab.x = x | |
lab.y = y | |
x <- with(data, get(x)) | |
x <- sapply(seq(0,1,1/n), function(q) quantile(x, q, na.rm=TRUE)) | |
y <- with(data, get(y)) |
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
time24_regex = re.compile( r"""\b ([01]?\d|2(?=[0-3])\d) [:|.]? ([0-5]?\d) \b""", re.VERBOSE) |
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
var dataset; // declare a global var to hold data | |
d3.csv("data/univar.csv", function(error, data) { | |
if(error) { | |
console.log(error); | |
} | |
else { | |
console.log(data); | |
} |
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
#! /usr/bin/python | |
# author: Steve Harris | |
# Convert short nvAlt image links to full path for previewing in Marked | |
# Todo | |
# ==== | |
# - move the pathto line to a variable | |
# - post this script as a gist |