Skip to content

Instantly share code, notes, and snippets.

View johncolby's full-sized avatar

John Colby johncolby

  • Marin Health
  • San Francisco, CA
View GitHub Profile
@johncolby
johncolby / my-first-style.xml
Created February 4, 2011 23:59
Trying to add 'disambiguate-add-year-suffix' and 'collapse'
<?xml version="1.0" encoding="UTF-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0"
class="in-text">
<info>
<title>My First Style</title>
<id>my-first-style</id>
<updated>2008-10-29T21:01:24+00:00</updated>
</info>
<macro name="author-short">
<names variable="author">
@johncolby
johncolby / trk_compile_data.patch
Created March 29, 2011 17:08
Patches revision 72c87f6 of along-tract-stats to use normal structures instead of datasets
diff --git a/trk_compile_data.m b/trk_compile_data.m
index 0b2ddfe..90d3d15 100644
--- a/trk_compile_data.m
+++ b/trk_compile_data.m
@@ -52,17 +52,12 @@ function [track_means,starting_pts_out] = trk_compile_data(subsDir,subIDs,tract_
if nargin < 7 || isempty(saveASCII), saveASCII = 0; end
if nargin < 6 || isempty(saveTrk), saveTrk = 0; end
if nargin < 5 || isempty(starting_pts_in)
- starting_pts_in = dataset();
-elseif ~iscell(starting_pts_in.Subject) % Reformat to cells if subIDs are all numeric
@johncolby
johncolby / between_grp.R
Created April 18, 2011 20:35
Updates to between group stats code
exptDir = '/Users/jcolby/Documents/LONI/along-tract-stats/along-tract-stats.git/example/between_group'
grpLabs = c('Control', 'FASD')
thresh = 0.05
nPerms = 100
library(nlme) # Mixed-effects models
library(ggplot2) # Plotting tools
library(plyr) # Data manipulation
library(RColorBrewer) # Color tables
@johncolby
johncolby / between_grp.R.diff
Created April 20, 2011 15:58
Modified to always do perms on all tracts/hemispheres
diff --git a/example/between_group/between_grp.R b/example/between_group/between_grp.R
index ffeeaeb..e2d1c08 100644
--- a/example/between_group/between_grp.R
+++ b/example/between_group/between_grp.R
@@ -77,16 +77,7 @@ doPerms <- function(df, demog, nPerms=100){
maxT
}
-# Only correct for multiple comparisons across the tracts with a significant
-# Point:Group interaction F-test. Set the corrected p-values of other tracts to 1
@johncolby
johncolby / trk_plot.m.diff
Created April 26, 2011 17:33
Tweak to trk_plot to highlight different levels
diff --git a/trk_plot.m b/trk_plot.m
index 30e0a4a..26cf093 100644
--- a/trk_plot.m
+++ b/trk_plot.m
@@ -37,6 +37,9 @@ if nargin < 4 || isempty(slices), slices = header.dim/2; end
if ~isstruct(tracks), error('Tracks must be in structure form. Try running TRK_RESTRUC first.'), end
+levels = [0 25 50 75 100];^M
+levels = round(levels*(97-1)/100 + 1);^M
@johncolby
johncolby / colorbar.R
Created May 26, 2011 19:16
An R function to generate color bar legends for neuroimaging plots
# Function to plot color bar
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') {
scale = (length(lut)-1)/(max-min)
dev.new(width=1.75, height=5)
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title)
axis(2, ticks, las=1)
for (i in 1:(length(lut)-1)) {
y = (i-1)/scale + min
rect(0,y,10,y+1/scale, col=lut[i], border=NA)
@johncolby
johncolby / Longitudinal data example.R
Created June 1, 2011 20:16
An example showing how to plot longitudinal data in R using base graphics and ggplot2
library(plyr)
library(ggplot2)
# Simulate data
numSubs = 40
x = runif(numSubs, 0, 30)
x = c(x, x + abs(rnorm(numSubs, 2)))
y = 2 + x - 0.02*x^2 + rnorm(2*numSubs, 0, 1)
@johncolby
johncolby / sub_means_example.R
Created June 22, 2011 17:23
An example showing how to obtain the mean for each subject across multiple observations in a data frame
library(plyr)
data = arrange(data.frame(ID=1:10, FA=runif(50, 0.2, 0.8)), ID)
ddply(data, 'ID', mean) # using plyr library
aggregate(data, list(ID=data$ID), mean) # using base
-1.22920245520088 1.26297072626596 1.83337525320795
1.20936180458861 0.611215979963239 -1.30133702133403
0.522987838117479 -0.451731971345027 -0.58388185591968
0.101340272969554 -0.435726497850704 0.569398963635685
0.426031516466784 0.151080475310323 0.956491447694583
-0.252059713648723 -0.175471660877733 -0.980883888395024
0.662052189667485 1.33212600996006 -1.47268894052709
1.48817331808508 -0.0473711069814109 -0.492789669961388
-0.503441036994115 -0.294926138113795 0.366179342735957
-2.12920560829524 1.02332212331524 -1.58266122316052
@johncolby
johncolby / bias_correct.R
Created October 26, 2011 18:22
An example of how each column in a data frame could be residualized for some covariates
# Download example data from: https://github.com/johncolby/SVM-RFE/zipball/master
setwd('/path/to/SVM-RFE/') # Change this to your setup
load('demo/input.Rdata')
data = input[, 2:3]
input = input[, -(1:3)]
# Function to residualize a vector x for the covariates in data
residualize <- function(x, fun=x~., data) {