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.

binarize(x, location_measure = "median")

# S3 method for binarize
predict(object, newdata = NULL, inverse = FALSE, ...)

# S3 method for binarize
print(x, ...)

## Arguments

x

A vector to binarize

location_measure

which location measure should be used? can either be "median", "mean", "mode", a number, or a function.

object

an object of class 'binarize'

newdata

a vector of data to be (reverse) transformed

inverse

if TRUE, performs reverse transformation

...

## Value

A list of class binarize with elements

x.t

transformed original data

x

original data

method

location_measure used for original fitting

location

estimated location_measure

n

number of nonmissing observations

norm_stat

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.

## Examples

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