griddy is an R package for geospatial distribution
dynamics with sf and tidy data. It is inspired by PySAL
giddy and by established spatial distribution dynamics
work, especially Rey (2001). Prior R implementations exist, including
estdaR and spdyn, but neither is on CRAN or
designed along tidy principles. This package is designed to work best
with long data and sf native spatial workflows.
Current scope:
ggplot2 plotsVersion 0.2.0 extends the core workflow with chain summaries and inferential tests for transition-regime homogeneity.
# CRAN release
install.packages("griddy")
# Development version
install.packages("pak")
pak::pak("dshkol/griddy")The minimal example below also uses spData for state
geometry:
install.packages("spData")griddy keeps the workflow keyed by explicit
id, time, and value columns
instead of matrix row position. The analytical outputs preserve
transition labels, class intervals, and spatial-lag intervals so they
can be inspected, joined, and plotted without reverse-engineering array
dimensions.
The bundled usjoin panel is the canonical PySAL
giddy reference dataset: 48 contiguous US states,
per-capita personal income, 1929 to 2009.
library(griddy)
library(dplyr)
library(sf)
library(sfdep)
library(spData)
data(usjoin)
geom <- us_states |>
filter(NAME %in% usjoin$name) |>
mutate(
nb = st_contiguity(geometry),
wt = st_weights(nb)
)
panel <- usjoin |>
filter(name %in% geom$NAME) |>
arrange(name, year)
classes <- classify_dynamics(panel, name, year, income, k = 5)
classic <- markov_dynamics(classes, name, year, class)
spatial <- spatial_markov(
panel, name, year, income,
geometry = geom, geometry_id = NAME, k = 5
)
classic$transitions |> select(id, from_time, to_time, transition) |> head()
lag_intervals(spatial)spatial_markov() takes a geometry argument:
an sf tibble with one row per spatial unit and
nb / wt list-columns produced by
sfdep. This keeps the spatial frame, neighbor structure,
and row-standardization choice in one tidy object. Rows of
geometry are matched to panel units by id, through the
column named in geometry_id or a column with the same name
as id. listw and nb arguments
remain accepted for compatibility with existing workflows.
The pkgdown site is organized around:
tidycensus and cancensus examples showing
applications with US and Canadian census datagiddy: what griddy
implements, short recipes for the rest, and what is plannedestdaR and
spdynllms.txt
index of the siteAI coding agents contributing to griddy should start
with AGENTS.md.