8000 kullback: count dof per initial state, accept list input, drop T6 by kadnaoui · Pull Request #266 · pysal/giddy · GitHub
[go: up one dir, main page]

Skip to content

kullback: count dof per initial state, accept list input, drop T6 - #266

Open
kadnaoui wants to merge 1 commit into
pysal:mainfrom
kadnaoui:fix/kullback-dof-list-input
Open

kadnaoui wants to merge 1 commit into
pysal:mainfrom
kadnaoui:fix/kullback-dof-list-input

Conversation

@kadnaoui
Copy link
Copy Markdown

Fixes #265, with the approach suggested there for each point.

  1. Degrees of freedom. cdof is now the sum over initial states of (s_i - 1)(c_i - 1), where s_i counts the strata with transitions from state i and c_i the terminal states reached from it (each factor floored at 0). That is the dof of the per-initial-state conditional G-tests the statistic already sums. Without empty margins it equals r(s-1)(r-1) as before.
    • Heads-up: this changes the Kullback (1962) Table 9.2 example from 30 to 29, because nothing moves from state 3 to state 0 in either stratum. I updated the docstring example and test___init__ and added a comment. The p-value there is still 0.0.
  2. List input. F = np.asarray(F) at the top, so nested lists work.
  3. T6 was unused, so I removed it.

Tests (in TestKullback):

  • test_dof_with_empty_margins compares the statistic and dof with chi2_contingency on each initial state's strata x terminal-state table, after dropping empty rows and columns. This is the dof check the issue asked to add next to test_matches_conditional_g.
  • test_list_input

Both fail on main (dof 6 instead of 3; TypeError for the list) and pass with the change. The full test suite and the markov.py doctests pass, and ruff check / ruff format --check are clean.

- The degrees of freedom assumed every initial state has transitions in
  every stratum and reaches every terminal state. Count them per initial
  state as (s_i - 1)(c_i - 1) over the non-empty strata and terminal
  states instead, matching the conditional G-tests the statistic sums.
  For the Kullback (1962) example this gives 29: nothing moves from
  state 3 to state 0.
- Convert F with np.asarray so nested lists work.
- Remove the unused T6 term.

Fixes pysal#265

This branch has not been deployed

No deployments
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.

kullback(): dof ignores empty margins, list input fails, unused T6

1 participant

0