Skip to content

Instantly share code, notes, and snippets.

@GuangchuangYu
Created May 2, 2012 02:28
Show Gist options
  • Save GuangchuangYu/2573113 to your computer and use it in GitHub Desktop.
Save GuangchuangYu/2573113 to your computer and use it in GitHub Desktop.
bootstrap method for enrichment analysis
# http://ygc.name/2012/04/29/bootstrap-for-enrichment-analysis/
goboot <- cmpfun(function(goid,
sampleSize,
nboot=1000) {
ratio <- rep(0, nboot)
allgene <- unique(mappedkeys(org.Hs.egGO))
allgeneInCategory <- unique(get(goid, org.Hs.egGO2ALLEGS))
for (i in 1:nboot) {
gene.sample <- sample(allgene, sampleSize)
k <- sum(gene.sample %in% allgeneInCategory)
ratio[i] <- k/sampleSize
}
return(ratio)
})
ratio <- goboot(goid="GO:0042221", sampleSize=100, nboot=1000)
## suppose a sample (100 genes) which have 35 genes annotated by GO:0042221
## the p value is:
pnorm(35/100, mean=mean(ratio), sd=sd(ratio), lower.tail=F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment