binarize: Binarize

View source: R/binarize.R

binarizeR Documentation

Binarize

Description

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.

Usage

binarize(x, location_measure = "median")

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

## S3 method for class '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

...

additional arguments

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))

predict(binarize_obj, newdata = p, inverse = TRUE)

petersonR/bestNormalize documentation built on March 15, 2024, 9:29 a.m.