Learn R Programming

VarianceGamma (version 0.1-2)

vgFit: Fit the Variance Gamma to Data

Description

Fits a variance gamma 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

vgFit(x, freq = NULL, breaks = NULL, paramStart = NULL,
        startMethod = "Nelder-Mead", startValues = "SL",
        method = "Nelder-Mead", hessian = FALSE,
        plots = FALSE, printOut = FALSE,
        controlBFGS = list(maxit = 200),
        controlNM = list(maxit = 1000), maxitNLM = 1500, ...)

## S3 method for class 'vgFit': print(x, digits = max(3, getOption("digits") - 3), ...)

## S3 method for class 'vgFit': 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(), ...)

Arguments

x
Data vector for vgFit. Object of class "vgFit" for print.vgFit and plot.vgFit.
freq
A vector of weights with length equal to length(x).
breaks
Breaks for histogram, defaults to those generated by hist(x, right = FALSE, plot = FALSE).
paramStart
A user specified starting parameter vector param taking the form c(vgC,sigma,theta,nu).
startMethod
Method used by vgFitStart in calls to optim, default is "Nelder-Mead". See Details.
startValues
Code giving the method of determining starting values for finding the maximum likelihood estimate of param, default method is "SL". See Details.
method
Different optimisation methods to consider, default is "Nelder-Mead". See Details.
hessian
Logical. If TRUE the value of the hessian is returned.
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 par, hist, logHist, qqhyperb and pphyperb.

Value

  • A list with components:
  • paramA vector giving the maximum likelihood estimate of param, as (c,sigma,theta,nu).
  • maxLikThe value of the maximised log-likelihood.
  • hessianIf hessian was set to TRUE, the value of the hessian. Not present otherwise.
  • methodOptimisation method used.
  • convConvergence code. See the relevant documentation (either optim or nlm) for details on convergence.
  • iterNumber of iterations of optimisation routine.
  • obsThe data used to fit the hyperbolic distribution.
  • obsNameA character string with the actual obs argument name.
  • paramStartStarting value of param returned by call to vgFitStart.
  • svNameDescriptive name for the method finding start values.
  • startValuesAcronym for the method of finding start values.
  • breaksThe cell boundaries found by a call to hist.
  • midpointsThe cell midpoints found by a call to hist.
  • empDensThe estimated density found by a call to hist.

code

method = "nlm"

itemize

  • "BFGS"

item

  • "Nelder-Mead"
  • "nlm"

Details

startMethod can be either "BFGS" or "Nelder-Mead".

startValues can be one of the following:

  • "US"
{User-supplied.} "SL"{Based on a fitted skew-Laplace distribution.} "MoM"{Method of moments.}

References

Seneta, E. (2004). Fitting the variance-gamma model to financial data. J. Appl. Prob., 41A:177--187.

See Also

optim, nlm, par, hist, logHist, qqvg, ppvg, dskewlap and vgFitStart.

Examples

Run this code
param <- c(0,0.5,0,0.5)
dataVector <- rvg(500, param = param)
## See how well vgFit works
vgFit(dataVector)
vgFit(dataVector, plots = TRUE)
fit <- vgFit(dataVector)
par(mfrow = c(1,2))
plot(fit, which = c(1,3))

## Use nlm instead of default
param <- c(0,0.5,0,0.5)
dataVector <- rvg(500, param = param)
vgFit(dataVector, method = "nlm", hessian = TRUE)


## Use BFGS instead of deault
param <- c(0,0.5,0,0.5)
dataVector <- rvg(500, param = param)
vgFit(dataVector, method = "BFGS", hessian = TRUE)

Run the code above in your browser using DataLab