| 1 |
skip_on_cran() |
| 2 |
|
| 3 |
skip_if_not_installed("modeltests") |
| 4 |
library(modeltests) |
| 5 |
|
| 6 |
skip_if_not_installed("irlba") |
| 7 |
|
| 8 |
mat <- scale(as.matrix(USJudgeRatings)) |
| 9 |
s <- svd(mat) |
| 10 |
p <- prcomp(mat) |
| 11 |
i <- irlba::irlba(mat) |
| 12 |
|
| 13 |
test_that("tidy_irlba", { |
| 14 |
check_arguments(tidy_irlba) |
| 15 |
|
| 16 |
tdu <- tidy(i, matrix = "u") |
| 17 |
check_tidy_output(tdu) |
| 18 |
check_dims(tdu, 215, 3) |
| 19 |
|
| 20 |
tdd <- tidy(i, matrix = "d") |
| 21 |
check_tidy_output(tdd) |
| 22 |
check_dims(tdd, 5, 4) |
| 23 |
|
| 24 |
tdv <- tidy(i, matrix = "v") |
| 25 |
check_tidy_output(tdv, strict = FALSE) |
| 26 |
check_dims(tdv, 60, 3) |
| 27 |
}) |
| 28 |
|
| 29 |
test_that("prcomp/svd/irlba consistency", { |
| 30 |
expect_equal(colnames(tidy(i)), colnames(tidy(p))) |
| 31 |
expect_equal(colnames(tidy(i)), colnames(tidy(s))) |
| 32 |
expect_equal(colnames(tidy(s)), colnames(tidy(p))) |
| 33 |
|
| 34 |
expect_equal( |
| 35 |
colnames(tidy(i, matrix = "d")), |
| 36 |
colnames(tidy(p, matrix = "d")) |
| 37 |
) |
| 38 |
expect_equal( |
| 39 |
colnames(tidy(i, matrix = "d")), |
| 40 |
colnames(tidy(s, matrix = "d")) |
| 41 |
) |
| 42 |
expect_equal( |
| 43 |
colnames(tidy(s, matrix = "d")), |
| 44 |
colnames(tidy(p, matrix = "d")) |
| 45 |
) |
| 46 |
|
| 47 |
expect_equal( |
| 48 |
colnames(tidy(i, matrix = "v")), |
| 49 |
colnames(tidy(p, matrix = "v")) |
| 50 |
) |
| 51 |
expect_equal( |
| 52 |
colnames(tidy(i, matrix = "v")), |
| 53 |
colnames(tidy(s, matrix = "v")) |
| 54 |
) |
| 55 |
expect_equal( |
| 56 |
colnames(tidy(s, matrix = "v")), |
| 57 |
colnames(tidy(p, matrix = "v")) |
| 58 |
) |
| 59 |
}) |