Skip to content

Instantly share code, notes, and snippets.

View mmparker's full-sized avatar

Matt Parker mmparker

View GitHub Profile
@mmparker
mmparker / gist:969492
Created May 12, 2011 21:24
Pared-down test interpretation function
qft.interp <- function(nil, tb, mitogen, tbnil.cutoff = 0.35){
# Set a tolerance to avoid floating point comparison troubles.
tol <- .Machine$double.eps ^ 0.5
# Set up the results vector
result <- rep(NA, times = length(nil))
# Iterate through each test.
for(i in seq_along(result)){
@mmparker
mmparker / gist:969641
Created May 12, 2011 22:55
Sample test data
tests <- structure(list(nil = c(0.06, 0, 0.07, 0.2, 0.07, 0.15, 0.18,
0.05, 0.07, 0.06, 0.11, 9.41, 0.17, 0.09, 0.15, 0.06, 0.07, 0.1,
0.12, 0.17, 0.11, 0.13, 0.12, 0.12, 0.12, 0.13, 0.24, 0.14, 0.09,
0.17, 0.11, 0.07, 0.15, 10, 3.53, 5.48, 0.06, 0.06, 0.08, 0.1,
0.07, 0.1, 0.1, 0.08, 0.05, 0.08, 0.1, 0.07, 0.76, 0.04, 0.06,
0.07, 0.06, 0.08, 0.07, 0.09, 0.13, 0.05, 0.25, 0.12, 0.08, 0.78,
0.12, 0.11, 0.13, 0.1, 0.1, 0.05, 0.11, 0.13, 0.32, 0.09, 0.2,
0.16, 0.24, 0.29, 0.06, 0.17, 0.22, 0.1, 0.16, 0.08, 9, 0.1,
0.08, 0.15, 0.23, 0.07, 9, 0.13, 0.07, 0.06, 0.04, 0.04, 0.03,
10, 0.04, 0.05, 0.05, 0.04, 0.05, 0.04, 9, 0.06, 0.06, 0.05,
@mmparker
mmparker / tbwaffles.r
Created November 11, 2011 17:38
Example waffles charts in R using ggplot2
library(ggplot2)
# Here's some data I had lying around
tb <- structure(list(region = c("Africa", "Asia", "Latin America",
"Other", "US-born"), ncases = c(36L, 34L, 56L, 2L, 44L)), .Names = c("region",
"ncases"), row.names = c(NA, -5L), class = "data.frame")
@mmparker
mmparker / non_ply.r
Created December 14, 2011 17:40
Denver R User Group Lightning Talk on non-**ply functions in the plyr package
# This file is a brief exploration of the non-**ply functions in the
# plyr package. It was presented (poorly) for a lightning talk, so not all of
# the functions are as thoroughly explored and documented as I'd normally like -
# but this should at least get you started.
# The Incantation
options(stringsAsFactors = FALSE)
# Load plyr
library(plyr)
@mmparker
mmparker / batch_pandoc_win.bat
Created July 13, 2012 16:52
Batch conversion of .markdown to .html on Windows command line
REM This file converts all of the Markdown files to HTML.
REM Converting in the current directory
REM %%~ni returns just the filename of %%i, not its extension
for %%i in (*.markdown) do pandoc -f markdown -t html5 %%~ni.markdown > html/%%~ni.html
REM Converting a subdirectory - just slap it on front
for %%i in (report_pages/*.markdown) do pandoc -f markdown -t html5 report_pages/%%~ni.markdown > html/report_pages/%%~ni.html
@mmparker
mmparker / reg_group_and_group_var.r
Created July 31, 2012 19:32
Regression with a group variable and a group-trait variable
# Make a dataset for Channel A
dat.a <- data.frame(purchase = rbinom(n = 100, size = 1, prob = .1),
channel = "a")
# One for Channel B
dat.b <- data.frame(purchase= rbinom(n = 100, size = 1, prob = .2),
channel = "b")
# Add the rates
dat.a$rate <- sum(dat.a$purchase) / nrow(dat.a)
@mmparker
mmparker / README.md
Created September 7, 2012 23:25
Table-driven plot in d3.js

Best viewed in its own window (because I haven't set up the CSS properly yet).

This is a report to enable my clinicians to easily review clinic statistics at will. Click on rows in the table to plot that statistic; click again to remove it from the plot.

Very much a work in progress, so please feel free to heap on the feedback!

Built with the rampantly awesome D3.js.

@mmparker
mmparker / printpack.py
Created December 11, 2012 23:29
A very rough Python script for printing reordered and grouped pages from a PDF using pdftk and gsview. In a study, we're able to generate participant packets in bulk - dozens at a time. But the pages in the pdf aren't in exactly the right order, and we want to be able to print them in the correct groupings to take advantage of our printer's auto…
import os
import subprocess
import glob
# Check for the existence of a "printed" folder
# If it doesn't exist, make it
if not os.path.exists(os.path.join(os.getcwd(), "printed")):
os.mkdir(os.path.join(os.getcwd(), "printed"))
@mmparker
mmparker / case_rate_experiment.r
Created February 21, 2013 18:24
An experiment in how case rates change
# How do case rates vary as sensitivity changes, given
# fixed population
# fixed % positive
# fixed number of cases?
# Strings ain't factors
options(stringsAsFactors = FALSE)
@mmparker
mmparker / facet_annotation.r
Created July 18, 2013 21:48
Example of annotating each ggplot2 facet with the number of points it displays
# Strings ain't factors
options(stringsAsFactors = FALSE)
library(ggplot2)
library(plyr)