Learn R Programming

spdep (version 0.2-9)

mat2listw: Convert a square spatial weights matrix to a weights list object

Description

The function converts a square spatial weights matrix to a weights list object, optionally adding region IDs from the row names of the matrix, as a sequence of numbers 1:nrow(x), or as given as an argument.

Usage

mat2listw(x, row.names = NULL)

Arguments

x
A square non-negative matrix with no NAs representing spatial weights
row.names
row names to use for region IDs

Value

  • A listw object with the following members:
  • style"M", meaning matrix style, underlying style unknown
  • neighboursthe derived neighbours list
  • weightsthe weights for the neighbours derived from the matrix

See Also

nb2listw, nb2mat

Examples

Run this code
data(columbus)
col005 <- dnearneigh(coords, 0, 0.5, attr(col.gal.nb, "region.id"))
summary(col005)
col005.w.mat <- nb2mat(col005, zero.policy=TRUE)
col005.w.b <- mat2listw(col005.w.mat)
summary(col005.w.b$neighbours)
diffnb(col005, col005.w.b$neighbours)

Run the code above in your browser using DataLab