@@ -5,33 +5,6 @@ library(sf)
5
5
sfe <- McKellarMuscleData(" small" )
6
6
g <- findVisiumGraph(sfe )
7
7
8
- test_that(" listw2sparse gives correct results" , {
9
- mat <- listw2sparse(g )
10
- expect_s4_class(mat , " dgCMatrix" )
11
- expect_equal(nrow(mat ), ncol(sfe ))
12
- expect_equal(ncol(mat ), ncol(sfe ))
13
- expect_equal(Matrix :: rowSums(mat > 0 ), card(g $ neighbours ), ignore_attr = TRUE )
14
- m2 <- listw2mat(g )
15
- expect_equal(as.matrix(mat ), m2 , ignore_attr = TRUE )
16
- expect_equal(rownames(mat ), rownames(m2 ))
17
- expect_equal(rownames(mat ), colnames(mat ))
18
- })
19
-
20
- # Add a singleton to g
21
- g_single <- g
22
- g_single $ neighbours <- c(g_single $ neighbours , 0L )
23
- class(g_single $ neighbours ) <- " nb"
24
- attr(g_single , " region.id" ) <- c(attr(g_single , " region.id" ), " foo" )
25
- g_single $ weights <- c(g_single $ weights , list (NULL ))
26
-
27
- test_that(" Deal with singletons in listw2sparse" , {
28
- mat <- listw2mat(g_single )
29
- n <- length(g_single $ neighbours )
30
- expect_equal(nrow(mat ), n )
31
- expect_equal(ncol(mat ), n )
32
- expect_equal(Matrix :: rowSums(mat )[n ], 0 , ignore_attr = TRUE )
33
- })
34
-
35
8
# Copied and pasted code from adespatial, which got kicked out of CRAN
36
9
bicenter.wt <- function (X , row.wt = rep(1 , nrow(X )), col.wt = rep(1 , ncol(X ))) {
37
10
X <- as.matrix(X )
@@ -72,25 +45,3 @@ test_that("moranBounds gives correct results", {
72
45
g3 <- findVisiumGraph(sfe , style = " S" )
73
46
expect_equal(moranBounds(g3 ), moran.bounds(g3 ))
74
47
})
75
-
76
- nb1 <- grid2nb(d = c(5 ,5 ))
77
- nb2 <- grid2nb(d = c(3 ,3 ))
78
- attr(nb1 , " region.id" ) <- LETTERS [1 : 25 ]
79
- attr(nb2 , " region.id" ) <- letters [1 : 9 ]
80
- l1 <- nb2listw(nb1 )
81
- l2 <- nb2listw(nb2 )
82
- listws <- list (l1 , l2 )
83
- names_expect <- c(LETTERS [1 : 25 ], letters [1 : 9 ])
84
- test_that(" Convert list of listws to one adjacency matrix" , {
85
- mat <- multi_listw2sparse(listws )
86
- expect_s4_class(mat , " dgCMatrix" )
87
- l_expect <- length(nb1 ) + length(nb2 )
88
- expect_equal(nrow(mat ), l_expect )
89
- expect_equal(ncol(mat ), l_expect )
90
- expect_equal(rownames(mat ), names_expect )
91
- expect_equal(colnames(mat ), names_expect )
92
- expect_equal(as.matrix(mat [1 : 25 ,1 : 25 ]), listw2mat(l1 ), ignore_attr = TRUE )
93
- expect_equal(as.matrix(mat [26 : 34 ,26 : 34 ]), listw2mat(l2 ), ignore_attr = TRUE )
94
- expect_equal(sum(mat [26 : 34 , 1 : 25 ]), 0 )
95
- expect_equal(sum(mat [1 : 25 , 26 : 34 ]), 0 )
96
- })
0 commit comments