Type: Package
Title: Fit Two-Component Normal and Lognormal Mixture Models
Version: 0.1.1
Description: Fits, bootstraps, and evaluates two-component normal and lognormal mixture models. Includes diagnostic plots and statistical evaluation of mixture model fits using differential evolution optimization.
Imports: DEoptim (≥ 2.0.0), pbapply (≥ 1.0.0), parallelly (≥ 1.0.0)
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-09-21 18:17:46 UTC; mac
Author: Farrokh Habibzadeh [aut, cre]
Maintainer: Farrokh Habibzadeh <farrokh.habibzadeh@gmail.com>
Repository: CRAN
Date/Publication: 2025-09-27 08:40:08 UTC

Internal function for multiple DEoptim runs

Description

Internal function for multiple DEoptim runs

Usage

.fit_mix2_core(
  x,
  family = c("lognormal", "normal"),
  lower = NULL,
  upper = NULL,
  NP = 100,
  itermax = 10000,
  reltol = 5e-06,
  steptol = 50,
  F = 0.8,
  CR = 0.9,
  strategy = 2,
  parallelType = 0,
  packages = c("stats"),
  parVar = NULL,
  n_runs = 20,
  quiet = 2,
  par_init = NULL,
  pgtol = 1e-08
)

Internal function for multiple DEoptim runs

Description

Internal function for multiple DEoptim runs

Usage

.run_demulti(
  loglik_fn,
  x,
  lower,
  upper,
  NP = 100,
  itermax = 10000,
  reltol = 5e-06,
  steptol = 50,
  F = 0.8,
  CR = 0.9,
  strategy = 2,
  parallelType = 0,
  packages = c("stats"),
  parVar = NULL,
  n_runs = 20,
  quiet = 2
)

Bootstrap mixture parameters

Description

Bootstrap mixture parameters

Usage

bootstrap_mix2(
  fit = NULL,
  x = NULL,
  par = NULL,
  family = NULL,
  B = 1000,
  parametric = TRUE,
  boot_size = NULL,
  parallelType = 0,
  quiet = 2,
  ci_level = 0.95
)

Arguments

fit

fitted object from fit_lognorm2 or fit_norm2

x

numeric vector (if fit not provided)

par

numeric vector of parameters (if fit not provided)

family

"lognormal" or "normal" (if fit not provided)

B

number of bootstrap replicates

parametric

logical, parametric bootstrap if TRUE

boot_size

size or fraction (if between 0 and 1) of bootstrap sample

parallelType

integer for DEoptim/pbapply parallelism

quiet

0/1/2 for verbosity

ci_level

confidence level

Value

list with cleaned bootstrap estimates, central tendency, and CI


Default bounds for lognormal mixture

Description

Default bounds for lognormal mixture

Usage

default_bounds_lognorm2(x)

Default bounds for normal mixture

Description

Default bounds for normal mixture

Usage

default_bounds_norm2(x)

Evaluate initial parameter values for mixture fitting

Description

Evaluate initial parameter values for mixture fitting

Usage

evaluate_init(
  par_init,
  x,
  family = c("lognormal", "normal"),
  lower = NULL,
  upper = NULL,
  pgtol = 1e-08
)

Arguments

par_init

numeric vector of initial parameters

x

numeric vector of data

family

"lognormal" or "normal"

lower

numeric vector of lower bounds

upper

numeric vector of upper bounds

pgtol

numeric, gradient tolerance for optim

Value

list with success flag, optimized parameters, log-likelihood, and convergence


Fit 2-component lognormal mixture

Description

Fit 2-component lognormal mixture

Usage

fit_lognorm2(x, ...)

Arguments

x

numeric vector of data to fit

...

additional arguments passed to .fit_mix2_core

Value

list with fitted parameters and metrics


Fit 2-component normal mixture

Description

Fit 2-component normal mixture

Usage

fit_norm2(x, ...)

Arguments

x

numeric vector of data to fit

...

additional arguments passed to .fit_mix2_core

Value

list with fitted parameters and metrics


Log-likelihood for 2-component lognormal mixture

Description

Log-likelihood for 2-component lognormal mixture

Usage

loglik_lognorm(params, x)

Log-likelihood for 2-component normal mixture

Description

Log-likelihood for 2-component normal mixture

Usage

loglik_norm(params, x)

Reorder mixture components to prevent label switching

Description

Reorder mixture components to prevent label switching

Usage

order_components(par)

Preliminary diagnostic plots

Description

Preliminary diagnostic plots

Usage

prelim_plots(
  x,
  which = c("hist"),
  hist_bins = 60,
  col_hist = "grey85",
  col_density = "darkorange",
  col_qq = "grey60",
  col_line = "darkorange"
)

Arguments

x

numeric vector

which

character vector: "hist", "qq", "pp", "logqq"

hist_bins

number of bins for histogram

col_hist

color for histogram

col_density

color for density line in histogram

col_qq

color for qq points

col_line

color for lines in "qq", "pp", "logqq" plots

Value

no return value, called for side effects (generating plots)


Select best mixture model (lognormal or normal) based on BIC

Description

Select best mixture model (lognormal or normal) based on BIC

Usage

select_best_mixture(x, n_runs = 1, NP = 50, itermax = 10000, quiet = 2)

Arguments

x

numeric vector

n_runs

number of DEoptim runs

NP

population size for DEoptim

itermax

maximum iterations

quiet

verbosity

Value

list with best fit, all fits, and BICs