transformVar: transform a numeric vector

View source: R/Module_transformDF.R

transformVarR Documentation

transform a numeric vector

Description

transform a numeric vector

Usage

transformVar(x, type, logfirst = FALSE, warning.print = FALSE)

Arguments

x

is a numeric vector

type

"none", "standardize" (rescale to 0-1), or "normalize" (rescale to mean=0, sd =1)

logfirst

if TRUE, do a log-transform BEFORE applying either standardize or normalize

warning.print

if TRUE print a warning if Perry et al 2021 0 fix is triggered

Details

Typically called from within transformDF. If any zeroes in the data, then the log-transform causes problems. Using the strategy from Perry et al 2021 (https://journals.plos.org/plosone/article/comments?id=10.1371/journal.pone.0245941) which replaces 0 with a random value greater than 0 and less than one-half of the lowest non-zero value in the data for that variable. If the data has negative values, a constant equal to min(x)* 1.01 is added to all values (i.e. smallest value is a bit larger than 0).

Value

A transformed vector

Examples

transformVar(X = mtcars$mpg, type = "standardize", logfirst = FALSE)
transformVarX = mtcars$mpg, type = "normalize", logfirst = TRUE)

SalmonForecastR/ForecastR-Package documentation built on March 10, 2023, 2:18 p.m.