mixle.analysis.extreme module¶
Extreme-value analysis: tails, threshold exceedances, and support endpoints.
The mean of a sample tells you nothing reliable about its rare extremes – floods, market crashes, record temperatures live in the tail, where ordinary fitting has almost no data. Extreme-value theory gives the limiting shapes that govern tails and provides estimators built only from the largest order statistics:
gpd_fit()/peaks_over_threshold()– the Generalized Pareto Distribution for threshold exceedances (the POT method), by maximum likelihood or probability-weighted moments, withreturn_level()for “the once-in-m-observations level”.
hill_estimator()/moment_estimator()– tail-index estimators from the top-korder statistics (Hill for heavy tails; the Dekkers–Einmahl–de Haan moment estimator for any tail).
mean_residual_life()– the mean-excess plot for choosing the POT threshold (linear in the threshold once the GPD regime is reached).
endpoint_estimator()– the finite right endpoint of a bounded support (Hall-type / GPD), generic to frontier analysis, reliability limits, and image edges.
record_times()/n_records()– running-maximum records and their count.
- class GPDFit(shape, scale, threshold, n_exceedances, n_total, method)[source]
Bases:
objectFitted Generalized Pareto Distribution for exceedances over a threshold.
- Parameters:
- shape
tail index
xi(> 0heavy/Pareto tail,= 0exponential,< 0bounded).- Type:
- scale
scale
beta(> 0).- Type:
- threshold
the threshold
uthe exceedances were measured over.- Type:
- n_exceedances / n_total
exceedance and full-sample sizes (for return levels).
- method
"mle"or"pwm".- Type:
- shape: float
- scale: float
- threshold: float
- n_exceedances: int
- n_total: int
- method: str
- property endpoint: float
Right endpoint of the support (finite when
shape < 0, elseinf).
- gpd_fit(exceedances, *, threshold=0.0, method='mle', n_total=None)[source]
Fit a Generalized Pareto Distribution to threshold exceedances.
- Parameters:
exceedances (ndarray) – the excesses
x - ufor observations above the threshold (all positive). If you have raw data, usepeaks_over_threshold()instead.threshold (float) – the threshold
u(stored for return-level computation).method (str) –
"mle"(Newton/Nelder-Mead on the GPD likelihood) or"pwm"(probability-weighted moments, closed form, robust forxi < 0.5).n_total (int | None) – full sample size before thresholding (defaults to the number of exceedances).
- Returns:
A
GPDFit.- Return type:
GPDFit
- peaks_over_threshold(data, threshold, *, method='mle')[source]
Peaks-over-threshold: select exceedances above
thresholdand fit a GPD to the excesses.
- return_level(fit, period)[source]
POT return level: the level exceeded on average once per
periodobservations.x_m = u + (beta/xi) [ (m zeta_u)^xi - 1 ]withzeta_u = n_exceed/n_totalthe exceedance rate (period = m). Forxi = 0it reduces tou + beta log(m zeta_u).
- hill_estimator(data, k)[source]
Hill estimator of the tail index
xi = 1/alphafrom the topkorder statistics.xi_hat = (1/k) sum_{i=1}^{k} log(X_(n-i+1) / X_(n-k))– consistent for heavy (Pareto-type,xi > 0) tails. For a Pareto tail with exponentalphathis estimates1/alpha.
- moment_estimator(data, k)[source]
Dekkers–Einmahl–de Haan moment estimator of the extreme-value index (any tail sign).
Generalises Hill to
xiof either sign by combining the first two log-moments of the topkexceedances; works for heavy, light, and bounded (xi < 0) tails.
- mean_residual_life(data, thresholds)[source]
Mean-excess (mean-residual-life) function for POT threshold selection.
e(u) = mean(X - u | X > u). Over a range where the GPD fits,e(u)is approximately linear inu(slopexi/(1-xi)); the lowest threshold from which the plot is linear is the choice.
- endpoint_estimator(data, k, *, method='gpd')[source]
Estimate the finite right endpoint of a bounded support (frontier / boundary estimation).
Fits a GPD to the top
kexceedances overX_(n-k); when the tail indexxiis negative the support is bounded and the endpoint isx+ = X_(n-k) - beta/xi(which, by the GPD support constraint, necessarily exceeds the observed maximum). Generic to econometric frontier analysis, reliability limits, and image-edge localisation. Returnsinfif the estimated tail is unbounded (xi >= 0).
- record_times(data)[source]
Indices at which a new running maximum (upper record) occurs, including the first observation.