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 gigFit
print(x,
digits = max(3, getOption("digits") - 3), ...)
# S3 method for 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 gigFit
coef(object, ...)
# S3 method for gigFit
vcov(object, ...)
Data vector for gigFit
. Object of class
"gigFit"
for print.gigFit
and plot.gigFit
.
A vector of weights with length equal to length(x)
.
A user specified starting parameter vector
param
taking the form c(chi, psi, lambda)
.
Method used by gigFitStartMoM
in calls to
optim
.
Code giving the method of determining starting
values for finding the maximum likelihood estimate of param
.
Different optimisation methods to consider. See Details.
Logical. If TRUE
, the data is first standardized
by dividing by the sample standard deviation.
Logical. If FALSE
suppresses printing of the
histogram, log-histogram, Q-Q plot and P-P plot.
Logical. If FALSE
suppresses printing of
results of fitting.
A list of control parameters for optim
when using
the "BFGS"
optimisation.
A list of control parameters for optim
when using the "Nelder-Mead"
optimisation.
A positive integer specifying the maximum number of
iterations when using the "nlm"
optimisation.
Desired number of digits when the object is printed.
If a subset of the plots is required, specify a subset of
the numbers 1:4
.
Titles to appear above the plots.
Logical. If TRUE
, the user is asked before
each plot, see par(ask = .)
.
Passes arguments to optim
, par
,
hist
, logHist
, qqgig
and ppgig
.
Object of class "gigFit"
for coef.gigFit
and for vcov.gigFit
.
gigFit
returns a list with components:
A vector giving the maximum likelihood estimate of
param, as c(chi, psi, lambda)
.
The value of the maximised log-likelihood.
Optimisation method used.
Convergence code. See the relevant documentation (either
optim
or nlm
) for details on
convergence.
Number of iterations of optimisation routine.
The data used to fit the generalized inverse Gaussian distribution.
A character string with the actual x
argument
name.
Starting value of param
returned by call to
gigFitStart
.
Descriptive name for the method finding start values.
Acronym for the method of finding start values.
The cell boundaries found by a call to
hist
.
The cell midpoints found by a call to
hist
.
The estimated density found by a call to
hist
.
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.
J<U+001B29E5>nsen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
optim
, par
,
hist
, logHist
(pkg DistributionUtils),
qqgig
, ppgig
, and gigFitStart
.
# NOT RUN {
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")
# }
Run the code above in your browser using DataLab