A spatial weights matrix turns a qualitative statement such as
“these locations are neighbors”
into a numerical object that can be used in spatial statistics and spatial regression.
For $n$ observations, define
$$ W=[w_{ij}], $$
where $w_{ij}$ describes the connection from location $i$ to location $j$.
Usually,
$$ w_{ii}=0, $$
so a location is not treated as its own neighbor.
The spatial weights matrix is not merely bookkeeping. It defines what the analysis means by spatial proximity or connection.
Changing $W$ can change:
After this chapter, you should be able to:
Suppose there are four spatial units:
$$ A,\ B,\ C,\ D. $$
A binary weights matrix might be
$$ W= \begin{bmatrix} 0&1&1&0\\ 1&0&1&0\\ 1&1&0&1\\ 0&0&1&0 \end{bmatrix}. $$
Read the first row as:
So
$$ w_{AB}=1, \qquad w_{AC}=1. $$
The matrix is the numerical representation of the neighborhood graph.

The diagonal entry
$$ w_{ii} $$
describes the relationship from a location to itself.
For many spatial statistics, the diagonal is set to zero:
$$ w_{ii}=0. $$
Why?
Because the goal is usually to summarize information from other locations.
For example, a spatial lag should describe the neighborhood around location $i$, not reproduce $x_i$ itself.
There are specialized settings in which self-weights are meaningful, but a zero diagonal is the standard default for the methods in this chapter.
For polygon data, neighborhood is often defined by shared boundaries.
Let
$$ A_i $$
and
$$ A_j $$
be two polygons.
A binary contiguity weight is
$$ w_{ij} = \begin{cases} 1,& A_i\text{ and }A_j\text{ are neighbors},\\ 0,& \text{otherwise}. \end{cases} $$
Two common definitions are rook and queen contiguity.
Rook contiguity requires two polygons to share an edge of positive length.
Imagine four square cells:
$$ \begin{matrix} A & B\\ C & D \end{matrix} $$
Under rook contiguity:
The diagonal contact between A and D does not count.
The binary rook matrix is
$$ W_R= \begin{bmatrix} 0&1&1&0\\ 1&0&0&1\\ 1&0&0&1\\ 0&1&1&0 \end{bmatrix}. $$
Queen contiguity counts either:
For the same $2\times2$ grid, every cell touches all three other cells either by an edge or a corner.
Therefore
$$ W_Q= \begin{bmatrix} 0&1&1&1\\ 1&0&1&1\\ 1&1&0&1\\ 1&1&1&0 \end{bmatrix}. $$

Rook and queen contiguity define different neighborhoods.
If a spatial statistic changes substantially between them, the result is sensitive to whether corner-touching regions are treated as connected.
Use the rook matrix
$$ W_R= \begin{bmatrix} 0&1&1&0\\ 1&0&0&1\\ 1&0&0&1\\ 0&1&1&0 \end{bmatrix} $$
and observed values
$$ x= \begin{bmatrix} 10\\ 14\\ 8\\ 20 \end{bmatrix}. $$
The unstandardized spatial lag is
$$ W_Rx. $$
For A,
$$ (W_Rx)_A = 1(14)+1(8) = 22. $$
For B,
$$ (W_Rx)_B = 1(10)+1(20) = 30. $$
For C,
$$ (W_Rx)_C = 1(10)+1(20) = 30. $$
For D,
$$ (W_Rx)_D = 1(14)+1(8) = 22. $$
Thus
$$ \boxed{ W_Rx = \begin{bmatrix} 22\\ 30\\ 30\\ 22 \end{bmatrix} }. $$
These are neighbor sums, not neighbor averages.
A common transformation divides each nonzero row by its row sum.
If
$$ s_i=\sum_jw_{ij}, $$
then
$$ \boxed{ w_{ij}^{(R)} = \frac{w_{ij}}{s_i} }. $$
For a non-isolated location,
$$ \sum_jw_{ij}^{(R)}=1. $$
This changes the numerical meaning of $W$.
It is a modeling choice, not merely a computational trick.
In the rook matrix above, every cell has two neighbors.
The first row is
$$ [0,1,1,0]. $$
Its row sum is
$$ 2. $$
After row standardization,
$$ [0,1,1,0] \longrightarrow \left[ 0,\frac12,\frac12,0 \right]. $$
Therefore
$$ W_R^{(R)} = \begin{bmatrix} 0&1/2&1/2&0\\ 1/2&0&0&1/2\\ 1/2&0&0&1/2\\ 0&1/2&1/2&0 \end{bmatrix}. $$
Now compute
$$ W_R^{(R)}x. $$
For A,
$$ (W_R^{(R)}x)_A = \frac12(14) + \frac12(8). $$
So
$$ (W_R^{(R)}x)_A = 7+4 = 11. $$
Thus, A's spatial lag is the mean of its two neighbors:
$$ \boxed{ 11 }. $$
Similarly,
$$ (W_R^{(R)}x)_B = \frac12(10)+\frac12(20) = 15. $$
The full spatial lag is
$$ \boxed{ W_R^{(R)}x = \begin{bmatrix} 11\\ 15\\ 15\\ 11 \end{bmatrix} }. $$
This is why row-standardized binary weights are often described as producing a neighbor average.
For binary weights,
$$ (Wx)_i $$
grows partly with the number of neighbors.
A region with eight neighbors can receive a much larger raw lag than a region with two neighbors even when their neighboring values have similar magnitudes.
For row-standardized weights,
$$ (W^{(R)}x)_i $$
is instead a weighted average.
These two forms encode different ideas.
Neither is automatically appropriate in every application.

For point coordinates, define
$$ d_{ij} $$
as the distance between locations $i$ and $j$.
A distance-band matrix can be defined as
$$ \boxed{w_{ij}=\mathbf{1}{{0<d{ij}\le d_0}}} $$
Locations are treated as neighbors when they lie within the threshold $d_0$.
Suppose four locations lie on a line:
$$ A=0, \quad B=1, \quad C=3, \quad D=7 $$
in kilometers.
Use threshold
$$ d_0=2.5\text{ km}. $$
Distances include:
$$ d_{AB}=1, $$
$$ d_{BC}=2, $$
$$ d_{CD}=4, $$
$$ d_{AC}=3. $$
Therefore:
The binary weights are
$$ W= \begin{bmatrix} 0&1&0&0\\ 1&0&1&0\\ 0&1&0&0\\ 0&0&0&0 \end{bmatrix}. $$
Location D has no neighbors.
D is an island.
If the threshold changes from
$$ 2.5 $$
to
$$ 4.5\text{ km}, $$
additional links appear:
The graph can change substantially after a modest change in the threshold.
Therefore a threshold should be based on:
It should not be chosen simply because it produces a desired statistical result.
A $k$-nearest-neighbor rule connects each observation to its $k$ closest other observations.
For example, with
$$ k=2, $$
every location sends connections to its two nearest neighbors.
This is useful when sampling density varies across space.
Unlike a fixed distance band, $k$-NN avoids islands as long as there are at least $k+1$ observations.
Suppose three points lie at
$$ A=0, \qquad B=1, \qquad C=10. $$
With
$$ k=1, $$
A's nearest neighbor is B.
B's nearest neighbor is A.
C's nearest neighbor is B.
Therefore:
$$ w_{CB}=1, $$
but
$$ w_{BC}=0. $$
So
$$ W\neq W^\top. $$

This asymmetry is not an error.
It follows from the directed nearest-neighbor rule.
A directed $k$-NN graph can be symmetrized in different ways.
Locations $i$ and $j$ are connected if either selects the other:
$$ w_{ij}^{(U)} = 1 \quad\text{if}\quad w_{ij}=1 \text{ or } w_{ji}=1. $$
They are connected only if both select one another:
$$ w_{ij}^{(M)} = 1 \quad\text{if}\quad w_{ij}=w_{ji}=1. $$
These rules produce different graphs.
Always state which convention is used.
Instead of using a binary decision, distance can enter continuously.
A common form is
$$ \boxed{ w_{ij} = d_{ij}^{-\alpha} } $$
for
$$ i\neq j. $$
With
$$ \alpha=1, $$
the weight is inverse distance.
With
$$ \alpha=2, $$
weights decay faster.
Suppose location A has two neighbors at distances
$$ d_{AB}=1 $$
and
$$ d_{AC}=2. $$
With
$$ \alpha=1, $$
the raw weights are
$$ w_{AB}=1, $$
$$ w_{AC}=\frac12. $$
The row sum is
$$ 1+\frac12 = 1.5. $$
After row standardization,
$$ w_{AB}^{(R)} = \frac{1}{1.5} = \frac23, $$
and
$$ w_{AC}^{(R)} = \frac{0.5}{1.5} = \frac13. $$
If
$$ x_B=12, \qquad x_C=6, $$
then A's spatial lag is
$$ (Wx)_A = \frac23(12)+\frac13(6). $$
Therefore
$$ (Wx)_A = 8+2 = \boxed{ 10 }. $$
The closer neighbor therefore receives twice as much weight.
For inverse-distance weights,
$$ w_{ij}=d_{ij}^{-\alpha}, $$
a zero distance would cause division by zero.
This can occur if:
Possible responses include:
Do not allow infinite weights without explicitly addressing the cause.
For observed values
$$ x= \begin{bmatrix} x_1\\ \vdots\\ x_n \end{bmatrix}, $$
the spatial lag is
$$ \boxed{ Wx }. $$
At location $i$,
$$ (Wx)i = \sum_jw{ij}x_j. $$
It is a weighted summary of values at connected locations.
The phrase “neighbor average” is correct only when the weights in a row sum to 1.
For binary unstandardized weights,
$$ (Wx)_i $$
is a neighbor sum.
For inverse-distance weights without row standardization, it is a weighted sum.
For row-standardized weights, it is a weighted average.
This distinction matters when interpreting the resulting values.
For Moran's $I$, define centered observations
$$ z_i=x_i-\bar x. $$
Then calculate
$$ Wz. $$
A positive value
$$ (Wz)_i>0 $$
means that the neighborhood is above the global mean on average when row-standardized weights are used.
A negative value means the neighborhood is below the global mean.
This interpretation leads directly to the Moran scatterplot.
Use
$$ x= \begin{bmatrix} 10\\ 14\\ 8\\ 20 \end{bmatrix}. $$
The mean is
$$ \bar x = \frac{10+14+8+20}{4} = 13. $$
Therefore
$$ z= \begin{bmatrix} -3\\ 1\\ -5\\ 7 \end{bmatrix}. $$
Using row-standardized rook weights,
$$ (Wz)_A = \frac12(1)+\frac12(-5) = -2. $$
A is below the mean,
$$ z_A=-3, $$
and its neighborhood is also below the mean,
$$ (Wz)_A=-2. $$
A therefore falls in the low-low quadrant of a Moran scatterplot.
An island is a location with no neighbors under the chosen weights definition.
Mathematically,
$$ \sum_jw_{ij}=0. $$
For that row, ordinary row standardization would require division by zero.
An explicit convention is therefore needed.
Common options include:

Suppose row $i$ is
$$ [0,0,\ldots,0]. $$
Then
$$ (Wx)_i=0. $$
But zero here does not mean that the neighbors average to zero.
It means that the chosen weights definition provides no neighbor information for that location.
That distinction should be handled carefully in both plots and models.
A graph can contain several internally connected groups with no links between them.
For example,
$$ A-B-C $$
and
$$ D-E-F $$
may form two disconnected components.
This is not automatically a problem.
It may represent:
However, it changes the interpretation of global summaries because no spatial relationship is represented across components.
A weights matrix is symmetric when
$$ w_{ij}=w_{ji} $$
for every pair.
Binary rook contiguity is naturally symmetric:
If A shares an edge with B, B shares an edge with A.
Euclidean distance-band weights are also symmetric.
Directed $k$-NN weights need not be symmetric.
Symmetry can affect:
After row standardization, even a matrix that began symmetric may no longer be numerically symmetric when regions have different neighbor counts.
This distinction is important.
Suppose the original binary matrix has
$$ w_{ij}=w_{ji}=1. $$
If location $i$ has two neighbors, then after row standardization:
$$ w_{ij}^{(R)}=\frac12. $$
If location $j$ has four neighbors,
$$ w_{ji}^{(R)}=\frac14. $$
Therefore
$$ w_{ij}^{(R)} \neq w_{ji}^{(R)}. $$
The binary graph is symmetric, but the standardized numerical matrix is not.
For a binary graph, the degree of location $i$ is
$$ k_i = \sum_jw_{ij}. $$
It is the number of neighbors for that location.
Mapping or plotting degree is a useful diagnostic.
Very high degree can indicate:
Very low degree can indicate:

As the threshold $d_0$ increases:
At very large thresholds, nearly every observation may become connected to every other observation.
At that point, the weights matrix can lose much of its local spatial meaning.
The goal is not simply to maximize connectivity.
The graph should represent the scientifically relevant interaction scale.
A $k$-NN rule fixes the number of neighbors but not the distance to them.
In a dense city, the fifth nearest neighbor might be
$$ 200\text{ m} $$
away.
In a sparse rural area, the fifth nearest neighbor might be
$$ 20\text{ km} $$
away.
Thus, $k$-NN fixes graph degree at the cost of allowing the physical scale to vary.
This tradeoff should be considered in light of the scientific process.
A distance band makes the opposite tradeoff.
It fixes the physical scale but allows the number of neighbors to vary.
Dense regions may have many neighbors.
Sparse regions may have few or none.
This can be appropriate when the process has a meaningful interaction radius.
Suppose Moran's $I$ is calculated with:
These are not repeated calculations of one universal statistic.
They answer related but different questions because each defines a different neighborhood structure.
Similarly, a SAR model using $W_1$ is not the same model as a SAR model using $W_2$.
There is rarely a single uniquely correct $W$.
A strong analysis examines scientifically plausible alternatives.
For example:
$$ W_1=\text{rook adjacency}, $$
$$ W_2=\text{queen adjacency}, $$
$$ W_3=\text{4-nearest neighbors}. $$
Then compare:

Suppose a location has value
$$ x_A=10. $$
Under rook contiguity, its neighbors have values
$$ 8,\ 12. $$
The row-standardized lag is
$$ \frac{8+12}{2} = 10. $$
Under queen contiguity, suppose an additional diagonal neighbor has value
$$ 20. $$
Then the lag becomes
$$ \frac{8+12+20}{3} = \frac{40}{3} \approx13.33. $$
The same location can have a very different spatial lag when the neighborhood definition changes.
Before using a spatial weights matrix, inspect:
A weights matrix should be inspected like any other major model input.
Always state explicitly how $W$ was constructed.
It changes the interpretation from a raw neighbor sum to a relative weighting or average.
Directed nearest-neighbor relationships can be one-way.
Rows with zero neighbors require an explicit convention.
This can create scientifically meaningless long-distance links.
Adjacency, road links, flow networks, or travel time may be more appropriate.
The underlying graph may be symmetric while the standardized weights are not.
Weights should be justified independently of the desired result.
Global Moran's $I$ is
$$ I = \frac{n}{S_0} \frac{ z^\top Wz }{ z^\top z }, $$
where
$$ S_0=\sum_i\sum_jw_{ij}. $$
The weights matrix enters directly into the numerator.
Changing $W$ therefore changes the statistic.
This is why Moran's $I$ cannot be interpreted without specifying the weights matrix.
A spatial error model can contain
$$ u=\lambda Wu+\varepsilon. $$
A SAR model can contain
$$ y=\rho Wy+X\beta+\varepsilon. $$
The scientific meaning of $\lambda$ and $\rho$ therefore depends on what $W$ represents.
If $W$ means shared borders, the model propagates across shared borders.
If $W$ means nearest neighbors, it propagates through that graph.
The matrix defines the geometry through which spatial influence is represented.
Suppose four regions form a $2\times2$ grid:
$$ \begin{matrix} A&B\\ C&D \end{matrix} $$
with values
$$ x= \begin{bmatrix} 10\\ 14\\ 8\\ 20 \end{bmatrix}. $$
Using rook contiguity:
$$ W= \begin{bmatrix} 0&1&1&0\\ 1&0&0&1\\ 1&0&0&1\\ 0&1&1&0 \end{bmatrix}. $$
Every row has sum 2.
So row standardization gives
$$ W^{(R)} = \begin{bmatrix} 0&0.5&0.5&0\\ 0.5&0&0&0.5\\ 0.5&0&0&0.5\\ 0&0.5&0.5&0 \end{bmatrix}. $$
The spatial lag is
$$ W^{(R)}x = \begin{bmatrix} 11\\ 15\\ 15\\ 11 \end{bmatrix}. $$
The global mean is
$$ \bar x=13. $$
Centered values are
$$ z= \begin{bmatrix} -3\\ 1\\ -5\\ 7 \end{bmatrix}. $$
The centered spatial lag is
$$ W^{(R)}z = \begin{bmatrix} -2\\ 2\\ 2\\ -2 \end{bmatrix}. $$
This example contains the main logic needed for the next chapter on spatial autocorrelation.
The workflow is
$$ \text{spatial geometry} $$
$$ \downarrow $$
$$ \text{define scientific neighbor relation} $$
$$ \downarrow $$
$$ \text{construct }W $$
$$ \downarrow $$
$$ \text{inspect islands, degree, components, symmetry} $$
$$ \downarrow $$
$$ \text{choose raw or standardized weighting} $$
$$ \downarrow $$
$$ \text{calculate }Wx $$
$$ \downarrow $$
$$ \text{use }W\text{ in Moran, local statistics, or spatial models} $$
$$ \downarrow $$
$$ \text{check sensitivity to reasonable alternatives}. $$
The central idea is:
A spatial weights matrix is a mathematical statement about which locations can influence or summarize one another.