Learn R Programming

fitdistrplus (version 0.3-4)

mmedist: Matching moment fit of univariate distributions

Description

Fit of univariate distributions by matching moments (raw or centered) for non censored data.

Usage

mmedist(data, distr, order, memp, start=NULL, fix.arg=NULL,
    optim.method="default", lower=-Inf, upper=Inf, custom.optim=NULL, ...)

Arguments

data
A numeric vector for non censored data.
distr
A character string "name" naming a distribution (see 'details').
order
A numeric vector for the moment order(s). The length of this vector must be equal to the number of parameters to estimate.
memp
A function implementing empirical moments, raw or centered but has to be consistent with distr argument. This function must have two arguments : as a first one the numeric vector of the data and as a second the order of the moment
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).
fix.arg
An optional named list giving the values of parameters of the named distribution that must kept fixed rather than estimated.
optim.method
"default" 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 optimization .
...
further arguments passed to the optim or custom.optim function.

Value

  • mmedist returns a list with following components,
  • estimatethe parameter estimates.
  • convergence(if appropriate) 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.
  • loglikthe log-likelihood.
  • hessian(if appropriate) 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(if appropriate) the name of the optimization function.
  • memp(if appropriate) the empirical moment function.
  • orderthe order of the moment(s) matched.
  • methodeither "closed formula" or the name of the optimization method.

Details

The argument distr can be one of the base R distributions: "norm", "lnorm", "exp" and "pois", "gamma", "logis", "nbinom" , "geom", "beta" and "unif". In that case, no other arguments than data and distr are required, because the estimate is computed by a closed formula. For distributions characterized by one parameter ("geom", "pois" and "exp"), this parameter is simply estimated by matching theoretical and observed means, and for distributions characterized by two parameters, these parameters are estimated by matching theoretical and observed means and variances (Vose, 2000). The argument distr can also be the distribution name as long as a corresponding mdistr function exists, e.g. "pareto" if "mpareto" exists. In that case arguments arguments order and memp have to be supplied in order to carry out the matching numerically, by minimization of the sum of squared differences between observed and theoretical moments. Optionnally other aguments may be supplied to control optimization (see the 'details' section of mledist for details about arguments for the control of optimization). This function is not intended to be called directly but is internally called in fitdist and bootdist when used with the matching moments method.

References

Vose D (2000) Risk analysis, a quantitative guide. John Wiley & Sons Ltd, Chischester, England, pp. 99-143. Evans M, Hastings N and Peacock B (2000) Statistical distributions. John Wiley and Sons Inc.

See Also

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

Examples

Run this code
# (1) basic fit of a normal distribution with moment matching 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)
mmedist(x1,"norm")

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

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



# (3) 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)
mmedist(x3,"beta")


# (4) fit a Pareto distribution
#

require(actuar)
    #simulate a sample
    x4 <- rpareto(1000, 6, 2)

    #empirical raw moment
    memp <- function(x, order)
        ifelse(order == 1, mean(x), sum(x^order)/length(x))


    #fit
    mmedist(x4, "pareto", order=c(1, 2), memp="memp", start=c(10, 10), 
    lower=1, upper=Inf)

Run the code above in your browser using DataLab