View source: R/power_transform.R
power_transform | R Documentation |
Applies a power transformation to numeric input data using the car::powerTransform
function. Supported transformation families include Box-Cox ("bcPower"
), Box-Cox with negative values ("bcnPower"
), and Yeo-Johnson ("yjPower"
). The function estimates either optimal or rounded lambda values for each numeric variable and transforms the data accordingly.
power_transform(
data,
family = c("bcPower", "bcnPower", "yjPower"),
type = c("optimal", "rounded")
)
data |
A numeric vector, matrix, or data frame. Only numeric columns will be transformed. Non-numeric columns are dropped with a warning. |
family |
A character string specifying the transformation family. Must be one of |
type |
A character string specifying whether to use the estimated optimal lambda values ( |
Rows with missing values are removed prior to estimating lambda parameters. A warning is issued if any non-numeric columns are dropped or if any rows are excluded due to missingness. The same estimated lambda values are then applied to the original data (excluding dropped rows or columns).
A list containing two elements. The first is a data frame of transformed numeric columns. The second is a named numeric vector of the lambda values used for the transformation.
if (requireNamespace("car", quietly = TRUE)) {
x <- rnorm(100, mean = 10, sd = 2)
y <- rexp(100, rate = 0.2)
df <- data.frame(x = x, y = y)
result <- power_transform(df, family = "bcPower", type = "optimal")
head(result$data)
result$lambda
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.