sgt (version 1.0)

sgtmle: Maximum Likelihood Estimation with the Skewed Generalized T Distribution

Description

This function allows data to be fit to the skewed generalized t distribution using maximum likelihood estimation. This function uses the maxLik package to perform its estimations.

Usage

sgt.mle(X.f, mu.f = mu ~ mu, sigma.f = sigma ~ sigma, 
lambda.f = lambda ~ lambda, p.f = p ~ p, q.f = q ~ q, 
data = parent.frame(), start, subset, method = 'BFGS', 
constraints = NULL, follow.on = FALSE, iterlim = 5000, ...)

Arguments

X.f
A formula specifying the data, or the function of the data with parameters, that should be used in the maximisation procedure. X should be on the left-hand side and the right-hand side should be the data or function of the data that should be
mu.f, sigma.f, lambda.f, p.f, q.f
formulas including variables and parameters that specify the functional form of the parameters in the skewed generalized t log-likelihood function. mu, sigma, lambda, p, and q should be
data
an optional data frame in which to evaluate the variables in formula and weights. Can also be a list or an environment.
start
a named list or named numeric vector of starting estimates for every parameter.
subset
an optional vector specifying a subset of observations to be used in the fitting process.
method
A list of the methods to be used. May include "NR" (for Newton-Raphson), "BFGS" (for Broyden-Fletcher-Goldfarb-Shanno), "BHHH" (for Berndt-Hall-Hall-Hausman), "SANN" (for Simulated ANNealing), "CG" (for Conjugate Gradients), or "NM"
constraints
either NULL for unconstrained optimization or a list with two components. The components may be either eqA and eqB for equality-constrained optimization $A \theta + B = 0$; or ineqA and
follow.on
logical; if TRUE, and there are multiple methods, then the last set of parameters from one method is used as the starting set for the next.
iterlim
If provided as a vector of the same length as method, gives the maximum number of iterations or function values for the corresponding method. If a single number is provided, this will be used for all methods.
...
further arguments that are passed to the selected maximisation routine in the maxLik package. See below for a non-exhaustive list of some further arguments that can be used.

Value

  • If only one method is specified, sgt.mle returns a list of class "MLE". If multiple methods are given, sgt.mle returns a list of class "mult.MLE" with each component containing the results of each maximisation procedure. Each component is a list of class "MLE". A list of class "MLE" has the following components:
  • parametersthe names of the given parameters taken from start
  • maximumfn value at maximum (the last calculated value if not converged).
  • estimateestimated parameter value.
  • gradientvector, last gradient value which was calculated. Should be close to 0 if normal convergence.
  • gradientObsmatrix of gradients at parameter value estimate evaluated at each observation (only if grad returns a matrix or grad is not specified and fn returns a vector).
  • hessianHessian at the maximum (the last calculated value if not converged).
  • codereturn code:
    • 1
    { gradient close to zero (normal convergence).} 2{ successive function values within tolerance limit (normal convergence).} 3{ last step could not find higher value (probably not converged). This is related to line search step getting too small, usually because hitting the boundary of the parameter space. It may also be related to attempts to move to a wrong direction because of numerical errors. In some cases it can be helped by changing steptol.} 4{ iteration limit exceeded.} 5{ Infinite value.} 6{ Infinite gradient.} 7{ Infinite Hessian.} 8{ Successive function values withing relative tolerance limit (normal convergence).} 9{ (BFGS) Hessian approximation cannot be improved because of gradient did not change. May be related to numerical approximation problems or wrong analytic gradient.} 100{ Initial value out of range.}

item

  • message
  • last.step
  • f0
  • climb
  • fixed
  • iterations
  • type
  • constraints
  • outer.iterations
  • barrier.value

code

NULL

itemize

  • type

Details

The parameter names are taken from start. If there is a name of a parameter or some data found on the right-hand side of one of the formulas but not found in data and not found in start, then an error is given. Below is a non-exhaustive list of further arguments that may be passed in to the sgt.mle function (see maxLik documentation for more details): [object Object],[object Object],[object Object],[object Object],[object Object] Note that not all arguments may be used for every maximisation algorithm at this time. If multiple methods are supplied (i.e. length(method) > 1), all arguments are employed for each method (except for iterlim, which is allowed to vary for different methods). If multiple methods are supplied, and some methods fail to initialise properly, a warning will be given. If every method fails to initialise, an error is given.

References

Henningsen, Arne and Toomet, Ott (2011). "maxLik: A package for maximum likelihood estimation in R" Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.

See Also

The maxLik package and its documentation. The sgt.mle simply uses its functions to maximize the skewed generalized t log-likelihood.

Examples

Run this code
### Showing how to fit a simple vector of data to the skewed 
### generalized t distribution. 
require(graphics)
require(stats)
set.seed(123456)
x = rt(100, df=10)
X.f = X ~ x
start = list(mu = 0, sigma = 2, lambda = 0, p = 2, q = 12)
result = sgt.mle(X.f = X.f, start = start, finalHessian = "BHHH")
sumResult = summary(result)
print(result)
coef(result)
print(sumResult)
### Note that the t distribution is a special case of the 
### skewed generalized t distribution

### Looking at the fit graphically
xvals = seq(-3,3,by=0.01)
plot(xvals, dt(xvals, df=10), type="l", col="blue")
lines(density(x))
mu = result$estimate[1]
sigma = result$estimate[2]
lambda = result$estimate[3]
p = result$estimate[4]
q = result$estimate[5]
lines(xvals, dsgt(xvals, mu = mu, sigma = sigma, lambda = lambda, p = p, q = q), col="red")

Run the code above in your browser using DataCamp Workspace