mixOmicsTeam / mixOmics

Development repository for the Bioconductor package 'mixOmics '
http://mixomics.org/
150 stars 51 forks source link

`predict()` produces all `NaN`s for a given block #266

Closed Max-Bladen closed 1 year ago

Max-Bladen commented 1 year ago

šŸž Describe the bug:

When applying auroc() to block.splsda objects, if any of the predictors variance equal to 0 and a center not equal to 0, following error is raised:

Error in cut.default(cases, thresholds) : invalid number of intervals.

If the zero-variance feature(s)'s center is 0, NO error is raised. If it not 0, then error raised.


šŸ” reprex results from reproducible example including sessioninfo():

X1 <- data.frame(matrix(rnorm(100000, 5, 5), nrow = 100))
X2 <- data.frame(matrix(rnorm(150000, 5, 5), nrow = 100))
Y <- c(rep("A", 50), rep("B", 50))

X <- list(block1=X1, block2=X2)

list.keepX <- list(block1=c(15, 15), block2=c(30,30))

## NO ERROR RAISED
X$block1[,1] <- rep(0, 100)
model = block.splsda(X = X, Y = Y, ncomp = 2,
                          keepX = list.keepX, design = "full")
#> Warning in cor(A[[k]], variates.A[[k]]): the standard deviation is zero
auc.splsda = auroc(model)

    #> $block1
    #> $block1$comp1
    #>           AUC   p-value
    #> A vs B 0.8364 6.723e-09
    #> 
    #> $block1$comp2
    #>           AUC   p-value
    #> A vs B 0.9104 1.515e-12
    #> 
    #> 
    #> $block2
    #> $block2$comp1
    #>           AUC   p-value
    #> A vs B 0.9404 3.197e-14
    #> 
    #> $block2$comp2
    #>           AUC p-value
    #> A vs B 0.9812       0

## ERROR RAISED
X$block1[,1] <- rep(1, 100)
model = block.splsda(X = X, Y = Y, ncomp = 2,
                     keepX = list.keepX, design = "full")
    #> Warning in cor(A[[k]], variates.A[[k]]): the standard deviation is zero
auc.splsda = auroc(model)
    #> Error in cut.default(cases, thresholds): invalid number of intervals

Created on 2022-11-15 with reprex v2.0.2

Note: when first feature of first block are all 0s, auroc() functions as normal. If feature is all 1s, auroc() fails.


šŸ¤” Expected behavior:

Features with zero variance should not be allowed - this will be addressed in its own branch and pull request.

A fail safe should be implemented as temporary fix


šŸ’” Possible solution:

Requires exploration