spwt
Spatial weights
spwt( x = NULL, y = NULL, type = "knn", k = 4, d = NULL, nb = NULL, idw = 0, style = "row", metric = "euclid", lonlat = FALSE)Builds the neighbours and weights the autocorrelation statistics
(gearc(), gorg(), lmorn(), locgi()) use: the k nearest
neighbours of each point (type = "knn", ties broken by the lower row
number), the points within distance d ("band", the distance itself
included), or a contiguity list nb ("contig", one element per unit
giving its neighbours’ numbers, as spdep’s poly2nb() returns). Weights
are 1, or the inverse distance to the power idw; style = "row"
divides each unit’s weights by their sum (a unit without neighbours keeps
none), "raw" leaves them.
Parameters
Section titled “Parameters”x, yThe points:
xandynumeric vectors of equal length; orxa matrix or data frame with columns namedxandy(orXandY, assf::st_coordinates()names them, orlonandlatwithlonlat = TRUE) andyNULL; orxan sf or sfc object of POINT geometries, whose coordinate reference system must agree withlonlat. An unnamed two-column matrix is read asxtheny; other columns are never taken by position. Vectors given separately (x,y, andwortwhere a function takes them) are matched by name when every one is named and no name repeats, as elsewhere in the package; otherwise by position. No missing or infinite values.type"knn","band"or"contig".kFor
"knn": the number of neighbours, from 1 to the number of points less 1.dFor
"band": the distance, positive, in the unit of the coordinates (metres whenlonlat = TRUE).nbFor
"contig": a list with one element per unit, each a vector of neighbour numbers (from 1;0alone for none).idwThe power of the inverse distance: 0 (binary weights) or more; above 0 it needs the points.
style"row"or"raw".metric"euclid"or"manhattan"(|dx| + |dy|).lonlatFALSE(the default) whenxandyare planar coordinates in one length unit;TRUEwhen they are longitude and latitude in degrees, which are then projected to metres byeqproj()about their own centre, and centres are returned in degrees. It is never guessed.
Returns
Section titled “Returns”A list: n (the number of units), and one element per
neighbour pair, in order of unit then neighbour: i, j (integer unit
numbers), d (their distance, NA for contiguity without points) and
w (the weight). x may be NULL for contiguity with binary weights.
References
Section titled “References”Cliff, A. D. and Ord, J. K. (1981). Spatial Processes: Models and Applications. Pion, London.
Examples
Section titled “Examples”set.seed(1)p <- cbind(x = runif(20), y = runif(20))w <- spwt(p, k = 3)str(w)spwt(nb = list(2, c(1, 3), 2), type = "contig")$wGenerated from the R help page: spwt in the R reference.