This function will perform a binarizing transformation, which could be used as a last resort if the data cannot be adequately normalized. This may be useful when accidentally attempting normalization of a binary vector (which could occur if implementing bestNormalize in an automated fashion).
Note that the transformation is not one-to-one, in contrast to the other functions in this package.
A vector to binarize
which location measure should be used? can either be "median", "mean", "mode", a number, or a function.
an object of class 'binarize'
a vector of data to be (reverse) transformed
if TRUE, performs reverse transformation
additional arguments
A list of class binarize
with elements
transformed original data
original data
location_measure used for original fitting
estimated location_measure
number of nonmissing observations
Pearson's P / degrees of freedom
The predict
function with inverse = FALSE
returns the numeric
value (0 or 1) of the transformation on newdata
(which defaults to
the original data).
If inverse = TRUE
, since the transform is not 1-1, it will create
and return a factor that indicates where the original data was cut.
x <- rgamma(100, 1, 1)
binarize_obj <- binarize(x)
(p <- predict(binarize_obj))
#> [1] 1 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1
#> [38] 1 0 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 0 1
#> [75] 0 0 1 0 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 1
predict(binarize_obj, newdata = p, inverse = TRUE)
#> [1] >= 0.6090158 >= 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158
#> [6] >= 0.6090158 < 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158
#> [11] < 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158 < 0.6090158
#> [16] < 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158 < 0.6090158
#> [21] >= 0.6090158 < 0.6090158 < 0.6090158 < 0.6090158 < 0.6090158
#> [26] < 0.6090158 < 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158
#> [31] < 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158
#> [36] >= 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158 < 0.6090158
#> [41] < 0.6090158 < 0.6090158 < 0.6090158 < 0.6090158 < 0.6090158
#> [46] >= 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158 < 0.6090158
#> [51] >= 0.6090158 >= 0.6090158 >= 0.6090158 < 0.6090158 >= 0.6090158
#> [56] >= 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158 >= 0.6090158
#> [61] < 0.6090158 < 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158
#> [66] >= 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158 >= 0.6090158
#> [71] >= 0.6090158 >= 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158
#> [76] < 0.6090158 >= 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158
#> [81] >= 0.6090158 >= 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158
#> [86] < 0.6090158 < 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158
#> [91] >= 0.6090158 < 0.6090158 >= 0.6090158 < 0.6090158 >= 0.6090158
#> [96] < 0.6090158 < 0.6090158 >= 0.6090158 >= 0.6090158 >= 0.6090158
#> Levels: < 0.6090158 >= 0.6090158