fitMixDist {usefr} | R Documentation |
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.
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, ...)
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 |
maxiter |
positive integer. Termination occurs when the number of iterations reaches maxiter. Default value: 1024. |
prior |
Same as in |
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 |
eps, tol |
Arguments to pass to |
usepoints |
Integer. Computation by function
|
seed |
Seed for random number generation. |
dens |
Logic. Whether to use fit the 'PDF' or 'CDF'. Default is TRUE. |
kmean |
Logic. Whether to use |
verbose |
if TRUE, prints the function log to stdout and a progress bar |
... |
Further arguments to pass to other functions like
|
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
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 |
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 [1]. In
addition, Stein's formula for adjusted R squared (rho) was used as an
estimator of the average cross-validation predictive power [1]. Notice
that the parameter values must be given in way understandable
by the set of functions mixtdistr
(see the example below)
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.
Robersy Sanchez (https://genomaths.com).
1. Stevens JP. Applied Multivariate Statistics for the Social Sciences. Fifth Edit. Routledge Academic; 2009.
fitdistr
, fitCDF
,
mixtdistr
, and mcgoftest
.
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)