-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest_xval.R
31 lines (26 loc) · 1.05 KB
/
test_xval.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
context("xvalDapc test")
xvalnames <- c("Cross-Validation Results",
"Median and Confidence Interval for Random Chance",
"Mean Successful Assignment by Number of PCs of PCA",
"Number of PCs Achieving Highest Mean Success",
"Root Mean Squared Error by Number of PCs of PCA",
"Number of PCs Achieving Lowest MSE",
"DAPC")
data(sim2pop)
test_that("xvalDapc returns expected results", {
skip_on_cran()
xval <- xvalDapc(sim2pop@tab, pop(sim2pop), n.pca.max=100, n.rep=3, xval.plot = FALSE)
cvr <- xval[["Cross-Validation Results"]]
msa <- xval[["Mean Successful Assignment by Number of PCs of PCA"]]
expect_that(xval, is_a("list"))
expect_equivalent(names(xval), xvalnames)
expect_that(xval$DAPC, is_a("dapc"))
expect_that(nrow(cvr), equals(3 * length(msa)))
})
test_that("xvalDapc throws a warning with populations of 1 sample", {
skip_on_cran()
dat_pop <- as.character(pop(sim2pop))
dat_pop[1] <- "Pop C"
pop(sim2pop) <- dat_pop
expect_warning(xvalDapc(sim2pop@tab, pop(sim2pop), n.pca.max=100, n.rep=3, xval.plot = FALSE))
})