Learn R Programming

McSpatial (version 1.1.1)

makew: Calculation of spatial weight matrices

Description

Constructs a spatial weight matrix from a shape file or a matrix of geographic coordinates

Usage

makew(shpfile=NULL,coormat=NULL,method="queen",knum=10,
  ringdist=.25,kern="tcub",window=.10,eigenvalues=FALSE)

Arguments

shpfile
A shape file.
coormat
A matrix of geographic coordinates. The first column should be the longitude and the second latitude, in degrees.
method
Options using shape files to identify first-order contiguity are "queen" and "rook". Options requiring a matrix of geographic coordinates are "knear", "ring", and "kernel". The coordinate matrix can be inputted directly with the coormat optio
knum
The number of nearest neighbors for the knear option. Default: knum = 10
ringdist
The maximum distance for the ring option. Default: ringdist = .25
kern
The kernel function for the kernel option. Options include "rect", "tria", "epan", "bisq", "tcub" and "trwt".
window
Window size for the kernel option. Default: window = .25
eigenvalues
If TRUE, calculates eigenvalues. Default: eigenvalues=FALSE.

Value

  • wmatThe nxn spatial weight matrix. The matrix is row-normalized.
  • eigvarThe eigvenvalues of wmat. Calculated if eigenvalues=TRUE.

Details

If method=rook or method=queen, an nxn contiguity matrix is defined using the spdep package. A queen definition of contiguity means that two tracts are defined as contiguous if they share at least one point. A better definition of rook might be "non-queen": two tracts are defined as contiguous if they share two or more points. The rook and queen options require a shape file. The contiguity matrix is row-normalized to form the weight matrix. If method=knear, the k nearest neighbors are each given a weight of 1/k to form W. The calculations are made using the spdep package. Either a shape file or a matrix of geographic coordinates can be provided to the knear option. If method=ring, each observation within a distance of ringdist from observation i is given equal weight in row i. More distant observations receive a weight of zero. If method=kernel, a kernel weight function is used to define W, with the window size determined by the window option. The kernel weight function is defined by the kern option. The weights are $W_{ij} = K(d_{ij}/h)/h$ for $d_{ij}h$. The matrix is then row-normalized. Eigenvalues are returned if the eigenvalues=T is specified.

See Also

sarml qregspiv

Examples

Run this code
library(maptools)
cmap <- readShapePoly(system.file("maps/CookCensusTracts.shp",
  package="McSpatial"))
cmap <- cmap[cmap$POPULATION>0&cmap$AREA>0,]
cmap <- cmap[cmap$CHICAGO==1&cmap$CAREA!="O'Hare",]
lmat <- coordinates(cmap)
fit <- makew(shpfile=cmap,method="queen")
# fit <- makew(coormat=lmat,method="ring",ringdist=1)

Run the code above in your browser using DataLab