Newer
Older
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
context("s2dv::RatioRMS tests")
##############################################
# dat1
set.seed(1)
exp1_1 <- array(rnorm(120), dim = c(dataset = 1, sdate = 5, ftime = 3))
set.seed(2)
exp1_2 <- array(rnorm(120), dim = c(dataset = 1, sdate = 5, ftime = 3))
set.seed(3)
obs1 <- array(rnorm(80), dim = c(dataset = 1, sdate = 5, ftime = 3))
# dat 2: vector
set.seed(4)
exp2_1 <- rnorm(10)
set.seed(5)
exp2_2 <- rnorm(10)
set.seed(6)
obs2 <- rnorm(10)
##############################################
test_that("1. Input checks", {
# exp1, exp2, obs
expect_error(
RatioRMS(c(), exp1_2, c()),
"Parameter 'exp1', 'exp2', and 'obs' cannot be NULL."
)
expect_error(
RatioRMS(c('b'), c('a'), obs1),
"Parameter 'exp1', 'exp2', and 'obs' must be a numeric array."
)
expect_error(
RatioRMS(exp1_1, array(1:10, dim = c(2, 5)), array(1:4, dim = c(2, 2))),
"Parameter 'exp1', 'exp2', and 'obs' must have dimension names."
)
expect_error(
RatioRMS(exp1_1, exp1_2, array(1:15, dim = c(data = 1, ftime = 3, sdates = 5))),
"Parameter 'exp1', 'exp2', and 'obs' must have same dimension names."
)
expect_error(
RatioRMS(exp1_1, exp1_2, array(1:12, dim = c(dataset = 1, ftime = 3, sdate = 4))),
"Parameter 'exp1', 'exp2', and 'obs' must have the same length of all the dimensions."
)
# time_dim
expect_error(
RatioRMS(exp1_1, exp1_2, obs1, time_dim = c('sdate', 'ftime')),
"Parameter 'time_dim' must be a character string."
)
expect_error(
RatioRMS(exp1_1, exp1_2, obs1, time_dim = 'a'),
"Parameter 'time_dim' is not found in 'exp1', 'exp2', and 'obs' dimensions."
)
# pval
expect_error(
RatioRMS(exp1_1, exp1_2, obs1, pval = 1),
"Parameter 'pval' must be one logical value."
)
expect_error(
RatioRMS(exp1_1, exp1_2, obs1, ncores = 1.5),
"Parameter 'ncores' must be a positive integer."
)
})
##############################################
test_that("2. Output checks: dat1", {
expect_equal(
names(RatioRMS(exp1_1, exp1_2, obs1)),
c('ratiorms', 'p.val')
)
expect_equal(
dim(RatioRMS(exp1_1, exp1_2, obs1)$ratiorms),
c(dataset = 1, ftime = 3)
)
expect_equal(
dim(RatioRMS(exp1_1, exp1_2, obs1)$p.val),
c(dataset = 1, ftime = 3)
)
expect_equal(
as.vector(RatioRMS(exp1_1, exp1_2, obs1)$p.val),
c(0.1811868, 0.4758232, 0.7473213),
tolerance = 0.0001
)
expect_equal(
as.vector(RatioRMS(exp1_1, exp1_2, obs1)$ratiorms),
c(2.0944471, 0.6814573, 1.1873955),
tolerance = 0.0001
)
expect_equal(
names(RatioRMS(exp1_1, exp1_2, obs1, pval = FALSE)),
c('ratiorms')
)
expect_equal(
as.vector(RatioRMS(exp1_1, exp1_2, obs1, pval = FALSE, time_dim = 'ftime')$ratiorms),
c(2.0832571, 0.7292987, 0.6031437, 1.1885930, 0.8542696),
tolerance = 0.0001
)
expect_equal(
as.vector(RatioRMS(exp1_1, exp1_2, obs1, time_dim = 'ftime')$p.val),
c(0.3745346, 0.6944118, 0.5334904, 0.8289285, 0.8437813),
tolerance = 0.0001
)
})
##############################################
test_that("3. Output checks: dat2", {
expect_equal(
names(RatioRMS(exp2_1, exp2_2, obs2)),
c('ratiorms', 'p.val')
)
expect_equal(
RatioRMS(exp2_1, exp2_2, obs2)$p.val,
0.7418331,
tolerance = 0.0001
)
expect_equal(
RatioRMS(exp2_1, exp2_2, obs2)$ratiorms,
0.8931399,
tolerance = 0.0001
)
})