This function transform input data via
a *Step Function*.
See stepFunction
for further information.
Arguments
- x
a (named) numerical vector or a matrix features-by-samples
- y
numerical vector of length 3, the values to use for the piecewise function. The first value is used for the left interval, the second value is used when
x == threshold
, and the third value is used for the right interval- thr
numerical value, the threshold to use to divide values in
x
in two intervals- method
character string, indicating the score to be used as threshold. This parameter is only used when
thr = NULL
or not provided- by
character string, indicating whether to compute the threshold by applying
method
to rows or columns ofx
. In the first case, the threshold for the \(i\)-th row is the same across columns. In the second case, the threshold is the same within the same column vector. It is used whenx
is a matrix- na.rm
logical, whether to remove
NA
values before the computation of the threshold
Examples
#set seed for reproducibility
set.seed(seed = 5381L)
#x is a vector
x = sample(x = -10:10, size = 10)
stepFunctionTranformation(x, thr = 0)
#> [1] -1 -1 1 -1 1 -1 -1 1 1 0
#x is a matrix
#Define row/col size
nr = 20
nc = 10
#Create input matrix
x = matrix(
data = stats::runif(n = nr*nc, min = 0, max = 1000),
nrow = nr,
ncol = nc,
dimnames = list(
paste0("g",seq(nr)),
paste0("S",seq(nc))
)
)
#compute
stepFunctionTranformation(x, thr = 500)
#> S1 S2 S3 S4 S5 S6 S7 S8 S9 S10
#> g1 -1 1 -1 -1 -1 -1 1 -1 -1 1
#> g2 1 -1 1 1 -1 1 1 -1 -1 -1
#> g3 1 1 -1 -1 -1 -1 -1 1 1 -1
#> g4 -1 1 -1 1 1 -1 -1 1 -1 -1
#> g5 1 1 1 -1 1 -1 1 -1 1 -1
#> g6 -1 -1 -1 1 -1 1 1 1 -1 1
#> g7 1 1 -1 -1 -1 -1 -1 1 -1 1
#> g8 -1 -1 -1 1 1 -1 -1 1 -1 1
#> g9 -1 1 1 -1 1 1 -1 1 -1 -1
#> g10 -1 -1 1 1 1 -1 1 -1 -1 1
#> g11 -1 1 1 1 -1 1 1 -1 1 1
#> g12 1 1 -1 -1 1 1 1 1 1 -1
#> g13 -1 -1 1 -1 1 1 -1 1 -1 -1
#> g14 -1 -1 -1 -1 1 -1 -1 -1 -1 -1
#> g15 1 1 -1 1 -1 1 1 1 1 1
#> g16 -1 -1 -1 1 1 1 1 1 -1 1
#> g17 1 -1 1 1 1 -1 -1 1 1 1
#> g18 1 1 -1 1 -1 1 -1 1 1 -1
#> g19 1 -1 1 1 1 -1 1 1 -1 1
#> g20 1 1 -1 1 -1 1 -1 1 1 -1
#use median as threshold
stepFunctionTranformation(x, method = 'median')
#> S1 S2 S3 S4 S5 S6 S7 S8 S9 S10
#> g1 -1 1 -1 1 -1 -1 1 1 -1 1
#> g2 1 -1 1 1 -1 1 1 -1 -1 -1
#> g3 1 1 -1 1 -1 -1 -1 1 1 -1
#> g4 -1 1 -1 1 1 -1 -1 1 1 -1
#> g5 1 1 -1 -1 1 -1 1 -1 1 -1
#> g6 -1 -1 -1 1 -1 1 1 1 -1 1
#> g7 1 1 1 -1 -1 -1 -1 1 -1 1
#> g8 1 -1 -1 1 1 -1 -1 1 -1 1
#> g9 -1 1 1 -1 1 1 -1 1 -1 -1
#> g10 -1 -1 1 1 1 -1 1 -1 -1 1
#> g11 -1 -1 1 1 -1 1 1 -1 -1 1
#> g12 1 1 -1 -1 1 1 -1 1 -1 -1
#> g13 -1 -1 1 -1 1 1 -1 1 1 -1
#> g14 -1 -1 1 1 1 -1 1 -1 1 -1
#> g15 1 -1 -1 1 -1 -1 1 1 -1 1
#> g16 -1 -1 -1 1 1 1 -1 1 -1 1
#> g17 1 -1 -1 1 1 -1 -1 1 -1 1
#> g18 1 1 -1 -1 -1 1 -1 1 1 -1
#> g19 1 -1 -1 1 -1 -1 1 1 -1 1
#> g20 1 1 -1 -1 -1 1 -1 1 1 -1
#use median as threshold (by columns)
stepFunctionTranformation(x, method = 'median', by = 'cols')
#> S1 S2 S3 S4 S5 S6 S7 S8 S9 S10
#> g1 -1 1 -1 -1 -1 -1 1 -1 -1 1
#> g2 1 -1 1 1 -1 1 1 -1 -1 -1
#> g3 1 1 -1 -1 -1 -1 -1 1 1 -1
#> g4 -1 -1 -1 1 1 -1 -1 -1 -1 -1
#> g5 1 1 1 -1 1 -1 1 -1 1 -1
#> g6 -1 -1 -1 -1 -1 1 1 -1 -1 1
#> g7 1 1 -1 -1 -1 -1 -1 -1 -1 1
#> g8 -1 -1 -1 1 1 -1 -1 -1 -1 1
#> g9 -1 1 1 -1 1 1 -1 1 1 -1
#> g10 -1 -1 1 1 1 -1 1 -1 -1 1
#> g11 -1 1 1 1 -1 1 1 -1 1 1
#> g12 1 1 -1 -1 1 1 1 1 1 -1
#> g13 -1 -1 1 -1 1 1 -1 1 1 -1
#> g14 -1 -1 -1 -1 1 -1 -1 -1 -1 -1
#> g15 1 1 1 1 -1 1 1 1 1 1
#> g16 -1 -1 1 1 1 1 1 1 -1 1
#> g17 1 -1 1 1 1 -1 -1 1 1 1
#> g18 1 1 -1 -1 -1 1 -1 1 1 -1
#> g19 1 -1 1 1 -1 -1 1 1 -1 1
#> g20 1 1 -1 1 -1 1 -1 1 1 -1