Package 'dgevbhm'

Title: Bayesian Hierarchical Modeling for Duration-Dependent GEV
Description: The dgevbhm package is a software package written in R and Stan that offers a Bayesian hierarchical regional framework to estimate the occurrence probability of extreme precipitation based on small sample sizes, as sub-daily observations and high-resolution climate model simulations typically cover less than 50 years. dgevbhm features Bayesian parameter estimation for the duration-dependent Generalized Extreme Value distribution, which requires annual maxima of precipitation across different durations. By utilizing No U-turn sampling via rstan, models sample posterior samples more efficiently, and with the help tensor computation via torch these large posterior samples are computed quicker and more efficiently. Furthermore, the package provides model application and evaluation tools to guide the user in model selection, as well as making inferences from model output to generate robust estimations of intensity-duration-frequency curves.
Authors: Alexander Lee Rischmuller [aut, cre]
Maintainer: Alexander Lee Rischmuller <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-06-06 06:20:45 UTC
Source: https://github.com/AlexLeeR/dgevbhm

Help Index


Read and Process Precipitation Station Data

Description

This function reads .txt files from a directory, extracts metadata, and calculates annual maximum precipitation for specified durations.

Usage

data_read(
  dir_path,
  missing_data = 5,
  durs = c(1, 3, 6, 12, 24, 48),
  cores = 4,
  min_year = 25
)

Arguments

dir_path

Character. Path to the directory containing .txt files.

missing_data

Numeric. Percentage threshold for missing data (default is 5).

durs

Numeric vector. Durations (in hours) to calculate max precipitation.

cores

Integer. Number of CPU cores for parallel processing.

min_year

Integer. Minimum number of valid years required to keep a station.

Value

A list containing processed precipitation arrays, annual mean precipitation, coordinates, and station IDs.


Bayesian Hierarchical Model for d-GEV

Description

Fits a Bayesian Hierarchical Model using Stan for duration-dependent Generalized Extreme Value distributions.

Usage

dgev_bhm(data, chains = 4, iter = 2000, cores = 4, shp_d = NULL)

Arguments

data

A list containing processed station data (output from data_read).

chains

Integer. Number of independent MCMC chains.

iter

Integer. Number of iterations per chain (including warmup).

cores

Integer. Number of cores for parallel sampling.

shp_d

Character. Dimension for shape parameter: "d" for durational, "j" for spatial.

Value

A list containing MCMC samples (pars), original data, and metadata.


Result of xi_d Model Fit

Description

Pre-computed BHM fit using the shape parameter hierarchical with respect to duration.

Usage

fit_xi_d

Format

An object of class list of length 10.


Result of xi_d Model Fit

Description

Pre-computed BHM fit using the shape parameter hierarchical with respect to space.

Usage

fit_xi_j

Format

An object of class list of length 10.


GEV Cumulative Distribution Function using Base R

Description

Calculates the CDF for the Generalized Extreme Value distribution using highly optimized base R logical subsetting.

Usage

gev_cdf(x, mu, sigma, xi)

Arguments

x

Numeric vector, matrix, or array. The data points.

mu

Numeric vector, matrix, or array. Location parameter.

sigma

Numeric vector, matrix, or array. Scale parameter.

xi

Numeric vector, matrix, or array. Shape parameter.


Quantile function for d-GEV using Base R

Description

Quantile function for d-GEV using Base R

Usage

gev_mat(p, mu_mat, sigma_mat, xi_vec, xi_dim)

Arguments

p

Probability (scalar)

mu_mat

Location parameter matrix (Durations x Samples)

sigma_mat

Scale parameter matrix (Durations x Samples)

xi_vec

Shape parameter vector

xi_dim

Character. "duration" for shp_d='d', "sample" for shp_d='j'


Plot IDF Curves using Base R

Description

Plot IDF Curves using Base R

Usage

idf_plot(fit, j = NULL, rp, alpha = 0.05)

Arguments

fit

List. The output object from the dgev_bhm function.

j

Integer. Station index.

rp

Numeric vector. Return periods (max 3).

alpha

Numeric. Significance level.


Posterior Predictive Histogram Plot (Base R)

Description

Generates a histogram of the posterior predictive distribution for a specific statistic and compares it against the observed (empirical) value.

Usage

post_pred_plot(fit, stat, d, j)

Arguments

fit

List. Output from dgev_bhm.

stat

Numeric (0-1) or Character ("median", "max", "min"). The statistic to check.

d

Integer. Index of the duration to plot.

j

Integer. Index of the station to plot.


Posterior Predictive P-value (PPP)

Description

Calculates the posterior predictive p-value for a given statistic. A value near 0.5 indicates a good model fit.

Usage

post_pred_pval(fit, stat, d, j)

Arguments

fit

List. Output from dgev_bhm.

stat

Numeric (0-1) or Character ("median", "max", "min"). The statistic to check.

d

Integer. Index of the duration.

j

Integer. Index of the station.

Value

Numeric. The calculated PPP.


Probability-Probability (P-P) Plot for d-GEV

Description

Creates a P-P plot comparing empirical probabilities to theoretical d-GEV probabilities with credible intervals using base R.

Usage

pp_plot(fit, j, alpha = 0.05)

Arguments

fit

List. Output from dgev_bhm.

j

Integer. Index of the station to plot.

alpha

Numeric. Significance level for credible intervals (default 0.05).


Plot Return Level Curves for d-GEV (Base R)

Description

Calculates and plots the relationship between return periods and precipitation intensity (return levels) with Bayesian credible intervals.

Usage

return_level_plot(fit, max_rp = 100, j, d, alpha = 0.05)

Arguments

fit

List. Output from dgev_bhm.

max_rp

Numeric or Character. Maximum return period to plot. Use "data" to cap at the record length.

j

Integer. Index of the station.

d

Integer. Index of the duration.

alpha

Numeric. Significance level for the credible interval (default 0.05).


UK Extreme Rainfall Data

Description

A dataset containing annual maxima for 25 stations. Filtered using amp median.

Usage

UK_data

Format

A list with elements:

y

A list of matrices duration dependent annual maxima for each station. year x duration

amp

Annual mean precipitation for each station.

latlon

Latitude and longitude for each station.

stationID

station ID for each station.

durs

Durations corresponding to the columns of the y matrices.


UK Extreme Rainfall Data

Description

A dataset containing annual maxima for 47 stations. The full list of processed data.

Usage

UK_data_full

Format

A list with elements:

y

A list of matrices duration dependent annual maxima for each station. year x duration

amp

Annual mean precipitation for each station.

latlon

Latitude and longitude for each station.

stationID

station ID for each station.

durs

Durations corresponding to the columns of the y matrices.