Skip to content

Instantly share code, notes, and snippets.

View sachsmc's full-sized avatar

Michael Sachs sachsmc

View GitHub Profile
cibars <- function(x, y, y.se, tinyfactor = 50, ...){
lower <- y - 1.96*y.se
upper <- y + 1.96*y.se
segments(x0 = x, y0 = lower, x1 = x, y1 = upper, ...)
tinybarwidth <- (max(x) - min(x))/tinyfactor
segments(x0 = x - tinybarwidth, y0 = lower, x1 = x + tinybarwidth, y1 = lower, ...)
segments(x0 = x - tinybarwidth, y0 = upper, x1 = x + tinybarwidth, y1 = upper, ...)
@sachsmc
sachsmc / myBoxplot.R
Last active January 1, 2016 05:19
Boxplot with quantile whiskers
myboxplot <- function(datalist, quantiles = c(.1, .9), names, ...){
bp <- boxplot(datalist, plot = FALSE)
quants <- sapply(datalist, function(df){
quantile(df, quantiles, na.rm = T)
favre <- function(model, coeff.index){
favre2 <- matrix(c(1, -1, 0, 0,
1, 0, -1, 0,
1, 0, 0, -1
), nrow = 3, ncol = 4, byrow = T)
theta.hat <- favre2 %*% as.matrix(model$coeff[coeff.index])
cov.hat <- favre2 %*% vcov(model)[coeff.index, coeff.index] %*% t(favre2)
@sachsmc
sachsmc / ddplyWithTotals.R
Created February 5, 2014 02:24
ddplyWithTotals.R
##############################################################
## Author: Michael Sachs, michael.sachs@nih.gov
## Version 1.0
## Date Updated: 9/16/2013
# Description: An extension of the ddply function from the
# plyr package that additionally evaluates the user-supplied
# function on subsets defined by lower-order combinations of the
# variables. This is useful for calculating sub-totals and totals.
@sachsmc
sachsmc / freq-approach.R
Created August 20, 2014 14:28
frequentist approach
## frequentist approach for comparison
freq_leaveout <- function(formula) {
leftout <- sapply(1:n.trials, function(i){
fit.biv <- lm(formula, data = hat.test[-i, ])
predict(fit.biv, newdata = hat.test)[i]
})
@sachsmc
sachsmc / Rjobs
Last active August 29, 2015 14:09
Parallel Jobs on Biowulf
Rscript --vanilla run.R 1 > run-1.Rout
Rscript --vanilla run.R 2 > run-2.Rout
Rscript --vanilla run.R 3 > run-3.Rout
Rscript --vanilla run.R 4 > run-4.Rout
Rscript --vanilla run.R 5 > run-5.Rout
Rscript --vanilla run.R 6 > run-6.Rout
Rscript --vanilla run.R 7 > run-7.Rout
Rscript --vanilla run.R 8 > run-8.Rout
Rscript --vanilla run.R 9 > run-9.Rout
Rscript --vanilla run.R 10 > run-10.Rout
@sachsmc
sachsmc / example.Rmd
Created November 14, 2014 18:13
Sparklificator in rmarkdown
---
title: "Sparklify"
author: "Michael Sachs"
date: "November 14, 2014"
output:
html_document:
self_contained: false
---
<head>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
@sachsmc
sachsmc / man-legend.R
Last active May 29, 2018 21:36
Add manual legend in ggplot2
tm <- data.frame(Marker = sort(rep(letters[1:5], 10)), x = runif(50), y = runif(50))
p1 + geom_line(data = tm, aes(linetype = Marker, x = x, y = y), alpha = 0) +
scale_linetype(guide = guide_legend(override.aes = list(alpha = 1)), labels =
c(expression(A[1]), expression(A[2]), expression(A[3]), expression(A[4]), expression(A[5]))) +
theme(legend.position = c(.75, .25))
@sachsmc
sachsmc / Submit to biowulf
Last active August 29, 2015 14:21
MPI Apply on Biowulf
qsub -v np=52 -l walltime=424:00:00, nodes=26 simRun.bat
@sachsmc
sachsmc / .block
Last active February 17, 2016 18:21
Scrape your personal Capital Bikeshare Trip data
license: mit