R: Fit the normal inverse Gaussian Distribution to Data
nigFit
R Documentation
Fit the normal inverse Gaussian Distribution to Data
Description
Fits a normal 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.
Usage
nigFit(x, freq = NULL, paramStart = NULL,
startMethod = c("Nelder-Mead","BFGS"),
startValues = c("FN","Cauchy","MoM","US"),
criterion = "MLE",
method = c("Nelder-Mead","BFGS","nlm",
"L-BFGS-B","nlminb","constrOptim"),
plots = FALSE, printOut = FALSE,
controlBFGS = list(maxit = 200),
controlNM = list(maxit = 1000), maxitNLM = 1500,
controlLBFGSB = list(maxit = 200),
controlNLMINB = list(),
controlCO = list(), ...)
## S3 method for class 'nigFit'
print(x,
digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'nigFit'
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 'nigFit'
coef(object, ...)
## S3 method for class 'nigFit'
vcov(object, ...)
Arguments
x
Data vector for nigFit. Object of class
"nigFit" for print.nigFit and plot.nigFit.
freq
A vector of weights with length equal to length(x).
paramStart
A user specified starting parameter vector param taking
the form c(mu, delta, alpha, beta).
startMethod
Method used by nigFitStart in calls to
optim.
startValues
Code giving the method of determining starting
values for finding the maximum likelihood estimate of param.
criterion
Currently only "MLE" is implemented.
method
Different optimisation methods to consider.
See Details.
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.
controlLBFGSB
A list of control parameters for optim when using
the "L-BFGS-B" optimisation.
controlNLMINB
A list of control parameters for nlminb
when using the "nlminb" optimisation.
controlCO
A list of control parameters for constrOptim
when using the "constrOptim" 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 par, hist,
logHist, qqnig and ppnig.
object
Object of class "nigFit" for coef.nigFit
and for vcov.nigFit.
Details
startMethod can be either "BFGS" or
"Nelder-Mead".
startValues can be one of the following:
"US"User-supplied.
"FN"A fitted normal distribution.
"Cauchy"Based on a fitted Cauchy distribution.
"MoM"Method of moments.
For the details concerning the use of paramStart,
startMethod, and startValues, see
nigFitStart.
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.
Value
A list with components:
param
A vector giving the maximum likelihood estimate of
param, as c(mu, delta, alpha, beta).
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.
x
The data used to fit the normal inverse Gaussian distribution.
xName
A character string with the actual x argument
name.
paramStart
Starting value of param returned by call to
nigFitStart.
svName
Descriptive name for the method finding start values.
Barndorff-Nielsen, O. (1977)
Exponentially decreasing distributions for the logarithm of particle size,
Proc. Roy. Soc. Lond.,
A353, 401–419.
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992)
Statistics of particle size data.
Appl. Statist.,
41, 127–146.
Paolella, Marc S. (2007)
Intermediate Probability: A Computational Approach,
Chichester: Wiley
See Also
optim, nlm, par,
hist, logHist,
qqnig, ppnig, dskewlap
and nigFitStart.
Examples
param <- c(2, 2, 2, 1)
dataVector <- rnig(500, param = param)
## See how well nigFit works
nigFit(dataVector)
nigFit(dataVector, plots = TRUE)
fit <- nigFit(dataVector)
par(mfrow = c(1, 2))
plot(fit, which = c(1, 3))
## Use nlm instead of default
nigFit(dataVector, method = "nlm")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(GeneralizedHyperbolic)
Loading required package: DistributionUtils
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GeneralizedHyperbolic/nigFit.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nigFit
> ### Title: Fit the normal inverse Gaussian Distribution to Data
> ### Aliases: nigFit print.nigFit plot.nigFit coef.nigFit vcov.nigFit
> ### Keywords: distribution
>
> ### ** Examples
>
> param <- c(2, 2, 2, 1)
> dataVector <- rnig(500, param = param)
> ## See how well nigFit works
> nigFit(dataVector)
Data: dataVector
Parameter estimates:
mu delta alpha beta
1.971 2.318 2.234 1.037
Likelihood: -794.3487
criterion : MLE
Method: Nelder-Mead
Convergence code: 0
Iterations: 171
> nigFit(dataVector, plots = TRUE)
Data: dataVector
Parameter estimates:
mu delta alpha beta
1.971 2.318 2.234 1.037
Likelihood: -794.3487
criterion : MLE
Method: Nelder-Mead
Convergence code: 0
Iterations: 171
> fit <- nigFit(dataVector)
> par(mfrow = c(1, 2))
> plot(fit, which = c(1, 3))
>
> ## Use nlm instead of default
> nigFit(dataVector, method = "nlm")
Data: dataVector
Parameter estimates:
mu delta alpha beta
1.978 2.313 2.226 1.031
Likelihood: -794.3486
criterion : MLE
Method: nlm
Convergence code: 1
Iterations: 26
>
>
>
>
>
>
> dev.off()
null device
1
>