fitMixDist {usefr} R Documentation

Nonlinear fit of Mixture distributions

Description

This function performs the nonlinear fit of mixture distributions exploiting a firth approach on parameterized finite Gaussian mixture models obtained through the function Mclust from package mclust.

Usage

fitMixDist(X, args = list(norm = c(mean = NA, sd = NA), weibull = c(shape
= NA, scale = NA)), npoints = 100, maxiter = 1024,
prior = priorControl(), ftol = 1e-14, ptol = 1e-14,
maxfev = 1e+05, equalPro = FALSE, eps, tol, usepoints, seed = 123,
dens = TRUE, kmean = FALSE, verbose = TRUE, ...)

Arguments

 X numerical vector npoints number of points used in the fit of the density function or NULL. These are used as histogram break points to estimate the empirical density values. If npoints = NULL and dens = TRUE, then. Kernel Density Estimation function density from stats package is used to estimate the empirical density. Default value is 100. maxiter positive integer. Termination occurs when the number of iterations reaches maxiter. Default value: 1024. prior Same as in Mclust function. ftol non-negative numeric. Termination occurs when both the actual and predicted relative reductions in the sum of squares are at most ftol. Therefore, ftol measures the relative error desired in the sum of squares. Default value: 1e-12 ptol non-negative numeric. Termination occurs when the relative error between two consecutive iterates is at most ptol. Therefore, ptol measures the relative error desired in the approximate solution. Default value: 1e-12. maxfev Integer; termination occurs when the number of calls to fn has reached maxfev. Note that nls.lm sets the value of maxfev to 100*(length(par) + 1) if maxfev = integer(), where par is the list or vector of parameters to be optimized. equalPro An argument to pass to emControl function. Logical variable indicating whether or not the mixing proportions are equal in the model. Default: equalPro = FALSE. eps, tol Arguments to pass to emControl function. usepoints Integer. Computation by function Mclust could take long time when the sample size is about >= 10000. This number can be used to extract a random sample of size 'usepoints' and to do the estimation with it. seed Seed for random number generation. dens Logic. Whether to use fit the 'PDF' or 'CDF'. Default is TRUE. kmean Logic. Whether to use kmeans algorithm to perform the estimation in place of Mclust. Deafult is FALSE. verbose if TRUE, prints the function log to stdout and a progress bar ... Further arguments to pass to other functions like Mclust and density. arg A list of named vectors with the corresponding named distribution parameters values. The names of the vector of parameters and the parameter names must correspond to defined functions. For example, if one of the involved distributions is the gamma density (see GammaDist), then the corresponding vector of parameters must be gamma = c(shape = 'some value', scale = 'some value'). For the following distributions, the arguments can be provided with NULL values: "norm" (Wikipedia) "halfnorm" (Wikipedia). "gnorm" (Wikipedia) "gamma" (Wikipedia) "beta" (Wikipedia) "laplace" (Wikipedia) "weibull" (Wikipedia) "rayleigh" (Wikipedia) "exp" (Wikipedia) Notice that the distribution given names correspond to the root-names as given for R functions. For example, 'gamma' is the root-name for functions GammaDist. See example, for more details.

Details

The approch tries to fit the proposed mixture distributions using a modification of Levenberg-Marquardt algorithm implemented in function nls.lm from minpack.lm package that is used to perform the nonlinear fit. Cross-validations for the nonlinear regressions (R.Cross.val) are performed as described in reference . In addition, Stein's formula for adjusted R squared (rho) was used as an estimator of the average cross-validation predictive power . Notice that the parameter values must be given in way understandable by the set of functions mixtdistr (see the example below)

Value

A list with the model table with coefficients and goodness-of-fit results, the fitted model returned by function nls.lm, and a named list of fitted arguments.

Author(s)

Robersy Sanchez (https://genomaths.com).

References

1. Stevens JP. Applied Multivariate Statistics for the Social Sciences. Fifth Edit. Routledge Academic; 2009.

fitdistr, fitCDF, mixtdistr, and mcgoftest.

Examples

set.seed(123) # set a seed for random generation
## ========= A mixture of three distributions =========
phi = c(3/10, 7/10) #' Mixture proportions
## ---------------------------------------------------------

## === Named vector of the corresponding distribution function parameters
## must be provided
args <- list(gamma = c(shape = 2, scale = 0.1), weibull = c(shape = 3, scale = 0.5))
## ------------------------------------------------------------

## ===== Sampling from the specified mixture distribution ====
X <- rmixtdistr(n = 1e5, phi = phi , arg = args)
## ------------------------------------------------------------

## ===== Nonlinear fit of the specified mixture distribution ====
FIT <- fitMixDist(X, args = list(gamma = c(shape = NA, scale = NA),
weibull = c(shape = NA, scale = NA)),
npoints = 200, usepoints = 1000)

## === The graphics for the simulated dataset and the corresponding theoretical
## mixture distribution
par(bg = "gray98",  mar = c(3, 4, 2, 1) )
hist(X, 90, freq = FALSE, las = 1, family = "serif", col = rgb(0, 0, 1, 0.),
border = "deepskyblue", main = "Histogram of Mixture Distribution")
x1 <- seq(-4, 10, by = 0.001)
lines(x1, dmixtdistr(x1, phi = phi, arg = args), col = "red")
lines(x1, dmixtdistr(x1, phi = FIT\$phi, arg = FIT\$args), col = "blue")
legend(1, 1.5, legend=c("Theoretical Mixture PDF", "Estimated Mixture PDF"),
col=c("red", "blue"), lty=1, cex=0.8)

[Package usefr version 0.1.0 ]