dfitverse: Density, CDF, Quantile, and Random Sampling for a Fitted...

View source: R/probability_tools.R

dfitverseR Documentation

Density, CDF, Quantile, and Random Sampling for a Fitted Distribution

Description

Convenience functions that evaluate the probability density function (PDF), cumulative distribution function (CDF), quantile function (inverse CDF), and random-number generator for the best-fit distribution stored in a fitverse object.

These follow the standard R d/p/q/r naming convention and delegate to the underlying d*, p*, q*, and r* functions for the best-fit distribution.

Usage

dfitverse(x,   fit, log = FALSE)
pfitverse(q,   fit, lower.tail = TRUE, log.p = FALSE)
qfitverse(p,   fit, lower.tail = TRUE, log.p = FALSE)
rfitverse(n,   fit)

Arguments

x

Numeric vector of quantiles at which to evaluate the density.

q

Numeric vector of quantiles at which to evaluate the CDF.

p

Numeric vector of probabilities p \in (0, 1).

n

Integer: number of random samples to generate.

fit

An object of class "fitverse" as returned by fitverse().

log, log.p

Logical: if TRUE, return (or accept) log-scale values. Default FALSE.

lower.tail

Logical: if TRUE (default), return P(X \le q); if FALSE, return P(X > q).

Details

The correct d/p/q/r functions are resolved via .lookup_dpqr(), which follows a two-step priority:

  1. Internal closed-form implementations (highest priority): GEV, Gumbel, GPD, Pearson III, Log-Pearson III, and GLO all use FitVerse's own vectorised implementations registered in .FITVERSE_DPQR_OVERRIDES. This avoids any package-version signature issues with evd and provides full support for the new hydrological distributions that have no dedicated CRAN d/p/q/r package.

  2. Package namespace lookup: For all other distributions, stats functions are found via match.fun(); Imports/Suggests packages (actuar, sn, mc2d) are resolved via getExportedValue().

The estimated parameters are extracted from fit$best_fit$params and passed as named arguments to the underlying function. This is equivalent to calling, for example, dgamma(x, shape = fit$best_fit$params["shape"], rate = fit$best_fit$params["rate"]).

Value

dfitverse()

Numeric vector of density values.

pfitverse()

Numeric vector of probabilities.

qfitverse()

Numeric vector of quantiles.

rfitverse()

Numeric vector of random samples.

Author(s)

Karuna G. Reddy karuna.reddy@auckland.ac.nz
M. G. M. Khan mgm.khan@usp.ac.fj

See Also

return_level for T-year return levels.
fitverse for the fitting step.

Examples

set.seed(42)
x <- rgamma(300, shape = 2, rate = 0.5)
fit <- fitverse(x, dists = "gamma", plot = FALSE, verbose = FALSE)

# Density at x = 2
dfitverse(2, fit)

# Probability that X <= 5
pfitverse(5, fit)

# 90th percentile
qfitverse(0.90, fit)

# Generate 10 random samples
rfitverse(10, fit)

FitVerse documentation built on Dec. 1, 2026, 1:07 a.m.