Skip to content

Instantly share code, notes, and snippets.

@sashaphanes
Last active December 16, 2015 20:59
Show Gist options
  • Save sashaphanes/5496661 to your computer and use it in GitHub Desktop.
Save sashaphanes/5496661 to your computer and use it in GitHub Desktop.
#Thsdf
#read macaque data
setwd("/home/rosseraa/work.dir/allen.brain/macaque")
raw.data = read.csv("maoaOut.csv")
#get pairwise combinations
com = combn(colnames(raw.data), 2)
#get p-values
p.values = apply(com, 2, function(x) t.test(raw.data[,x[1]], raw.data[,x[2]])$p.val)
#put into dataframe
data.frame(comparison = paste(com[1,], com[2,], sep = ' vs. '), p.value = p.values)
#store p-values in a column with regions in a separate column:
#p.values = stack(mapply(function(x, y) t.test(x,y)$p.value, maoa, maob))
#order p-values
#ordered = p.values[with(p.values, order(values)),]
#use melt from reshape package and pairwise.t.test
library(reshape)
with(melt(raw.data), pairwise.t.test(value, variable, p.adjust.method = 'none'))
#pair just the first with all other columns
x = sapply(raw.data[,-1], function(x) t.test(x, raw.data[,1])$p.value)
data.frame(variable = names(x), p.value = as.numeric(x))
#sapply(names(raw.data), function(x) sapply( names(raw.data), function(y) t.test(raw.data[[x]],raw.data[[y]])$statistic ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment