normalizer: Function to normalize distributions

View source: R/normalizer.R

normalizerR Documentation

Function to normalize distributions

Description

The function will apply several transformations, and indicate the transformation that best approximates a normal distribution.

Usage

normalizer(x, plotit = FALSE, return_all = FALSE, ...)

Arguments

x

a numeric vector without absent data.

plotit

Logical If TRUE histograms of each transformation will be ploted.

return_all

Logical. If TRUE it will return all values. Default is FALSE, and only the selected vector is returned.

...

Other parameters passed to the hist function.

Details

The function will apply eigth different transformations to the data:

  1. Square root

  2. Natural logarithm

  3. Cube root

  4. Box Cox

  5. Logarithm in the base 10

  6. Inverse (1 / x)

  7. Inverse Natural logarithm (revert the data, apply a natural logarithm and then invert it back)

  8. Tukey Ladder of Powers (if the vector is between 3 and 5000 long)

The normalizer function uses the standardized D value calculated by a Kolmogorov-Smirnov test using the function stats::ks.test to determine the transformation that most approximate a normal distribution.

Value

The function will return a list with transformed vector (or the raw data) that is closer to a normal distribution and the D value. If return_all equals TRUE, than a list with all transformations is returned.

Author(s)

Bruno Vilela (email: bvilela@wustl.edu)

Examples

# Example 1:
library(letsR)
x <- as.vector(na.exclude(values(temp)))
x <- x / 100
x_t <- normalizer(x, plotit = TRUE)

# Example 2:
library(datasets)
data(mtcars)
mpg_t <- normalizer(mtcars$mpg, plotit = TRUE, return_all = TRUE)

BrunoVilela/normalizer documentation built on March 26, 2022, 9:18 a.m.