@@ -8,6 +8,7 @@ cors.length <- pp*(pp+1)/2
88cors.test <- runif(cors.length )
99betas.test <- matrix (runif(pp * pp ), ncol = pp )
1010lambda.test <- pi
11+ weights.test <- rep(1 , pp * pp )
1112gamma.test <- 2.0
1213eps.test <- 0.1
1314maxIters.test <- 1000L
@@ -29,128 +30,142 @@ test_that("ccdr_singleR runs as expected", {
2930 expect_error(ccdr_singleR(cors = cors.test ))
3031
3132 # ## No error
32- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
33+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
3334
3435 # ## No error
35- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj , indexj = indexj , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
36+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj , indexj = indexj , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
3637
3738})
3839
3940test_that(" Check input: cors" , {
4041
4142 # ## Throw error if cors has length != pp*(pp+1)/2
42- expect_error(ccdr_singleR(cors = cors.test [- 1 ], pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
43+ expect_error(ccdr_singleR(cors = cors.test [- 1 ], pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
4344})
4445
4546test_that(" Check input: pp" , {
4647
4748 # ## pp is not an integer
48- expect_error(ccdr_singleR(cors = cors.test , pp = pi , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
49+ expect_error(ccdr_singleR(cors = cors.test , pp = pi , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
4950
5051 # ## pp is not > 0
51- expect_error(ccdr_singleR(cors = cors.test , pp = - 1L , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
52+ expect_error(ccdr_singleR(cors = cors.test , pp = - 1L , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
5253})
5354
5455test_that(" Check input: nn" , {
5556
5657 # ## nn is not an integer
57- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = pi , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
58+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = pi , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
5859
5960 # ## nn is not > 0
60- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = - 1L , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
61+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = - 1L , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
6162})
6263
6364test_that(" Check input: indexj" , {
6465 # ## indexj is defined to be a vector containing the start position of the correlation matrix for node j in 'cors'
6566
6667 # ## indexj is not a vector
67- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = matrix (0L , nrow = 1 , ncol = pp + 1 ), betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
68+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = matrix (0L , nrow = 1 , ncol = pp + 1 ), betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
6869
6970 # ## indexj is of wrong size
70- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = rep(0L , pp + 2 ), betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
71+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = rep(0L , pp + 2 ), betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
7172
7273 # ## indexj has non-integer
7374 indexj1 <- indexj
7475
7576 indexj1 [1 ] <- pi
76- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
77+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
7778
7879 indexj1 [1 ] <- NA
79- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
80+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
8081
8182 # ## indexj out of bound
8283 indexj1 [1 ] <- 0
83- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
84+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
8485
8586 indexj1 [1 ] <- pp + 2
86- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
87+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , indexj = indexj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
8788})
8889
8990test_that(" Check input: nj" , {
9091 # ## nj is defined to be a vector containing the number of times each node is free of intervention (to replace nn)
9192
9293 # ## nj is not a vector
93- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = matrix (nn , nrow = 1 , ncol = pp ), betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
94+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = matrix (nn , nrow = 1 , ncol = pp ), betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
9495
9596 # ## nj is of wrong size
96- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = as.integer(rep(nn , pp + 1 )), betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
97+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = as.integer(rep(nn , pp + 1 )), betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
9798
9899 # ## nj has non-integer
99100 nj1 <- nj
100101
101102 nj1 [1 ] <- pi
102- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
103+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
103104
104105 nj1 [1 ] <- NA
105- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
106+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
106107
107108 # ## nj out of bound
108109 nj1 <- rep(- 1L , pp )
109- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
110+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
110111
111112 nj1 <- as.integer(rep(nn + 1 , pp ))
112- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
113+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , nj = nj1 , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
113114})
114115
115116test_that(" Check input: betas" , {
116117
117118 # ## betas is not a matrix or SparseBlockMatrixR
118- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = as.numeric(betas.test ), lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
119+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = as.numeric(betas.test ), lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
119120
120121 # ## If betas = zeroes and lambda = sqrt(n), then output should be zero
121- final <- ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = matrix (0 , nrow = pp , ncol = pp ), lambda = sqrt(nn ), gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test )
122+ final <- ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = matrix (0 , nrow = pp , ncol = pp ), lambda = sqrt(nn ), weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test )
122123 expect_true(is.zero(final $ sbm ))
123124})
124125
125126test_that(" Check input: lambda" , {
126127
127128 # ## lambda is negative
128- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = - lambda.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
129+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = - lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
130+ })
131+
132+ test_that(" Check input: weights" , {
133+
134+ # ## weight > 1
135+ weights.test <- rep(1 , pp * pp )
136+ weights.test [1 ] <- 2
137+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = - 5 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), " weights out of bounds" )
138+
139+ # ## weight < 1
140+ weights.test <- rep(1 , pp * pp )
141+ weights.test [1 ] <- - 2
142+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = - 1 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), " weights out of bounds" )
143+
129144})
130145
131146test_that(" Check input: gamma" , {
132147
133148 # ## gamma is negative
134- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = - 5 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
149+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = - 5 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ))
135150
136151 # ## gamma = -1 is OK
137- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = - 1 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
152+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = - 1 , eps = eps.test , maxIters = maxIters.test , alpha = alpha.test ), NA )
138153
139154})
140155
141156test_that(" Check input: eps" , {
142157
143158 # ## eps is negative
144- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = - 5 , maxIters = maxIters.test , alpha = alpha.test ))
159+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = - 5 , maxIters = maxIters.test , alpha = alpha.test ))
145160
146161 # ## Output warning if user sets eps = 0
147- expect_warning(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = 0 , maxIters = maxIters.test , alpha = alpha.test ))
162+ expect_warning(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = 0 , maxIters = maxIters.test , alpha = alpha.test ))
148163})
149164
150165test_that(" Check input: maxIters" , {
151166
152167 # ## maxIters is negative
153- expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , gamma = gamma.test , eps = eps.test , maxIters = - 5 , alpha = alpha.test ))
168+ expect_error(ccdr_singleR(cors = cors.test , pp = pp , nn = nn , betas = betas.test , lambda = lambda.test , weights = weights.test , gamma = gamma.test , eps = eps.test , maxIters = - 5 , alpha = alpha.test ))
154169})
155170
156171test_that(" Check input: alpha" , {
0 commit comments