Space as math

How to include space in statistics?

We need its mathematical representation

geometries are not

graphs are

What is a graph?

a data structure that consists of a set of objects called nodes and a set of connections between them called edges

Matrix

\[ \begin{array}{cccc} 0 & w_{12} & \dots & w_{1N} \\ w_{21} & \ddots & w_{ij} & \vdots \\ \vdots & w_{ji} & 0 & \vdots \\ w_{N1} & \dots & \dots & 0 \end{array} \]

Matrix

\[ \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array} \]

mathematical structure capturing spatial relationships

What is a neighbour?

it depends

Contiguity

Two geometries are considered neighbours if they share at least one vertex (queen contiguity) or one edge (rook contiguity).

Starting with some polygons…

Focus on this one. Which are its neighbours?

Based on (rook) contiguity, these.

Here is a complete graph.

Here is a complete graph.

Distance

Two geometries are considered neighbours if they lie within a set threshold from each other

Distance band

Everything within a distance is a neighbour.

Just like this.

Here is a complete graph. A bit denser.

Here is a complete graph. A bit denser.

Distance

A geometry is considered a neighbour if it is no further than K-1 others

K-nearest neighbour

Only a set number of nearest geometries are neighbours.

In this case \(k=5\).

And a graph.

And a graph.

This would be the same with \(k=1\).

This would be the same with \(k=1\).

Block contiguity/regions

Two geometries are considered neighbours if they belong to the same group

Let’s assume five regions.

Let’s assume four regions. Each polygon belongs to one.

All geometries within a region are neighbours.

Graph forms isolated components.

Graph forms isolated components.

Graph routines

Order of contiguity

Let’s bring back contiguity.

Order 2 of contiguity

Order 3 of contiguity

Order 4 of contiguity

Component analysis

Let’s bring back KNN with \(k=1\).

You can identify connected components.

Weights are not always binary

Look at 20 nearest neighbours.

The closer a neighbour is, the higher the weight it has.

time to code

from libpysal import graph