| 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 |
This function reads .txt files from a directory, extracts metadata, and calculates annual maximum precipitation for specified durations.
data_read( dir_path, missing_data = 5, durs = c(1, 3, 6, 12, 24, 48), cores = 4, min_year = 25 )data_read( dir_path, missing_data = 5, durs = c(1, 3, 6, 12, 24, 48), cores = 4, min_year = 25 )
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. |
A list containing processed precipitation arrays, annual mean precipitation, coordinates, and station IDs.
Fits a Bayesian Hierarchical Model using Stan for duration-dependent Generalized Extreme Value distributions.
dgev_bhm(data, chains = 4, iter = 2000, cores = 4, shp_d = NULL)dgev_bhm(data, chains = 4, iter = 2000, cores = 4, shp_d = NULL)
data |
A list containing processed station data (output from |
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. |
A list containing MCMC samples (pars), original data, and metadata.
Pre-computed BHM fit using the shape parameter hierarchical with respect to duration.
fit_xi_dfit_xi_d
An object of class list of length 10.
Pre-computed BHM fit using the shape parameter hierarchical with respect to space.
fit_xi_jfit_xi_j
An object of class list of length 10.
Calculates the CDF for the Generalized Extreme Value distribution using highly optimized base R logical subsetting.
gev_cdf(x, mu, sigma, xi)gev_cdf(x, mu, sigma, xi)
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
gev_mat(p, mu_mat, sigma_mat, xi_vec, xi_dim)gev_mat(p, mu_mat, sigma_mat, xi_vec, xi_dim)
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
idf_plot(fit, j = NULL, rp, alpha = 0.05)idf_plot(fit, j = NULL, rp, alpha = 0.05)
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. |
Generates a histogram of the posterior predictive distribution for a specific statistic and compares it against the observed (empirical) value.
post_pred_plot(fit, stat, d, j)post_pred_plot(fit, stat, d, j)
fit |
List. Output from |
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. |
Calculates the posterior predictive p-value for a given statistic. A value near 0.5 indicates a good model fit.
post_pred_pval(fit, stat, d, j)post_pred_pval(fit, stat, d, j)
fit |
List. Output from |
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. |
Numeric. The calculated PPP.
Creates a P-P plot comparing empirical probabilities to theoretical d-GEV probabilities with credible intervals using base R.
pp_plot(fit, j, alpha = 0.05)pp_plot(fit, j, alpha = 0.05)
fit |
List. Output from |
j |
Integer. Index of the station to plot. |
alpha |
Numeric. Significance level for credible intervals (default 0.05). |
Calculates and plots the relationship between return periods and precipitation intensity (return levels) with Bayesian credible intervals.
return_level_plot(fit, max_rp = 100, j, d, alpha = 0.05)return_level_plot(fit, max_rp = 100, j, d, alpha = 0.05)
fit |
List. Output from |
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). |
A dataset containing annual maxima for 25 stations. Filtered using amp median.
UK_dataUK_data
A list with elements:
A list of matrices duration dependent annual maxima for each station. year x duration
Annual mean precipitation for each station.
Latitude and longitude for each station.
station ID for each station.
Durations corresponding to the columns of the y matrices.
A dataset containing annual maxima for 47 stations. The full list of processed data.
UK_data_fullUK_data_full
A list with elements:
A list of matrices duration dependent annual maxima for each station. year x duration
Annual mean precipitation for each station.
Latitude and longitude for each station.
station ID for each station.
Durations corresponding to the columns of the y matrices.