Skip to contents

Fit a finite mixture of 1-3 component distributions to a sample with a Bayesian MCMC analysis and return the frequency (quantile) curve, credible band, and goodness-of-fit scalars. Wraps the shared C++ MixtureAnalysis.

Usage

mixture_analysis(
  data,
  families,
  zero_inflated = FALSE,
  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.

families

character vector of component distribution family names (e.g. c("Normal", "Normal")).

zero_inflated

logical; add a zero-inflation component (default FALSE).

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, mode_curve, mean_curve, lower_ci, upper_ci, and the scalars aic, bic, dic, rmse.

Examples

x <- c(520, 580, 610, 700, 760, 850, 950, 5000, 5400, 5800, 6300, 6800)
fit <- mixture_analysis(x, c("Normal", "Normal"), iterations = 100, output_length = 200,
                        seed = 12345, thinning_interval = 1)
fit$aic
#> [1] 316.0609