Skip to content

Commit 4a57625

Browse files
committed
[fix] the score function now does work even if the standard deviation is 0
1 parent 82052b5 commit 4a57625

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

R/sivs.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ sivs <- function(x, y, test.ratio = 1/3, method = "glmnet",
192192
func.zscore <- function(x){
193193
## Description:
194194
## A function to perform zscore standardization on a vector of numbers
195+
## even when the standard deviation is zero! The base::scale() would
196+
## return NaN if sd(x)==0.
195197
##
196198
## Arguments:
197199
## x: A numeric vector
198-
as.numeric((x - mean(x = x, na.rm = TRUE)) / sd(x = x, na.rm = TRUE))
200+
as.numeric((x - mean(x = x, na.rm = TRUE)) / (sd(x = x, na.rm = TRUE) ^ as.logical(sd(x))))
199201
}
200202

201203

@@ -495,7 +497,7 @@ sivs <- function(x, y, test.ratio = 1/3, method = "glmnet",
495497

496498
func.cat(" [OK]")
497499
}
498-
500+
499501
#-------[ debug.mode ]-------#
500502
{
501503
func.cat("\t| debug.mode", new.line = FALSE)

0 commit comments

Comments
 (0)