Added tests for learn_partition_modified
This commit is contained in:
parent
b5d99903d2
commit
c630537516
2 changed files with 21 additions and 4 deletions
|
|
@ -8,10 +8,9 @@
|
||||||
#' further combined.
|
#' further combined.
|
||||||
learn_partition_modified <- function(ordered) {
|
learn_partition_modified <- function(ordered) {
|
||||||
part <- learn_simple_partition(ordered, 0.05)
|
part <- learn_simple_partition(ordered, 0.05)
|
||||||
# TODO: find learn_simple_partition
|
|
||||||
nclust <- length(unique(part))
|
nclust <- length(unique(part))
|
||||||
if (nclust == 3) {
|
if (nclust == 3) {
|
||||||
mini_1 <- min(ordered(which(part == 1))) # ASK: what is ordered()?
|
mini_1 <- min(ordered(which(part == 1)))
|
||||||
mini_2 <- min(ordered(which(part == 2)))
|
mini_2 <- min(ordered(which(part == 2)))
|
||||||
mini_3 <- min(ordered(which(part == 3)))
|
mini_3 <- min(ordered(which(part == 3)))
|
||||||
if (mini_1 > 0.9 & mini_2 > 0.9) {
|
if (mini_1 > 0.9 & mini_2 > 0.9) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
context("Admixture analysis")
|
context("Admixture analysis")
|
||||||
|
|
||||||
|
|
||||||
test_that("learn_simple_partition behaves like Matlab", {
|
test_that("learn*partition behaves like Matlab", {
|
||||||
|
# Test data
|
||||||
p1 <- c(0, .5, 1, 1.5)
|
p1 <- c(0, .5, 1, 1.5)
|
||||||
p2 <- c(seq(0, .5, .1), 1, 1, 1, 2)
|
p2 <- c(seq(0, .5, .1), 1, 1, 1, 2)
|
||||||
p3 <- c(.1, .1, .1, .5, .5, .5, 1, 1, 1)
|
p3 <- c(.1, .1, .1, .5, .5, .5, 1, 1, 1)
|
||||||
|
p4 <- c(.7, 1, 1, 1)
|
||||||
|
|
||||||
|
# Testing learn_simple_partition
|
||||||
expect_equal(
|
expect_equal(
|
||||||
object = learn_simple_partition(p1, 2),
|
object = learn_simple_partition(p1, 2),
|
||||||
expected = matrix(c(1, 1, 2, 2))
|
expected = matrix(c(1, 1, 2, 2))
|
||||||
|
|
@ -17,4 +21,18 @@ test_that("learn_simple_partition behaves like Matlab", {
|
||||||
object = learn_simple_partition(p3, .5),
|
object = learn_simple_partition(p3, .5),
|
||||||
expected = matrix(c(1, 1, 1, 2, 2, 2, 3, 3, 3))
|
expected = matrix(c(1, 1, 1, 2, 2, 2, 3, 3, 3))
|
||||||
)
|
)
|
||||||
})
|
expect_equal(
|
||||||
|
object = learn_simple_partition(p4, 5),
|
||||||
|
expected = matrix(c(1, 1, 1, 1))
|
||||||
|
)
|
||||||
|
expect_equal(
|
||||||
|
object = learn_simple_partition(p4, .1),
|
||||||
|
expected = matrix(c(1, 2, 2, 2))
|
||||||
|
)
|
||||||
|
|
||||||
|
# Testing learn_partition_modified
|
||||||
|
expect_equal(
|
||||||
|
object = learn_partition_modified(p4),
|
||||||
|
expected = matrix(c(1, 2, 2, 2))
|
||||||
|
)
|
||||||
|
})
|
||||||
Loading…
Add table
Reference in a new issue