[72a7c3]: / tests / testthat / test_combinePvalues.R

Download this file

56 lines (39 with data), 1.7 kB

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
context("P-value aggregation")
test_that("method selection works", {
df <- cbind(runif(5), runif(5), runif(5))
colnames(df) <- c("trans.pval", "prot.pval", "meta.pval")
method <- "random"
expect_error(combinePvalues(df, method = method))
})
test_that("Fisher method works", {
df <- cbind(runif(5), runif(5), runif(5))
colnames(df) <- c("trans.pval", "prot.pval", "meta.pval")
method <- "Fisher"
expect_is(combinePvalues(df, method = method), "numeric")
expect_equal(length(combinePvalues(df, method = method)), nrow(df))
})
test_that("Edgington method works", {
df <- cbind(runif(5), runif(5), runif(5))
colnames(df) <- c("trans.pval", "prot.pval", "meta.pval")
method <- "Edgington"
expect_is(combinePvalues(df, method = method), "numeric")
expect_equal(length(combinePvalues(df, method = method)), nrow(df))
})
test_that("Stouffer method works", {
df <- cbind(runif(5), runif(5), runif(5))
colnames(df) <- c("trans.pval", "prot.pval", "meta.pval")
method <- "Stouffer"
expect_is(combinePvalues(df, method = method), "numeric")
expect_equal(length(combinePvalues(df, method = method)), nrow(df))
})
test_that("weighted Stouffer method works", {
df <- cbind(runif(5), runif(5), runif(5))
colnames(df) <- c("trans.pval", "prot.pval", "meta.pval")
weights <- sample(1:100, 3, replace = TRUE)
expect_is(combinePvalues(df, weights = weights), "numeric")
expect_equal(length(combinePvalues(df)), nrow(df))
weights <- sample(1:100, 2, replace = TRUE)
expect_error(combinePvalues(df, weights = weights))
weights <- c(1, 1, 1)
expect_equal(combinePvalues(df), combinePvalues(df, weights = weights))
})