Skip to content

ENH: add GeneralizedParetoModel for GPD regression with covariates - #11203

Open
ByteMasterMike wants to merge 2 commits into
statsmodels:mainfrom
ByteMasterMike:enh-gpd-regression
Open

ByteMasterMike wants to merge 2 commits into
statsmodels:mainfrom
ByteMasterMike:enh-gpd-regression

Conversation

@ByteMasterMike

Copy link
Copy Markdown
Contributor

This PR adds a new statsmodels.extremes package with GeneralizedParetoModel, a regression model for threshold exceedances in which log scale and shape are both linear in covariates, following josef-pkt's design in #7317 (xref, this does not close it). The model is the one in Coles (2001), ch. 6, and is the same as ismev::gpd.fit with siglink = exp.

The log-likelihood uses one formula that is valid through shape 0 (a series near w = 0), with an analytic score and Hessian. Fitting runs BFGS followed by a Newton refinement, and a warning is issued when the fitted shape is below -0.5.

The tests check the model against scipy for the intercept-only model, a hand-written likelihood, numerical derivatives, and R's ismev and extRemes, where the parameters match and the log-likelihood here is slightly higher. They also cover a two-group case: with a binary covariate on both scale and shape, the likelihood splits into two separate scipy fits, which the model has to match exactly. The R script and its output are in statsmodels/extremes/tests/results/results_gpd_r.py.

Out of scope for now: a formula interface for the shape, an LR test, GEV regression, and the point-process model (#9663).

Questions for reviewers:

  1. Should this live in statsmodels.extremes or in othermod?
  2. Should the model be exported from the top-level statsmodels.api?

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code.
    Used for: Claude Code wrote the implementation, tests, docs and R validation script. I picked the model and scope from the #7317 discussion, wrote this description, ran the tests and the R comparison, and reviewed the code.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass ruff. You can
    verify your changes are well formatted by running
    ruff check . --fix
    
    assuming ruff is installed. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.
  • If AI tools were used to help write this PR, see the
    AI Policy for what disclosure
    and review is expected of you before submitting.

np.where(ok, sf_shape, np.nan),
)

def score_obs(self, params):
sf1, sf2 = self.score_factor(params)
return np.concatenate((sf1 @ self.exog, sf2 @ self.exog_shape))

def hessian_factor(self, params):
)
return GeneralizedParetoResultsWrapper(res)

def predict(self, params, exog=None, exog_shape=None, which="mean"):
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.

2 participants