Skip to content

DOC: document params ordering in zero-inflated model docstrings - #11289

Open
wangkangmao wants to merge 2 commits into
statsmodels:mainfrom
wangkangmao:doc-9319-zi-params-order
Open

wangkangmao wants to merge 2 commits into
statsmodels:mainfrom
wangkangmao:doc-9319-zi-params-order

Conversation

@wangkangmao

Copy link
Copy Markdown

Closes #9319

Issue

The docstrings of the multi-part (zero-inflated) count models do not say how the params vector is composed or ordered. This matters for users supplying start_params to fit, because fit inherits its docstring from the base model and carries no model-specific information about params.

Root cause

GenericZeroInflated.__init__ prepends the inflation-model names to exog_names:

infl_names = [f"inflate_{i}" for i in self.model_infl.data.param_names]
self.exog_names[:] = infl_names + list(self.exog_names)

and ZeroInflatedGeneralizedPoisson / ZeroInflatedNegativeBinomialP append alpha at the end. The likelihood, score and Hessian methods consistently split params at k_inflate, but none of the four class docstrings documented this, so the correct order was only discoverable by instantiating a model and inspecting exog_names.

Change

Add a shared Notes section (_doc_params_order) stating that inflation parameters come first, count-model parameters follow, and alpha is last for the Generalized Poisson / Negative Binomial variants. Reference exog_names as the authoritative source and include a concrete example. Inject it into the class docstrings of GenericZeroInflated, ZeroInflatedPoisson, ZeroInflatedGeneralizedPoisson and ZeroInflatedNegativeBinomialP.

Docs-only change: no runtime behavior is modified.

Verification

Confirmed the documented order against a live model instance:

ZeroInflatedPoisson
  k_inflate   = 2
  exog_names  = ['inflate_const', 'inflate_x1', 'const', 'x1']
  nparams     = 4
ZeroInflatedGeneralizedPoisson
  k_inflate   = 2
  exog_names  = ['inflate_const', 'inflate_x1', 'const', 'x1', 'alpha']
  nparams     = 5
ZeroInflatedNegativeBinomialP
  k_inflate   = 2
  exog_names  = ['inflate_const', 'inflate_x1', 'const', 'x1', 'alpha']
  nparams     = 5

All four class docstrings render the new Notes section, and the changed module's test suite passes:

$ python -m pytest statsmodels/discrete/tests/test_count_model.py -q -c /dev/null -p no:cacheprovider
92 passed, 1 xfailed, 43 warnings in 45.71s

@github-actions

Copy link
Copy Markdown

Thanks for the pull request! The PR description has no AI Disclosure section. If you replaced the pull request template with your own description, please add the section below.

Per the AI Policy, every pull request must state whether AI tools were used. Please edit the PR description so it includes the section below, tick exactly one box, and, if AI tools were used, replace the placeholders with the tool name(s) and how they were used.

#### AI Disclosure

Contributions must comply with the statsmodels [AI Policy](https://www.statsmodels.org/devel/dev/ai-policy.html).

- [ ] No AI tools were used to develop this pull request.
- [ ] AI tools were used.
      Tool(s): `<name(s), e.g. Copilot, Claude, ChatGPT>`.
      Used for: `<e.g. drafting an implementation, writing tests, debugging, editing docstrings>`.
      I have personally read, understood, and can explain every line of this diff, and
      have verified the statistical/numerical correctness of the change.

This check re-runs automatically when the description is edited.

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.

DOC: docstring are missing structure of params in multi-part models

1 participant