diff --git a/DESCRIPTION b/DESCRIPTION index 8326fdb..ce3476e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bestNormalize Type: Package Title: Normalizing Transformation Functions -Version: 1.9.2 +Version: 1.9.3 Date: 2025-11-29 Authors@R: person("Ryan A", "Peterson", email = "ryan-peterson@uiowa.edu", diff --git a/R/yeojohnson.R b/R/yeojohnson.R index e70f1d2..c24756c 100644 --- a/R/yeojohnson.R +++ b/R/yeojohnson.R @@ -126,9 +126,9 @@ print.yeojohnson <- function(x, ...) { # Helper functions that estimates yj lambda parameter #' @importFrom stats var optimize estimate_yeojohnson_lambda <- function(x, lower = -5, upper = 5, eps = .001, ...) { - n <- length(x) ccID <- !is.na(x) x <- x[ccID] + n <- length(x) pos_idx = which(x >= 0) neg_idx = which(x < 0) diff --git a/tests/testthat/test_yeojohnson.R b/tests/testthat/test_yeojohnson.R index e50cb4f..b1c2302 100644 --- a/tests/testthat/test_yeojohnson.R +++ b/tests/testthat/test_yeojohnson.R @@ -33,6 +33,13 @@ test_that('yeojohnson correctly handles missing new data', { expect_equal(as.numeric(NA), predict(b, newdata = c(1, NA), inverse = TRUE)[2]) }) +test_that('yeojohnson lambda is unaffected by appended missing values', { + expect_equal( + yeojohnson(train)$lambda, + yeojohnson(c(train, NA, NA, NA))$lambda + ) +}) + # without standardization yeojohnson_obj <- yeojohnson(train, standardize = FALSE)