The function takes a SpatialPolygonsDataFrame and computes the neighbor penalty matrix that can be used to fit a Markov random field, e.g., using the smooth constructor smooth.construct.mrf.smooth.spec.

## Compute the neighborhood matrix.
neighbormatrix(x, type = c("boundary", "dist", "delaunay", "knear"),
  k = 1, id = NULL, nb = FALSE, names = NULL, ...)

## Plot neighborhood structure.
plotneighbors(x, add = FALSE, ...)

Arguments

x

An object of class "SpatialPolygons" or "SpatialPolygonsDataFrame".

type

Which type of neighborhood structure should be used, "boundary" uses poly2nb, "dist" uses function dnearneigh, "delaunay" uses function tri2nb and option "knear" applies function knn2nb.

k

For type = "knear", specifies number of nearest neighbors.

id

An identifier variable for which the penalty matrix should be computed.

nb

Should only the neighborhood object be returned.

names

Specifies the column where the regions names are provided in the data slot in the "SpatialPolygonsDataFrame"

add

Should the neighborhood structure be added to an existing plot?

Arguments to be passed to function poly2nb, dnearneigh, tri2nb or knn2nb.

See also

Examples

data("LondonFire") ## Compute polygon boundary based ## neighborhood matrix. nm <- neighbormatrix(LondonBoroughs) print(nm)
#> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #> 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 -1 0 0 0 #> 1 0 4 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 #> 2 0 -1 6 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 #> 3 0 0 0 4 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 -1 0 0 #> 4 0 0 0 -1 5 0 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 #> 5 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 #> 6 0 0 0 -1 -1 0 3 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #> 7 0 0 0 0 -1 0 -1 4 -1 -1 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 -1 #> 26 0 3 0 -1 0 -1 0 -1 #> 27 -1 0 4 -1 -1 0 0 -1 #> 28 0 -1 -1 6 -1 -1 0 -1 #> 29 -1 0 -1 -1 6 0 0 0 #> 30 0 -1 0 -1 0 5 -1 0 #> 31 0 0 0 0 0 -1 3 0 #> 32 -1 -1 -1 -1 0 0 0 5 #> attr(,"call") #> spdep::nb2mat(neighbours = adjmat, style = "B", zero.policy = TRUE)
## Plot neighborhood structures. plotneighbors(LondonBoroughs)
plotneighbors(LondonBoroughs, type = "delaunay")
#> #> PLEASE NOTE: The components "delsgs" and "summary" of the #> object returned by deldir() are now DATA FRAMES rather than #> matrices (as they were prior to release 0.0-18). #> See help("deldir"). #> #> PLEASE NOTE: The process that deldir() uses for determining #> duplicated points has changed from that used in version #> 0.0-9 of this package (and previously). See help("deldir"). #>
plotneighbors(LondonBoroughs, type = "dist", d1 = 0, d2 = 0.15)