Skip to content

Add homogeneity_test(): chi2, likelihood-ratio, and Kullback tests for transition regimes - #3

Merged
dshkol merged 3 commits into
mainfrom
feature/markov-inference
Aug 2, 2026
Merged

dshkol merged 3 commits into
mainfrom
feature/markov-inference

Conversation

@dshkol

@dshkol dshkol commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Second tranche of the 0.2.0 feature work: the inference layer. This closes the biggest scoping caveat — griddy could show that lag-conditioned matrices differ but not test whether they differ beyond sampling noise.

New function

homogeneity_test(x) — generic with two methods:

  • grd_spatial_markov: tests the Rey, Kang & Wolf (2016) question directly — do the transition matrices conditioned on spatial-lag class differ from the pooled matrix?
  • list of count matrices: the same machinery for arbitrary regime stratifications (LISA Markov quadrant regimes, time regimes, etc.)

Returns a tidy tibble with one row per test: Pearson chi-squared Q and likelihood-ratio (both with the Bickenbach & Bald 2003 degrees-of-freedom adjustment), and the Kullback, Kupperman & Ku (1962) information test.

On the bundled usjoin panel: Q = 200.6 (df 60), LR = 170.7 — spatial conditioning decisively matters, which is the headline number for the release post.

Validation

  • Exact agreement with PySAL giddy 2.3.9 Spatial_Markov homogeneity attributes (Q, LR, dof, p-values) and giddy.markov.kullback() on the usjoin spatial count matrices; fixture generated by the new tools/oracle/pysal_giddy_inference.py (kept separate from the existing oracle script to avoid cross-branch conflicts)
  • The published Kullback (1962) Table 9.2 example ships as an in-package reference test (statistic 160.961, df 30)
  • Shipped tests also cover identical-regime invariants (Q = LR = 0; the Kullback statistic is deliberately not zero there — verified against giddy) and error paths
  • devtools::check(): 0 errors, 0 warnings, 0 notes

Note: branched off main independently of #2; both add a section under the same NEWS heading, so whichever merges second needs a trivial conflict resolution there.

🤖 Generated with Claude Code

dshkol and others added 3 commits July 27, 2026 21:16
Tests whether transition dynamics differ across regimes. For
grd_spatial_markov objects this is the Rey, Kang & Wolf (2016) question:
do the lag-conditioned matrices differ from the pooled matrix? Reports:

- Pearson chi-squared Q and likelihood-ratio tests with the
  Bickenbach & Bald (2003) degrees-of-freedom adjustment
- the Kullback, Kupperman & Ku (1962) information test

Returns a tidy one-row-per-test tibble. A list method accepts arbitrary
regime count matrices (e.g. LISA Markov quadrant regimes or time
regimes), so the machinery is not tied to spatial conditioning.

Validated against PySAL giddy 2.3.9: exact agreement with
Spatial_Markov Q/LR/dof/p-values and giddy.markov.kullback() on the
usjoin spatial count matrices (fixture generated by
tools/oracle/pysal_giddy_inference.py), plus the published Kullback
(1962) Table 9.2 example as a shipped reference test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dshkol
dshkol merged commit 0d8d57f into main Aug 2, 2026
6 checks passed
@dshkol
dshkol deleted the feature/markov-inference branch August 2, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant