gastonstat / AssotesteR

R package AssotesteR
13 stars 4 forks source link

bug in my_cmc_method #2

Open anilpatwardhan opened 11 years ago

anilpatwardhan commented 11 years ago

Hi, There is a small bug in my_cmc_method which will result in returning NA values when calculating the CMC statistic when a single supervariant is being evaluated. Need to coerce Xx and Yy into matrices before running colMeans and sweep functions. Otherwise for a single vector (single collapsed supervariant) they will produce an error and the function will return NA. See below:

my_cmc_method <- function(casecon, X.new) {

Internal function for CMAT method

## number of individuals N, cases nA, controls nU
N = nrow(X.new)
nA = sum(casecon)
nU = N - nA
## matrix of genotypes in cases
Xx = X.new[casecon==1,]  
## matrix of genotypes in controls  
Yy = X.new[casecon==0,] 
#BUGFIX Vectors need to be coerced into matrix for colMeans and sweep to work
Xx=as.matrix(Xx)
Yy=as.matrix(Yy)
## get means
Xx.mean = colMeans(Xx, na.rm=TRUE)
Yy.mean = colMeans(Yy, na.rm=TRUE)
## center matrices Xx and Yy
Dx = sweep(Xx, 2, Xx.mean)
Dy = sweep(Yy, 2, Yy.mean)

.....