Skip to contents

Fit a univariate distribution to a sample with a Bayesian MCMC analysis and return the frequency (quantile) curve, the posterior mean and credible band, and goodness-of-fit scalars. Wraps the shared C++ UnivariateAnalysis ported from USACE-RMC RMC.BestFit.

Usage

univariate_analysis(
  data,
  distribution,
  sampler = "DEMCz",
  iterations = 3000L,
  output_length = 10000L,
  credible_level = 0.9,
  seed = 12345L,
  exceedance_probabilities = NULL,
  thinning_interval = -1L
)

Arguments

data

numeric vector of observations.

distribution

distribution family name (e.g. "Normal", "GeneralizedExtremeValue", "LogPearsonTypeIII") – any name the core distribution factory accepts.

sampler

MCMC sampler: "DEMCz" (default), "DEMCzs", "ARWMH", or "NUTS".

iterations

number of post-warmup MCMC iterations.

output_length

number of posterior samples used to build the credible band.

credible_level

credible-interval width (e.g. 0.90 for a 90% band).

seed

PRNG seed for the sampler (fixed for reproducibility).

exceedance_probabilities

optional numeric vector of exceedance probabilities at which to tabulate the curve; when NULL, the 25 standard default ordinates are used.

thinning_interval

MCMC thinning interval; -1 (default) keeps the sampler's own default.

Value

A named list: parameters (point-estimate distribution parameters), mode_curve, mean_curve, lower_ci, upper_ci (one value per exceedance ordinate), and the scalars aic, bic, dic, rmse.

Details

Because both the R and Python packages call the identical compiled core with a bit-exact Mersenne Twister, a seeded call returns identical numbers in either language.

The MCMC warmup (burn-in) length is set automatically to max(50, iterations / 2); it is not a user parameter.

Examples

peaks <- c(12500, 15300, 8900, 22100, 18700, 14200, 9800, 28500, 17400, 11600)
fit <- univariate_analysis(peaks, "Normal", sampler = "DEMCzs",
                           iterations = 100, output_length = 400, seed = 12345)
fit$parameters
#> [1] 15781.366  6525.262