Learn R Programming

dendrometry (version 0.0.4)

fit_dist: Unified Parameter Estimation for Probability Distributions

Description

Estimates parameters of probability distributions using various methods: Maximum Likelihood (MLE), Maximum Product Spacing (MPS), or Method of Moments (MOM).

Usage

fit_dist(
  data,
  dist = "normal",
  method = "mle",
  start = NULL,
  lower = NULL,
  upper = NULL,
  optim_method = "Nelder-Mead",
  custom_functions = NULL,
  tol_spacing = 1e-16,
  tol_param = 1e-06,
  ties_method = "cheng_amin",
  ...
)

Value

A list with class "fit_dist" containing:

estimate

Named vector of parameter estimates

vcov

Variance-covariance matrix (for mps/mle)

se

Standard errors (for mps/mle)

loglik

Log-likelihood value

aic

Akaike Information Criterion

bic

Bayesian Information Criterion

objective

Maximum value of objective function (logspacing for mps, loglik for mle)

ks_statistic

Kolmogorov-Smirnov test statistic

ks_pvalue

Kolmogorov-Smirnov test p-value

convergence

Convergence code from optim (0 indicates success)

message

Convergence message from optim

data

Original data (sorted)

dist

Distribution name

method

Estimation method used

n

Sample size

k

Number of parameters

tol_spacing

Tolerance used for spacings/densities

tol_param

Tolerance used for parameter bounds

ties_method

Ties correction method (for MPS only)

Arguments

data

numeric vector of observed data.

dist

character string specifying the distribution. Options include: "normal", "exponential", "gamma", "weibull", "weibull3", "lognormal", "lognormal3", "beta", or "custom".

method

character string specifying estimation method. Options: "mle" (Maximum Likelihood - default), "mps" (Maximum Product Spacing), "mom" (Method of Moments).

start

named list or numeric vector of initial parameter values. Required for "custom" distributions with "mps" or "mle" methods.

lower

named list or numeric vector of lower bounds for parameters.

upper

named list or numeric vector of upper bounds for parameters.

optim_method

optimization method passed to optim. Default is "Nelder-Mead".

custom_functions

list containing custom distribution functions (for dist="custom"):

  • pdf: probability density function f(x, params) (for MLE and ties correction)

  • cdf: cumulative distribution function F(x, params) (for MPS)

  • param_names: character vector of parameter names

  • start_fn: function to compute starting values (optional)

tol_spacing

numeric tolerance for spacings/densities to avoid log(0). Default is 1e-16.

tol_param

numeric tolerance for parameter lower bounds. Default is 1e-6.

ties_method

character string for handling ties in MPS. Options: "cheng_amin" (default - Cheng & Amin 1983), "none", "cheng_stephens" (Cheng & Stephens 1989). Only applicable when method = "mps".

...

Additional arguments passed to optim.

References

Cheng, R. C. H., & Amin, N. A. K. (1983). Estimating parameters in continuous univariate distributions with a shifted origin. Journal of the Royal Statistical Society: Series B, 45(3), 394-403.

Cheng, R. C. H., & Stephens, M. A. (1989). A goodness-of-fit test using Moran's statistic with estimated parameters. Biometrika, 76(2), 385-392.

Examples

Run this code
# MLE estimation (default)
set.seed(123)
x <- rweibull(100, shape = 2.5, scale = 1.5)
fit1 <- fit_dist(x, dist = "weibull")
print(fit1)

# MPS estimation with Cheng-Amin ties correction
fit2 <- fit_dist(x, dist = "weibull", method = "mps")

# L-Moments estimation (under development)
# fit3 <- fit_dist(x, dist = "weibull", method = "lm")

# Method of Moments
fit4 <- fit_dist(x, dist = "weibull", method = "mom")

# Compare fits
cat("AIC - MLE:", fit1$aic, "MPS:", fit2$aic, "\n")

Run the code above in your browser using DataLab