Repository navigation
ENH: add GeneralizedParetoModel for GPD regression with covariates - #11203
Open
ByteMasterMike wants to merge 2 commits into
Open
ByteMasterMike wants to merge 2 commits into
ByteMasterMike wants to merge 2 commits into
Conversation
| 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"): |
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.
This PR adds a new
statsmodels.extremespackage withGeneralizedParetoModel, 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 asismev::gpd.fitwithsiglink = 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
ismevandextRemes, 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 instatsmodels/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:
statsmodels.extremesor inothermod?statsmodels.api?NumPy's guide.
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.
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:
needed for doc changes.
then show that it is fixed with the new code.
verify your changes are well formatted by running
ruffis installed. While passing this test is not required, it is good practice and it helpimprove code quality in
statsmodels.AI Policy for what disclosure
and review is expected of you before submitting.