tests/testthat/test-impute.R

# ===================================================================== #
#  An R package by Certe:                                               #
#  https://github.com/certe-medical-epidemiology                        #
#                                                                       #
#  Licensed as GPL-v2.0.                                                #
#                                                                       #
#  Developed at non-profit organisation Certe Medical Diagnostics &     #
#  Advice, department of Medical Epidemiology.                          #
#                                                                       #
#  This R package is free software; you can freely use and distribute   #
#  it for both personal and commercial purposes under the terms of the  #
#  GNU General Public License version 2.0 (GNU GPL-2), as published by  #
#  the Free Software Foundation.                                        #
#                                                                       #
#  We created this package for both routine data analysis and academic  #
#  research and it was publicly released in the hope that it will be    #
#  useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY.              #
# ===================================================================== #

test_that("imputation works", {
  iris2 <- dplyr::as_tibble(iris)
  iris2[1, 2] <- NA
  iris2[3, 4] <- NA
  iris2[4, 5] <- NA
  
  imp <- impute(iris2)
  expect_false(any(is.na(imp)))
  expect_false(any(is.na(impute(iris2, algorithm = "single-point"))))
  expect_true(any(is.na(impute(iris2, vars = where(is.double), algorithm = "single-point"))))
  
  expect_true(any(is_imputed(imp)))
  expect_s3_class(get_mice(imp), "mids")
  
})
certe-medical-epidemiology/certestats documentation built on Nov. 9, 2024, 8:15 p.m.