mledist {fitdistrplus}R Documentation

Maximum likelihood fitting of univariate distributions

Description

Fits a univariate distribution by maximum likelihood.

Usage

mledist(data, distr, start, optim.method="default", lower=-Inf, upper=Inf, custom.optim=NULL, ...)

Arguments

data A numeric vector for non censored data or a dataframe of two columns respectively named left and right, describing each observed value as an interval for censored data. In that case the left column contains either NA for left censored observations, the left bound of the interval for interval censored observations, or the observed value for non-censored observations. The right column contains either NA for right censored observations, the right bound of the interval for interval censored observations, or the observed value for non-censored observations.
distr A character string "name" naming a distribution (or directly the density function) for which the corresponding density function dname and the corresponding distribution pname must be classically defined.
start A named list giving the initial values of parameters of the named distribution. This argument may be omitted for some distributions for which reasonable starting values are computed (see details).
optim.method "default" (see details) or optimization method to pass to optim.
lower Left bounds on the parameters for the "L-BFGS-B" method (see optim).
upper Right bounds on the parameters for the "L-BFGS-B" method (see optim).
custom.optim a function carrying the MLE optimisation (see details).
... further arguments passed to the optim or custom.optim function.

Details

When custom.optim=NULL (the default), maximum likelihood estimations of the distribution parameters are computed with the R base optim. Direct optimization of the log-likelihood is performed (using optim) by default with the "Nelder-Mead" method for distributions characterized by more than one parameter and the "BFGS" method for distributions characterized by only one parameter, or with the method specified in the argument "optim.method" if not "default". Box-constrainted optimization may be used with the method "L-BFGS-B", using the constraints on parameters specified in arguments lower and upper. If non-trivial bounds are supplied, this method will be automatically selected, with a warning.

For the following named distributions, reasonable starting values will be computed if start is omitted : "norm", "lnorm", "exp" and "pois", "cauchy", "gamma", "logis", "nbinom" (parametrized by mu and size), "geom", "beta" and "weibull". Note that these starting values may not be good enough if the fit is poor. The function is not able to fit a uniform distribution.

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) and hessian. See examples in fitdist and fitdistcens.

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.

Value

mledist returns a list with following components,

estimate the parameter estimates
convergence an integer code for the convergence of optim defined as below or defined by the user in the user-supplied optimization function.
0 indicates successful convergence.
1 indicates that the iteration limit of optim has been reached.
10 indicates degeneracy of the Nealder-Mead simplex.
100 indicates that optim encountered an internal error.
loglik the log-likelihood
hessian a symmetric matrix computed by optim as an estimate of the Hessian at the solution found or computed in the user-supplied optimization function. It is used in fitdist to estimate standard errors.
optim.function the name of the optimization function used for maximum likelihood

Author(s)

Marie-Laure Delignette-Muller ml.delignette@vet-lyon.fr and Christophe Dutang

References

Venables W.N. and Ripley B.D. (2002) Modern applied statistics with S. Springer, New York, pp. 435-446.

See Also

mmedist, fitdist,fitdistcens, optim, bootdistcens and bootdist.

Examples


# (1) basic fit of a normal distribution with maximum likelihood estimation
#

x1<-c(6.4,13.3,4.1,1.3,14.1,10.6,9.9,9.6,15.3,22.1,13.4,
13.2,8.4,6.3,8.9,5.2,10.9,14.4)
mledist(x1,"norm")

# (2) defining your own distribution functions, here for the Gumbel distribution
# for other distributions, see the CRAN task view dedicated to probability distributions

dgumbel<-function(x,a,b) 1/b*exp((a-x)/b)*exp(-exp((a-x)/b))
mledist(x1,"gumbel",start=list(a=10,b=5))

# (3) fit a discrete distribution (Poisson)
#

x2<-c(rep(4,1),rep(2,3),rep(1,7),rep(0,12))
mledist(x2,"pois")
mledist(x2,"nbinom")

# (4) fit a finite-support distribution (beta)
#

x3<-c(0.80,0.72,0.88,0.84,0.38,0.64,0.69,0.48,0.73,0.58,0.81,
0.83,0.71,0.75,0.59)
mledist(x3,"beta")

# (5) fit frequency distributions on USArrests dataset.
#

x4 <- USArrests$Assault
mledist(x4, "pois")
mledist(x4, "nbinom")

# (6) fit a continuous distribution (Gumbel) to censored data.
#

d1<-data.frame(
left=c(1.73,1.51,0.77,1.96,1.96,-1.4,-1.4,NA,-0.11,0.55,0.41,
    2.56,NA,-0.53,0.63,-1.4,-1.4,-1.4,NA,0.13),
right=c(1.73,1.51,0.77,1.96,1.96,0,-0.7,-1.4,-0.11,0.55,0.41,
    2.56,-1.4,-0.53,0.63,0,-0.7,NA,-1.4,0.13))
mledist(d1,"norm")

dgumbel<-function(x,a,b) 1/b*exp((a-x)/b)*exp(-exp((a-x)/b))
pgumbel<-function(q,a,b) exp(-exp((a-q)/b))
mledist(d1,"gumbel",start=list(a=0,b=2),optim.method="Nelder-Mead")


[Package fitdistrplus version 0.1-2 Index]