Skip to content

Commit

Permalink
Merge pull request jtleek#1 from wevanjohnson/master
Browse files Browse the repository at this point in the history
Added a long overdue error message to ComBat when the experimental design is confounded
  • Loading branch information
jtleek committed Dec 4, 2014
2 parents bdd9758 + 33a090d commit 21cee1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sva
Title: Surrogate Variable Analysis
Version: 3.13.0
Version: 3.13.1
Author: Jeffrey T. Leek <jtleek@gmail.com>, W. Evan Johnson <wej@bu.edu>,
Hilary S. Parker <hiparker@jhsph.edu>, Elana J. Fertig <ejfertig@jhmi.edu>,
Andrew E. Jaffe <ajaffe@jhsph.edu>, John D. Storey <jstorey@princeton.edu>
Expand Down
9 changes: 9 additions & 0 deletions R/ComBat.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ ComBat <- function(dat, batch, mod, numCovs = NULL, par.prior=TRUE,prior.plots=F
n.batches <- sapply(batches, length)
n.array <- sum(n.batches)

# Checking if the design is confounded
if(qr(design)$rank<ncol(design)){
if(ncol(design)<=(n.batch)){stop("your batch variables are redundant or nested! Please remove one or more of the batch variables so they are no longer confounded.")}
if(ncol(design)==(n.batch+1)){stop("your covariate is confounded with batch! Please remove the confounded covariate and rerun ComBat.")}
if(ncol(design)>(n.batch+1)){
if((qr(design[,-c(1:n.batch)])$rank<ncol(design[,-c(1:n.batch)]))){stop('the experimental design of your covariates is confounded! Please remove one (or more) of the covariates so that your design is no longer confounded.')
}else{stop("one (or more) of your covariates is confounded with batch! Please remove the confounded covariate and rerun ComBat.")}}
}

## Check for missing values
NAs = any(is.na(dat))
if(NAs){cat(c('Found',sum(is.na(dat)),'Missing Data Values\n'),sep=' ')}
Expand Down

0 comments on commit 21cee1c

Please sign in to comment.