| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("modeltests") |
| 7 |
library(modeltests) |
| 8 |
|
| 9 |
skip_if_not_installed("mclust") |
| 10 |
suppressPackageStartupMessages(library(mclust)) |
| 11 |
|
| 12 |
skip_if_not_installed("modeldata") |
| 13 |
library(modeldata) |
| 14 |
data(hpc_data) |
| 15 |
|
| 16 |
dat <- hpc_data[, 2:5] |
| 17 |
dat3 <- hpc_data[, 2, drop = FALSE] |
| 18 |
dat4 <- hpc_data[, 2] |
| 19 |
|
| 20 |
fit <- Mclust(dat, G = 7, modelNames = "EII", verbose = FALSE) |
| 21 |
fit2 <- Mclust(dat, G = 1, verbose = FALSE) |
| 22 |
fit3 <- Mclust(dat3, G = 2, verbose = FALSE) |
| 23 |
fit4 <- Mclust(dat4, G = 2, verbose = FALSE) |
| 24 |
|
| 25 |
test_that("mclust tidier arguments", { |
| 26 |
check_arguments(tidy.Mclust) |
| 27 |
check_arguments(glance.Mclust) |
| 28 |
check_arguments(augment.Mclust, strict = FALSE) |
| 29 |
}) |
| 30 |
|
| 31 |
test_that("tidy.Mclust", { |
| 32 |
td <- tidy(fit) |
| 33 |
td2 <- tidy(fit2) |
| 34 |
td3 <- tidy(fit3) |
| 35 |
td4 <- tidy(fit4) |
| 36 |
|
| 37 |
check_tidy_output(td, strict = FALSE) |
| 38 |
check_tidy_output(td2, strict = FALSE) |
| 39 |
check_tidy_output(td3, strict = FALSE) |
| 40 |
check_tidy_output(td4, strict = FALSE) |
| 41 |
|
| 42 |
check_dims(td, 7, 8) |
| 43 |
check_dims(td2, 1, 7) |
| 44 |
check_dims(td3, 2, 5) |
| 45 |
check_dims(td4, 2, 5) |
| 46 |
}) |
| 47 |
|
| 48 |
test_that("glance.Mclust", { |
| 49 |
gl <- glance(fit) |
| 50 |
gl2 <- glance(fit2) |
| 51 |
gl3 <- glance(fit3) |
| 52 |
gl4 <- glance(fit4) |
| 53 |
|
| 54 |
check_glance_outputs(gl, gl2, gl3, gl4) |
| 55 |
}) |
| 56 |
|
| 57 |
test_that("augment.Mclust", { |
| 58 |
suppressWarnings( |
| 59 |
check_augment_function( |
| 60 |
aug = augment.Mclust, |
| 61 |
model = fit, |
| 62 |
data = dat, |
| 63 |
newdata = dat |
| 64 |
) |
| 65 |
) |
| 66 |
|
| 67 |
suppressWarnings( |
| 68 |
check_augment_function( |
| 69 |
aug = augment.Mclust, |
| 70 |
model = fit2, |
| 71 |
data = dat, |
| 72 |
newdata = dat |
| 73 |
) |
| 74 |
) |
| 75 |
|
| 76 |
check_augment_function( |
| 77 |
aug = augment.Mclust, |
| 78 |
model = fit3, |
| 79 |
data = dat3, |
| 80 |
newdata = dat3, |
| 81 |
strict = FALSE |
| 82 |
) |
| 83 |
|
| 84 |
fit_on_vector <- Mclust(1:10) |
| 85 |
|
| 86 |
# fix later: tibble warnings since data matrix doesn't have column |
| 87 |
# names |
| 88 |
# expect_silent( |
| 89 |
# augment(fit_on_vector) |
| 90 |
# ) |
| 91 |
|
| 92 |
expect_snapshot(error = TRUE, augment(fit, 1:10)) |
| 93 |
}) |