| Type: | Package |
| Title: | Regularized Point Processes and Stochastic Marginalization for Extremes |
| Version: | 0.1.0 |
| 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). |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | stats, utils, vars |
| Suggests: | dplyr, tidyr, extRemes, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-16 14:01:26 UTC; rodri |
| Author: | Rodrigo Fonseca Villa
|
| Maintainer: | Rodrigo Fonseca Villa <rodrigo03.villa@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-23 13:50:14 UTC |
BIC-based lambda selection for penalized NHPP models (internal)
Description
BIC-based lambda selection for penalized NHPP models (internal)
Usage
.select_lambda_bic(
dm,
y,
threshold,
alpha,
penalize_shape,
init,
obs_per_year = 365.25,
maxit = 5000L,
verbose = TRUE
)
Arguments
dm |
Design matrix list from |
y |
Numeric response vector. |
threshold |
Numeric scalar threshold. |
alpha |
Elastic-net mixing parameter. |
penalize_shape |
Logical. |
init |
Named numeric starting parameter vector. |
obs_per_year |
Numeric. |
maxit |
Integer. |
verbose |
Logical. |
Value
Named numeric vector c(mu=, sigma=, xi=) of selected lambdas.
Extract names of non-seasonal covariates from a fitted model
Description
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.
Usage
active_covariates(fit, free_cols = NULL, tol = 1e-04)
Arguments
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 |
Value
Character vector of active covariate names, or NULL if
the model has no active non-seasonal covariates.
Walk-forward backtesting for NHPP extreme value models
Description
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.
Usage
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
)
Arguments
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 |
Value
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
Description
Compute BIC for a fitted nhpp_fit model
Usage
bic_nhpp(fit, tol = 0.01)
Arguments
fit |
An |
tol |
Numeric. Coefficients smaller than this are counted as zero
for the active parameter count. Default |
Value
Numeric scalar. BIC value.
Parametric bootstrap confidence intervals for model coefficients
Description
Simulates R bootstrap samples, refits at the original penalty and
lambda, and returns empirical quantile CIs for each coefficient.
Usage
bootstrap_coef(fit, data, R = 200L, level = 0.95, seed = 42L, verbose = TRUE)
Arguments
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 |
Value
A data frame with columns parameter, estimate,
CI_low, CI_high, n_ok. Only parameters with
non-negligible estimates (|estimate| > 1e-4) are returned.
Parametric bootstrap confidence intervals for return levels
Description
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.
Usage
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
)
Arguments
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 |
Value
A data frame with columns TR, RL_est,
CI_low, CI_high, n_ok (number of successful
replicates).
Build a covariate data frame for marginalization
Description
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.
Usage
build_cov_annual(
fit,
cov_vals = list(),
n_obs = 365L,
period = 365.25,
interactions = list()
)
Arguments
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
|
Value
A data frame with n_obs rows and all columns required
by fit.
Build design matrices for the NHPP point process model
Description
Build design matrices for the NHPP point process model
Usage
build_design_matrices(
df,
loc_vars = NULL,
scale_vars = NULL,
shape_vars = NULL,
free_vars = NULL
)
Arguments
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 |
Value
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. |
Fit a non-homogeneous point process model for extremes
Description
Fits a peaks-over-threshold point process model via penalized maximum likelihood with BFGS optimization and exact analytical gradients.
Usage
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
)
Arguments
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 |
Value
An object of class nhpp_fit.
Fit a generic VAR generator over a model's active covariates
Description
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.
Usage
fit_var_generator(fit, data, vars = NULL, period = 365.25, lag_max = NULL)
Arguments
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 |
Value
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
Description
Check if an object is an nhpp_fit
Usage
is_nhpp_fit(x)
Arguments
x |
Any R object. |
Value
Logical.
Compute unconditional return levels by marginalizing over covariates
Description
Given a fitted nhpp_fit model, computes return levels by
integrating out covariate uncertainty under one or more approaches:
Usage
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
)
Arguments
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 |
Details
- A — conditional
Covariates fixed at user-specified scenarios (e.g. quantiles of observed distributions). Fast; useful for sensitivity analysis.
- B — parametric
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.- C — empirical
Block bootstrap over observed covariate years. Resamples whole years from
datato preserve temporal structure.
Value
A data frame with columns approach, scenario,
TR, RL.
Extract the number of exceedances from a fitted model
Description
Extract the number of exceedances from a fitted model
Usage
n_exceedances(fit, y)
Arguments
fit |
An |
y |
Numeric vector of observations used to fit the model. |
Value
Integer. Number of observations exceeding the threshold.
Analytical gradient of the penalized negative log-likelihood
Description
Analytical gradient of the penalized negative log-likelihood
Usage
pp_grad(
par,
dm,
y,
threshold,
lambda = 0.1,
alpha = 0.5,
pen_xi = TRUE,
eps_l1 = 1e-10,
obs_per_year = 365.25
)
Arguments
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). |
Value
Numeric vector of length length(par).
Penalized negative log-likelihood for the NHPP model
Description
Penalized negative log-likelihood for the NHPP model
Usage
pp_nllh(
par,
dm,
y,
threshold,
lambda = 0.1,
alpha = 0.5,
pen_xi = TRUE,
eps_l1 = 1e-10,
obs_per_year = 365.25
)
Arguments
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). |
Value
Scalar. The penalized negative log-likelihood value.
Compute time-varying GEV parameters from a fitted model
Description
Given an nhpp_fit object and a data frame of covariate values,
returns the implied location, scale, and shape parameters at each row.
Usage
predict_params(fit, newdata = NULL)
Arguments
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 |
Value
A list with three numeric vectors of length nrow(newdata):
mu |
Location parameter. |
sigma |
Scale parameter (always positive). |
xi |
Shape parameter. |
Wide-format return level table from marginalize() output
Description
Converts the long-format output of marginalize into a
wide table with one row per scenario and one column per return period.
Usage
rl_table(marg_result)
Arguments
marg_result |
Data frame returned by |
Value
A wide data frame.
Simulate stationary covariate trajectories from a VAR generator
Description
Simulate stationary covariate trajectories from a VAR generator
Usage
simulate_covariates(generator, n_mc, n_obs = 365L, burn_in = 300L, seed = NULL)
Arguments
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 |
Value
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).
Summarise a fitted nhpp_fit model
Description
Prints a structured summary of a fitted nhpp_fit object, including
the penalty used, active coefficients, and basic model diagnostics.
Usage
## S3 method for class 'nhpp_fit'
summary(object, tol = 1e-04, ...)
Arguments
object |
An |
tol |
Numeric. Coefficients smaller than this in absolute value are
treated as zero. Default |
... |
Ignored. |
Value
Invisibly returns the input nhpp_fit object.