tests/testthat/test_Gaussianize.R

context("Testing Gaussianize \n")
YY <- matrix(rt(n = 1000, df = 6), ncol = 2)

test_that("has the right attributes", {
  XX <- Gaussianize(YY, type = "h")
  expect_true(sum(grepl("Gaussianized", names(attributes(XX)))) == 4)
})
out <- Gaussianize(YY, type = "h", return.tau.mat = TRUE, 
                   verbose = FALSE, method = "IGMM") 

test_that("inverse works correctly produces identical input", {      
  expect_identical(ncol(out$tau.mat), ncol(YY))
  YY.hat <- Gaussianize(data = out$input, tau.mat = out$tau.mat, 
                        inverse = TRUE)
  expect_equal(lp_norm(YY.hat - YY, 2), 0)
  
  UU <- Gaussianize(YY, type = "h", tau.mat = out$tau.mat, 
                    verbose = FALSE, return.u = TRUE) 
  YY.hat.from.U <- Gaussianize(input.u = UU, tau.mat = out$tau.mat, 
                               inverse = TRUE)
  expect_equal(lp_norm(YY.hat.from.U - YY, 2), 0)
})

test_that("return.u actually returns zero-mean and unit variance input", {
  UU <- Gaussianize(YY, type = "h", tau.mat = out$tau.mat, 
                    verbose = FALSE, return.u = TRUE) 
  expect_equal(lp_norm(colMeans(UU), 1), 0, tol = 1e-4)
  expect_equal(lp_norm(apply(UU, 2, sd) - 1, 1), 0, tol = 1e-3)
})

Try the LambertW package in your browser

Any scripts or data that you put into this service are public.

LambertW documentation built on Nov. 2, 2023, 6:17 p.m.