Skip to contents

Given a matrix of \(k\) nearest neighbors and an adjacency matrix for the locations involved, produces the set of flexibly shaped zones as a list of integer vectors. The locations in these zones are all connected, in the sense that any location in the zone can be reached from another by traveling through adjacent locations within the zone.

Usage

flexible_zones(k_nearest, adjacency_matrix)

Arguments

k_nearest

An integer matrix of the \(k\) nearest neighbors for each location. Each row corresponds to a location, with the first element of each row being the location itself. Locations should be encoded as integers.

adjacency_matrix

A boolean matrix, with element \((i,j)\) set to TRUE if location \(j\) is adjacent to location \(i\).

Value

A list of integer vectors.

References

Tango, T. & Takahashi, K. (2005), A flexibly shaped spatial scan statistic for detecting clusters, International Journal of Health Geographics 4(1).

Examples

A <- matrix(c(0,1,0,0,0,0,
              1,0,1,0,0,0,
              0,1,0,0,0,0,
              0,0,0,0,1,0,
              0,0,0,1,0,0,
              0,0,0,0,0,0), 
              nrow = 6, byrow = TRUE) == 1
nn <- matrix(as.integer(c(1,2,3,4,5,6,
                          2,1,3,4,5,6,
                          3,2,1,4,5,6,
                          4,5,1,6,3,2,
                          5,4,6,1,3,2,
                          6,5,4,1,3,2)),
                          nrow = 6, byrow = TRUE)
flexible_zones(nn, A)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 1 2
#> 
#> [[3]]
#> [1] 1 2 3
#> 
#> [[4]]
#> [1] 2
#> 
#> [[5]]
#> [1] 2 3
#> 
#> [[6]]
#> [1] 3
#> 
#> [[7]]
#> [1] 4
#> 
#> [[8]]
#> [1] 4 5
#> 
#> [[9]]
#> [1] 5
#> 
#> [[10]]
#> [1] 6
#>