context("Multivariate")
test_that("The missing values are replaced for continuous data.", {
set.seed(123)
dat <- mtcars
dat$disp[sample.int(nrow(dat), 5)] <- NA
expect_false(anyNA(na_lm(dat, disp ~ mpg + drat)$disp))
expect_false(anyNA(na_glm(dat, disp ~ mpg + drat)$disp))
expect_false(anyNA(na_rpart(dat, disp ~ mpg + drat)$disp))
expect_false(anyNA(na_rf(dat, disp ~ mpg + drat)$disp))
expect_false(anyNA(na_loess(dat, disp ~ mpg + drat)$disp))
})
test_that("The missing values are replaced for categorical data.", {
set.seed(123)
dat <- mtcars
dat$gear[sample.int(nrow(dat), 10)] <- NA
dat$gear <- as.factor(dat$gear)
expect_false(anyNA(na_nb(dat, gear ~ mpg + drat)$disp))
expect_false(anyNA(na_knn(dat, gear ~ mpg + drat)$disp))
expect_false(anyNA(na_rpart(dat, factor(gear) ~ mpg + drat)$disp))
expect_false(anyNA(na_rf(dat, factor(gear) ~ mpg + drat)$disp))
})
test_that("Missing values are replaced or passed if it is not possible for continous data, but data does not change the dimmensions.", {
dat <- mtcars
n <- nrow(dat)
dat$disp[1:10] <- NA
dat$drat[5:15] <- NA
expect_warning(expect_identical(nrow(na_lm(dat, disp ~ mpg + drat)), n))
expect_warning(expect_identical(nrow(na_glm(dat, disp ~ mpg + drat)), n))
expect_warning(expect_identical(nrow(na_rpart(dat, disp ~ mpg + drat)), n))
# expect_warning(expect_identical(nrow(na_rf(dat, disp ~ mpg + drat)), n))
expect_warning(expect_identical(nrow(na_loess(dat, disp ~ mpg + drat)), n))
})
test_that("Missing values are replaced or passed if it is not possible for categorical data, but data does not change the dimmensions.", {
dat <- mtcars
n <- nrow(dat)
dat$gear[1:10] <- NA
dat$drat[5:15] <- NA
# expect_warning(expect_identical(nrow(na_nb(dat, gear ~ mpg + drat)), n))
# expect_warning(expect_identical(nrow(na_knn(dat, gear ~ mpg + drat)), n))
expect_warning(expect_identical(nrow(na_rpart(dat, factor(gear) ~ mpg + drat)), n))
# expect_warning(expect_identical(nrow(na_rf(dat, factor(gear) ~ mpg + drat)), n))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.