Skip to content

Instantly share code, notes, and snippets.

@chr1swallace
Created October 29, 2013 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr1swallace/7213787 to your computer and use it in GitHub Desktop.
Save chr1swallace/7213787 to your computer and use it in GitHub Desktop.
conditional testing of SNPs - reports number and which SNPs are "significant" in sequential conditional testing
library(snpStats)
best <- cond.best(X,Y, family=family)
while(length(newbest <- cond.best(X, Y, best, family=family)))
best <- c(best,newbest)
cond.best <- function(X,Y,best=NULL,p.thr=1e-6, ...) {
if(is.null(best)) {
cond <- snp.rhs.tests(Y ~ 1, snp.data=X, data=data.frame(Y=Y,
row.names=rownames(X)), ...)
p.thr <- 1
} else {
cond <- snp.rhs.tests(as.formula(paste("Y ~", paste(best, collapse="+"))),
snp.data=X,
data=cbind(data.frame(Y=Y,row.names=rownames(X)),as(X[,best],"numeric")),
control=glm.test.control(R2Max=1),
...)
}
p <- p.value(cond)
pmin <- min(p, na.rm=TRUE)
if(pmin<p.thr) {
newbest <- colnames(X)[ which.min(p) ]
message(newbest," ",format.pval(pmin))
return(newbest)
}
return(NULL)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment