Repository navigation
Conversation
The stratum-specific margin summed over initial states (axis=1), giving terminal-state totals, while the pooled margin used initial-state totals. The two only agree when every stratum's table is flow-balanced, which the Table 9.2 docstring example happens to be. For unbalanced tables, such as transition counts aggregated across many units, identical strata produced a nonzero statistic. Sum over axis=2 so the stratum margin counts transitions starting in each state. Add tests for identical strata (statistic must be zero) and for agreement with the sum of per-initial-state G-tests from scipy.stats.chi2_contingency. The existing Table 9.2 value is unchanged. Closes pysal#259 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011NgjHye3i25EidsJFhWAeF
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #259.
kullback()computed the stratum-specific margin withF.sum(axis=1), which for the documented(strata, initial, terminal)layout sums over initial states and yields terminal-state totals. The pooled margin uses initial-state totals, so the two terms only cancel when each stratum's table is flow-balanced. The Table 9.2 example is exactly balanced, which is why the existing test couldn't catch it. For unbalanced tables, including any transition counts aggregated across many units, two identical strata produced a positive statistic.This changes the stratum margin to
F.sum(axis=2)and adds two tests:scipy.stats.chi2_contingencyThe Table 9.2 value (160.9606...) is unchanged.