| Title: | Regularized Point Processes and Stochastic Marginalization for Extremes |
|---|---|
| Description: | Implements a non-stationary extreme value analysis framework by coupling a covariate-driven Non-Homogeneous Poisson Process (NHPP) with Elastic-Net regularization and exact analytical gradients. Provides methodologies for estimating conditional return levels and unconditional (marginalized) return levels via parametric stochastic integration over Vector Autoregressive VAR(p) covariate trajectories, or non-parametric block bootstrapping. Methodologies are based on Villa (2026) <https://sabi.ufrgs.br/> "A Novel Regularized Point Process and Stochastic Marginalization Framework for Return Level Inference under Covariate-Driven Extremes" (Master's dissertation, Universidade Federal do Rio Grande do Sul). |
| Authors: | Rodrigo Fonseca Villa [aut, cre] (ORCID: <https://orcid.org/0009-0005-2938-2270>), Flavio Ziegelmann [ths] (ORCID: <https://orcid.org/0000-0001-8899-350X>) |
| Maintainer: | Rodrigo Fonseca Villa <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-07-23 15:53:01 UTC |
| Source: | https://github.com/cran/margEVT |
Returns the covariate names that appear in the model with a non-negligible coefficient — i.e. those that actually affect the parameters and need to be supplied during marginalization.
active_covariates(fit, free_cols = NULL, tol = 1e-04)active_covariates(fit, free_cols = NULL, tol = 1e-04)
fit |
An |
free_cols |
Character vector of column names to always exclude from
the result (intercept and seasonality terms are always excluded).
Default |
tol |
Numeric. Coefficients smaller than this in absolute value are
treated as zero (LASSO shrinkage). Default |
Character vector of active covariate names, or NULL if
the model has no active non-seasonal covariates.
Evaluates predictive performance of a fitted nhpp_fit model via
walk-forward cross-validation. For each window, the model is refit on
training data at the original penalty and lambda, return levels are
computed, and exceedance rates are compared to nominal rates via
binomial tests. Probabilistic calibration is assessed via a
Kolmogorov-Smirnov test on the PIT values.
backtest( fit, data, varname, TRs = c(2, 5, 10), n_obs = 365L, window_years = 5L, min_train_years = 10L, n_boot = 200L, interactions = list(), year_col = "year", min_obs_year = NULL, verbose = TRUE )backtest( fit, data, varname, TRs = c(2, 5, 10), n_obs = 365L, window_years = 5L, min_train_years = 10L, n_boot = 200L, interactions = list(), year_col = "year", min_obs_year = NULL, verbose = TRUE )
fit |
An |
data |
The data frame used to fit |
varname |
Character. Name of the column in |
TRs |
Numeric vector of return periods to evaluate. Default
|
n_obs |
Integer. Observations per year. Default |
window_years |
Integer. Width of each validation window in years.
Default |
min_train_years |
Integer. Minimum number of training years before
the first validation window. Default |
n_boot |
Integer. Bootstrap years for covariate marginalization
within each window. Default |
interactions |
Named list of interactions passed to
|
year_col |
Character. Name of the year column. Default |
min_obs_year |
Integer. Minimum observations in a validation year
for it to be included. Default |
verbose |
Logical. Print progress. Default |
A list with three elements:
results |
Data frame with one row per validation year, containing the observed annual maximum, PIT value, and exceedance indicators for each return period. |
binom_tests |
Data frame with binomial test results for each TR. |
ks_test |
Data frame with KS test result for PIT calibration,
or |
Compute BIC for a fitted nhpp_fit model
bic_nhpp(fit, tol = 0.01)bic_nhpp(fit, tol = 0.01)
fit |
An |
tol |
Numeric. Coefficients smaller than this are counted as zero
for the active parameter count. Default |
Numeric scalar. BIC value.
Simulates R bootstrap samples, refits at the original penalty and
lambda, and returns empirical quantile CIs for each coefficient.
bootstrap_coef(fit, data, R = 200L, level = 0.95, seed = 42L, verbose = TRUE)bootstrap_coef(fit, data, R = 200L, level = 0.95, seed = 42L, verbose = TRUE)
fit |
An |
data |
The data frame used to fit |
R |
Integer. Number of bootstrap replicates. Default |
level |
Numeric. Confidence level. Default |
seed |
Integer. Random seed. Default |
verbose |
Logical. Print progress. Default |
A data frame with columns parameter, estimate,
CI_low, CI_high, n_ok. Only parameters with
non-negligible estimates (|estimate| > 1e-4) are returned.
Simulates R bootstrap samples from the fitted model, refits at the
original penalty and lambda, recomputes return levels via
marginalize, and returns empirical quantile CIs.
bootstrap_rl( fit, data, TRs = c(2, 5, 10, 20, 50, 100), R = 200L, approach = "C", marginalize_args = list(), level = 0.95, seed = 42L, verbose = TRUE )bootstrap_rl( fit, data, TRs = c(2, 5, 10, 20, 50, 100), R = 200L, approach = "C", marginalize_args = list(), level = 0.95, seed = 42L, verbose = TRUE )
fit |
An |
data |
The data frame used to fit |
TRs |
Numeric vector of return periods. Default |
R |
Integer. Number of bootstrap replicates. Default |
approach |
Character. Which marginalization approach to use for each
replicate: |
marginalize_args |
Named list of additional arguments passed to
|
level |
Numeric. Confidence level. Default |
seed |
Integer. Random seed. Default |
verbose |
Logical. Print progress. Default |
A data frame with columns TR, RL_est,
CI_low, CI_high, n_ok (number of successful
replicates).
Constructs a data frame with n_obs rows containing all columns
required by a fitted nhpp_fit model. Seasonality columns
(cos1, sen1, cos2, sen2) are computed
automatically from n_obs. Any other required column is filled
from cov_vals, or set to zero with a warning if absent.
build_cov_annual( fit, cov_vals = list(), n_obs = 365L, period = 365.25, interactions = list() )build_cov_annual( fit, cov_vals = list(), n_obs = 365L, period = 365.25, interactions = list() )
fit |
An |
cov_vals |
Named list of covariate values. Each element is either
a scalar (replicated to |
n_obs |
Integer. Number of rows (time points) to generate.
Typically |
period |
Numeric. Period for the seasonal harmonics in days.
Default |
interactions |
Named list of length-2 character vectors declaring
interaction columns to compute. Each element is
|
A data frame with n_obs rows and all columns required
by fit.
Build design matrices for the NHPP point process model
build_design_matrices( df, loc_vars = NULL, scale_vars = NULL, shape_vars = NULL, free_vars = NULL )build_design_matrices( df, loc_vars = NULL, scale_vars = NULL, shape_vars = NULL, free_vars = NULL )
df |
A data frame containing all required columns. |
loc_vars |
Character vector of covariate names for the location (mu) parameter. |
scale_vars |
Character vector of covariate names for the scale (sigma) parameter. |
shape_vars |
Character vector of covariate names for the shape (xi) parameter. |
free_vars |
Character vector of column names that should never be penalized
(e.g. seasonality terms like |
A list with elements:
X_mu |
Design matrix for location. |
X_sigma |
Design matrix for scale. |
X_xi |
Design matrix for shape. |
idx_pen_mu |
Integer indices of penalized columns in X_mu. |
idx_pen_sigma |
Integer indices of penalized columns in X_sigma. |
idx_pen_xi |
Integer indices of penalized columns in X_xi. |
Fits a peaks-over-threshold point process model via penalized maximum likelihood with BFGS optimization and exact analytical gradients.
fit_nhpp( df, threshold, loc_vars = NULL, scale_vars = NULL, shape_vars = NULL, free_vars = NULL, penalty = c("none", "lasso", "ridge", "elnet"), alpha = 0.5, lambda = "bic", penalize_shape = TRUE, obs_per_year = 365.25, maxit = 10000L, calc_hessian = FALSE, verbose = TRUE )fit_nhpp( df, threshold, loc_vars = NULL, scale_vars = NULL, shape_vars = NULL, free_vars = NULL, penalty = c("none", "lasso", "ridge", "elnet"), alpha = 0.5, lambda = "bic", penalize_shape = TRUE, obs_per_year = 365.25, maxit = 10000L, calc_hessian = FALSE, verbose = TRUE )
df |
A data frame containing the response and all covariates.
Must have a column named |
threshold |
Numeric scalar. The extreme value threshold u. |
loc_vars |
Character vector of covariate names for the location
parameter. |
scale_vars |
Character vector of covariate names for the scale
parameter. |
shape_vars |
Character vector of covariate names for the shape
parameter. |
free_vars |
Character vector of covariate names that are never
penalized (e.g. seasonality terms). |
penalty |
Character. Penalty type: |
alpha |
Numeric in [0, 1]. Elastic-net mixing parameter.
Only used when |
lambda |
Numeric scalar or named vector |
penalize_shape |
Logical. Penalize shape parameter covariates?
Default |
obs_per_year |
Numeric. Observations per year. E.g. |
maxit |
Integer. Maximum optimizer iterations. Default |
calc_hessian |
Logical. Compute Hessian at solution? Needed for
delta-method standard errors. Default |
verbose |
Logical. Print progress during BIC grid search and
convergence warnings. Default |
An object of class nhpp_fit.
Deseasonalizes each active covariate column in data (regressing
on cos1, sen1, cos2, sen2), then fits a multivariate VAR to the
standardized residuals. No covariate names are hardcoded: whatever
active_covariates returns (or whatever you pass in
vars) is treated as a final, ready-to-model column.
fit_var_generator(fit, data, vars = NULL, period = 365.25, lag_max = NULL)fit_var_generator(fit, data, vars = NULL, period = 365.25, lag_max = NULL)
fit |
An |
data |
Data frame used to fit |
vars |
Character vector of covariate names to model. Default
|
period |
Numeric. Seasonal period in observations. Default
|
lag_max |
Integer. Max VAR lag considered by |
An object of class nhpp_var_generator, or NULL
(with a warning) if the model has no active covariates.
Check if an object is an nhpp_fit
is_nhpp_fit(x)is_nhpp_fit(x)
x |
Any R object. |
Logical.
Given a fitted nhpp_fit model, computes return levels by
integrating out covariate uncertainty under one or more approaches:
marginalize( fit, data, TRs = c(2, 5, 10, 20, 50, 100), n_obs = 365L, approaches = c("A", "C"), scenarios = NULL, mc_sample = NULL, interactions = list(), year_col = "year", n_boot = 500L, seed = 2024L, tol_root = 1e-04, z_hi = NULL )marginalize( fit, data, TRs = c(2, 5, 10, 20, 50, 100), n_obs = 365L, approaches = c("A", "C"), scenarios = NULL, mc_sample = NULL, interactions = list(), year_col = "year", n_boot = 500L, seed = 2024L, tol_root = 1e-04, z_hi = NULL )
fit |
An |
data |
The data frame used to fit |
TRs |
Numeric vector of return periods in years. Default
|
n_obs |
Integer. Observations per year. Default |
approaches |
Character vector. Which approaches to run. Any subset of
|
scenarios |
Named list of covariate scenarios for approach A. Each
element is itself a named list of scalar covariate values, passed to
|
mc_sample |
List of data frames for approach B. Each element is one
simulated year of covariates ( |
interactions |
Named list of interactions passed to
|
year_col |
Name of the year column in |
n_boot |
Integer. Number of bootstrap years for approach C.
Default |
seed |
Integer. Random seed for approach C. Default |
tol_root |
Numeric. Root-finding tolerance. Default |
z_hi |
Numeric. Upper search bound for return levels. If |
Covariates fixed at user-specified scenarios (e.g. quantiles of observed distributions). Fast; useful for sensitivity analysis.
Covariates drawn from a user-supplied Monte Carlo
sample (e.g. from a fitted VAR or any stochastic generator). The
sample is a list of n_obs-row data frames, one per simulated
year.
Block bootstrap over observed covariate years.
Resamples whole years from data to preserve temporal structure.
A data frame with columns approach, scenario,
TR, RL.
Extract the number of exceedances from a fitted model
n_exceedances(fit, y)n_exceedances(fit, y)
fit |
An |
y |
Numeric vector of observations used to fit the model. |
Integer. Number of observations exceeding the threshold.
Analytical gradient of the penalized negative log-likelihood
pp_grad( par, dm, y, threshold, lambda = 0.1, alpha = 0.5, pen_xi = TRUE, eps_l1 = 1e-10, obs_per_year = 365.25 )pp_grad( par, dm, y, threshold, lambda = 0.1, alpha = 0.5, pen_xi = TRUE, eps_l1 = 1e-10, obs_per_year = 365.25 )
par |
Numeric vector of parameters: c(beta_mu, beta_sigma, beta_xi). |
dm |
Design matrix list from |
y |
Numeric vector of observations. |
threshold |
Numeric scalar. The extreme value threshold u. |
lambda |
Penalty strength. Either a scalar or named vector
|
alpha |
Elastic-net mixing parameter in [0,1]. 1 = LASSO, 0 = ridge.
Either a scalar or named vector |
pen_xi |
Logical. Should the shape parameter covariates be penalized? |
eps_l1 |
Small positive constant for smooth L1 approximation. |
obs_per_year |
Number of observations per year (e.g. 365.25 for daily). |
Numeric vector of length length(par).
Penalized negative log-likelihood for the NHPP model
pp_nllh( par, dm, y, threshold, lambda = 0.1, alpha = 0.5, pen_xi = TRUE, eps_l1 = 1e-10, obs_per_year = 365.25 )pp_nllh( par, dm, y, threshold, lambda = 0.1, alpha = 0.5, pen_xi = TRUE, eps_l1 = 1e-10, obs_per_year = 365.25 )
par |
Numeric vector of parameters: c(beta_mu, beta_sigma, beta_xi). |
dm |
Design matrix list from |
y |
Numeric vector of observations. |
threshold |
Numeric scalar. The extreme value threshold u. |
lambda |
Penalty strength. Either a scalar or named vector
|
alpha |
Elastic-net mixing parameter in [0,1]. 1 = LASSO, 0 = ridge.
Either a scalar or named vector |
pen_xi |
Logical. Should the shape parameter covariates be penalized? |
eps_l1 |
Small positive constant for smooth L1 approximation. |
obs_per_year |
Number of observations per year (e.g. 365.25 for daily). |
Scalar. The penalized negative log-likelihood value.
Given an nhpp_fit object and a data frame of covariate values,
returns the implied location, scale, and shape parameters at each row.
predict_params(fit, newdata = NULL)predict_params(fit, newdata = NULL)
fit |
An object of class |
newdata |
A data frame with one row per time point. Must contain all
columns that appear in the model's design matrices (except the intercept).
If |
A list with three numeric vectors of length nrow(newdata):
mu |
Location parameter. |
sigma |
Scale parameter (always positive). |
xi |
Shape parameter. |
Converts the long-format output of marginalize into a
wide table with one row per scenario and one column per return period.
rl_table(marg_result)rl_table(marg_result)
marg_result |
Data frame returned by |
A wide data frame.
Simulate stationary covariate trajectories from a VAR generator
simulate_covariates(generator, n_mc, n_obs = 365L, burn_in = 300L, seed = NULL)simulate_covariates(generator, n_mc, n_obs = 365L, burn_in = 300L, seed = NULL)
generator |
Object from |
n_mc |
Integer. Number of simulated years. |
n_obs |
Integer. Observations per simulated year. Default |
burn_in |
Integer. Burn-in to discard transient VAR dynamics.
Default |
seed |
Integer. Random seed. Default |
A list of length n_mc, each element an n_obs-row
data frame with one column per active covariate - directly usable as
mc_sample in marginalize (approach B).
Prints a structured summary of a fitted nhpp_fit object, including
the penalty used, active coefficients, and basic model diagnostics.
## S3 method for class 'nhpp_fit' summary(object, tol = 1e-04, ...)## S3 method for class 'nhpp_fit' summary(object, tol = 1e-04, ...)
object |
An |
tol |
Numeric. Coefficients smaller than this in absolute value are
treated as zero. Default |
... |
Ignored. |
Invisibly returns the input nhpp_fit object.