This function is not intended to be called directly but is internally called in
fitdist
and bootdist
when used with the maximum likelihood method
and fitdistcens
and bootdistcens
.
It is assumed that the distr
argument specifies the distribution by the
probability density function and the cumulative distribution function (d, p).
The quantile function and the random generator function (q, r) may be
needed by other function such as mmedist
, qmedist
, mgedist
,
fitdist
,fitdistcens
, bootdistcens
and bootdist
.
For the following named distributions, reasonable starting values will
be computed if start
is omitted (i.e. NULL
) : "norm"
, "lnorm"
,
"exp"
and "pois"
, "cauchy"
, "gamma"
, "logis"
,
"nbinom"
(parametrized by mu and size), "geom"
, "beta"
, "weibull"
from the stats
package;
"invgamma"
, "llogis"
, "invweibull"
, "pareto1"
, "pareto"
,
"lgamma"
, "trgamma"
, "invtrgamma"
from the actuar
package.
Note that these starting values may not be good enough if the fit is poor.
The function uses a closed-form formula to fit the uniform distribution.
If start
is a list, then it should be a named list with the same names as in
the d,p,q,r functions of the chosen distribution.
If start
is a function of data, then the function should return a named list with the same names as in
the d,p,q,r functions of the chosen distribution.
The mledist
function allows user to set a fixed values for some parameters.
As for start
, if fix.arg
is a list, then it should be a named list with the same names as in
the d,p,q,r functions of the chosen distribution.
If fix.arg
is a function of data, then the function should return a named list with the
same names as in the d,p,q,r functions of the chosen distribution.
When custom.optim=NULL
(the default), maximum likelihood estimations
of the distribution parameters are computed with the R base optim
or constrOptim
.
If no finite bounds (lower=-Inf
and upper=Inf
) are supplied,
optim
is used with the method specified by optim.method
.
Note that optim.method="default"
means optim.method="Nelder-Mead"
for distributions
with at least two parameters and optim.method="BFGS"
for distributions with only one parameter.
If finite bounds are supplied (among lower
and upper
) and gradient != NULL
,
constrOptim
is used.
If finite bounds are supplied (among lower
and upper
) and gradient == NULL
,
constrOptim
is used when optim.method="Nelder-Mead"
;
optim
is used when optim.method="L-BFGS-B"
or "Brent"
;
in other case, an error is raised (same behavior as constrOptim
).
When errors are raised by optim
, it's a good idea to start by adding traces during
the optimization process by adding control=list(trace=1, REPORT=1)
.
If custom.optim
is not NULL
, then the user-supplied function is used
instead of the R base optim
. The custom.optim
must have (at least)
the following arguments
fn
for the function to be optimized, par
for the initialized parameters.
Internally the function to be optimized will also have other arguments,
such as obs
with observations and ddistname
with distribution name for non censored data (Beware of potential conflicts with optional
arguments of custom.optim
). It is assumed that custom.optim
should carry
out a MINIMIZATION.
Finally, it should return at least the following components par
for the estimate,
convergence
for the convergence code, value
for fn(par)
,
hessian
, counts
for the number of calls (function and gradient)
and message
(default to NULL
) for the error message
when custom.optim
raises an error,
see the returned value of optim
.
See examples in fitdist
and fitdistcens
.
Optionally, a vector of weights
can be used in the fitting process.
By default (when weigths=NULL
), ordinary MLE is carried out, otherwise
the specified weights are used to balance the log-likelihood contributions.
It is not yet possible to take into account weights in functions plotdist
,
plotdistcens
, plot.fitdist
, plot.fitdistcens
, cdfcomp
,
cdfcompcens
, denscomp
, ppcomp
, qqcomp
, gofstat
,
descdist
, bootdist
, bootdistcens
and mgedist
.
(developments planned in the future).
NB: if your data values are particularly small or large, a scaling may be needed
before the optimization process. See Example (7).