spnaf vignette
Find groups of unusually busy or quiet links in origin–destination data.
Prepare the counties and the flows
The CRAN package includes California county boundaries and migration counts. The input table needs an origin ID (oid), a destination ID (did), and a flow count (n). The IDs need to match the county IDs in the boundary data.
install.packages("spnaf")
library(spnaf)
migration <- spnaf::CA
flows <- data.frame(
oid = migration$FIPS.County.Code.of.Geography.B,
did = migration$FIPS.County.Code.of.Geography.A,
n = as.numeric(migration$Flow.from.Geography.B.to.Geography.A)
)
set.seed(42)
clusters <- Gij.flow(
df = flows,
shape = spnaf::CA_polygon,
method = "queen",
OD = "t",
R = 1000
)
head(clusters[[1]])
Read the results
The first result is a table with a score and p-value for each flow. Positive scores point to groups of higher flows and negative scores point to groups of lower flows. The second result contains line geometries for mapping the connections. The full vignette shows how to map the results and explains the options for defining nearby flows.