gigFit function

Fit the Generalized Inverse Gausssian Distribution to Data

Fit the Generalized Inverse Gausssian Distribution to Data

Fits a generalized inverse Gaussian distribution to data. Displays the histogram, log-histogram (both with fitted densities), Q-Q plot and P-P plot for the fit which has the maximum likelihood.

gigFit(x, freq = NULL, paramStart = NULL, startMethod = c("Nelder-Mead","BFGS"), startValues = c("LM","GammaIG","MoM","Symb","US"), method = c("Nelder-Mead","BFGS","nlm"), stand = TRUE, plots = FALSE, printOut = FALSE, controlBFGS = list(maxit = 200), controlNM = list(maxit = 1000), maxitNLM = 1500, ...) ## S3 method for class 'gigFit' print(x, digits = max(3, getOption("digits") - 3), ...) ## S3 method for class 'gigFit' plot(x, which = 1:4, plotTitles = paste(c("Histogram of ", "Log-Histogram of ", "Q-Q Plot of ", "P-P Plot of "), x$obsName, sep = ""), ask = prod(par("mfcol")) < length(which) & dev.interactive(), ...) ## S3 method for class 'gigFit' coef(object, ...) ## S3 method for class 'gigFit' vcov(object, ...)

Arguments

  • x: Data vector for gigFit. Object of class "gigFit" for print.gigFit and plot.gigFit.

  • freq: A vector of weights with length equal to length(x).

  • paramStart: A user specified starting parameter vector param taking the form c(chi, psi, lambda).

  • startMethod: Method used by gigFitStartMoM in calls to optim.

  • startValues: Code giving the method of determining starting values for finding the maximum likelihood estimate of param.

  • method: Different optimisation methods to consider. See Details .

  • stand: Logical. If TRUE, the data is first standardized by dividing by the sample standard deviation.

  • plots: Logical. If FALSE suppresses printing of the histogram, log-histogram, Q-Q plot and P-P plot.

  • printOut: Logical. If FALSE suppresses printing of results of fitting.

  • controlBFGS: A list of control parameters for optim when using the "BFGS" optimisation.

  • controlNM: A list of control parameters for optim

    when using the "Nelder-Mead" optimisation.

  • maxitNLM: A positive integer specifying the maximum number of iterations when using the "nlm" optimisation.

  • digits: Desired number of digits when the object is printed.

  • which: If a subset of the plots is required, specify a subset of the numbers 1:4.

  • plotTitles: Titles to appear above the plots.

  • ask: Logical. If TRUE, the user is asked before each plot, see par(ask = .).

  • ...: Passes arguments to optim, par, hist, logHist, qqgig and ppgig.

  • object: Object of class "gigFit" for coef.gigFit

    and for vcov.gigFit.

Details

Possible values of the argument startValues are the following:

  • "LM": Based on fitting linear models to the upper tails of the data x and the inverse of the data 1/x.
  • "GammaIG": Based on fitting gamma and inverse gamma distributions.
  • "MoM": Method of moments.
  • "Symb": Not yet implemented.
  • "US": User-supplied.

If startValues = "US" then a value must be supplied for paramStart.

For the details concerning the use of paramStart, startMethod, and startValues, see gigFitStart.

The three optimisation methods currently available are:

  • "BFGS": Uses the quasi-Newton method "BFGS" as documented in optim.
  • "Nelder-Mead": Uses an implementation of the Nelder and Mead method as documented in optim.
  • "nlm": Uses the nlm function in R.

For details of how to pass control information for optimisation using optim and nlm, see optim and nlm.

When method = "nlm" is used, warnings may be produced. These do not appear to be a problem.

Returns

gigFit returns a list with components: - param: A vector giving the maximum likelihood estimate of param, as c(chi, psi, lambda).

  • maxLik: The value of the maximised log-likelihood.

  • method: Optimisation method used.

  • conv: Convergence code. See the relevant documentation (either optim or nlm) for details on convergence.

  • iter: Number of iterations of optimisation routine.

  • obs: The data used to fit the generalized inverse Gaussian distribution.

  • obsName: A character string with the actual x argument name.

  • paramStart: Starting value of param returned by call to gigFitStart.

  • svName: Descriptive name for the method finding start values.

  • startValues: Acronym for the method of finding start values.

  • breaks: The cell boundaries found by a call to hist.

  • midpoints: The cell midpoints found by a call to hist.

  • empDens: The estimated density found by a call to hist.

References

, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.

Author(s)

David Scott d.scott@auckland.ac.nz , David Cusack

See Also

optim, par, hist, logHist (pkg list("DistributionUtils")), qqgig, ppgig, and gigFitStart.

Examples

param <- c(1, 1, 1) dataVector <- rgig(500, param = param) ## See how well gigFit works gigFit(dataVector) ##gigFit(dataVector, plots = TRUE) ## See how well gigFit works in the limiting cases ## Gamma case dataVector2 <- rgamma(500, shape = 1, rate = 1) gigFit(dataVector2) ## Inverse gamma require(actuar) dataVector3 <- rinvgamma(500, shape = 1, rate = 1) gigFit(dataVector3) ## Use nlm instead of default gigFit(dataVector, method = "nlm")