6.5.1 The package Davies
Even though the focus of the packageDaviesis an implementation of the Davies quantile function (see Hankin and Lee 2006),Rroutines that address the GLD dis- tribution are also included. The package is listed in the CRAN “Distributions” Task View. The package is shipped with aNAMESPACEfile, but neitherS3norS4classes/
methods are employed. Hence, in addition to two data sets, the package offers a col- lection of functions for dealing with these two kinds of distributions—no more and no less.
With respect to the GLD, the functions are based on the Ramberg–Schmeiser (RS) specification. The density, distribution, and quantile functions of the GLD have been implemented, as well as a function for generating random variates, and thedpqr
k k naming convention is followed for naming these routines, ( e.g.,dgld()). Further-
more, the routinedgld.p()is an implementation of the density function expressed in terms of the quantile.
The expected value of the GLD for a given parameterization can be retrieved either as an exact value with the routineexpected.gld()or as an approximation with expected.gld.approx(). Within both functions the values are determined as the sum of a constant (𝜆1) and two Davies quantile functions.
6.5.2 The package fBasics
A general description of the packagefBasicshas already been provided in Section 6.4.1. Hence, in the following description the focus will be on theRroutines for handling the GLD.
The density, distribution, and quantile functions and a routine for obtaining random variates have been implemented asRroutines, and thedpqrnaming convention is followed ( e.g.,dgld()). These functions are wrappers for the bodies of the func- tions of the routines with the same name contained in the packagegldby King et al.
(2016)—see Section 6.5.3 for a discussion of this package. However, these wrapper functions are limited to the RS specification, and only parameter values for𝜆1,…, 𝜆4
pertinent to region 4 of the parameter space can be supplied as arguments to these functions, otherwise an error is returned.
The fitting of data to the GLD is provided by the functiongldFit(). Similar to the above functions, the GLD is expressed in the RS specification and the optimization is carried out for the parameter space pertinent to region 4. Apart from the data argument xand the initial parameter values lambda1[234], the function has an argumentmethodby which the estimation method can be set. The available estimation procedures are: maximization of the log-likelihood ("mle"), the method of maximum product spacing ("mps"), robust moment matching ("rob"), goodness of fit ("gof"), and histogram binning ("hist"). If one of the latter two methods is chosen, the user can set the type of goodness-of-fit statistic or the binning method via the function’s argumenttype. This argument is passed as an ellipsis argument to either of the user-hidden functions .gldFit.gof() or .gldFit.hist(), respectively. For estimation methods based on goodness of fit this can be the Anderson–Darling ("ad"), Cramér–von Mises ("cvm"), or Kolmogorov–Smirnov ("ks") statistic. If the histogram approach is chosen, the count of bins can be determined by the Freedman–Diaconis binning ("fd"), Scott’s histogram binning ("scott"), or Sturges binning approach ("sturges"). The function returns anS4objectfDISTFIT. The estimates, the value of the objective, and the convergence code of the nlminb() optimizer are returned as a list in the slotfit of objects of this kind. By default, a plot of the estimated density is produced, which can be suppressed by settingdoplot = FALSE.
The mode of the GLD can be computed for given parameter values of𝜆1,…, 𝜆4 with the function gldMode(). Robust estimates for location, dispersion, skew- ness, and kurtosis can be computed for given parameter values with the functions gldMED(),gldIQR(),gldSKEW(), andgldKURT(), respectively.
k k
6.5.3 The package gld
The packagegldis, to the author’s knowledge, the only one that implements all three GLD specifications: RS, FMKL, and FM5 (see King et al. 2016). The latter is an extension of the FMKL version in which a fifth parameter is included in order to explicitly capture the skewness of the data. The FM5 specification is derived from the modification of the RS specification by Gilchrist (2000).
The package is included in CRAN “Distributions” Task View.S3classes and meth- ods have been utilized, and the package contains aNAMESPACEfile. The distribution functions of the GLD specifications are interfaced from routines written in theClan- guage.
The density, quantile density, distribution, and quantile distribution functions are implemented as Rroutinesdgl(),dqgl(),pgl(), andqdgl(), respectively.
Random variates of the GLD can be generated with the function rgl(). With respect to parameter estimation, the starship method has been implemented as function starship(). Here, the initial values are determined according to an adaptive grid search (starship.adaptivegrid()) and then used in the call tooptim(). The objective function itself is included in the package as function starship.obj(). The function starship() returns an object of informal class starship for whichplot(),print(), and summary() methods are made available. The validity of the estimated 𝜆 parameters can be checked with the functiongl.check.lambda(). As a means of assessing the goodness of fit graphically, the functionqqgl()produces a QQ plot. Finally, the density of the GLD can be depicted with the functionplotgl().
6.5.4 The package lmomco
Estimation methods based on L-moments for various distributions are implemented in the packagelmomco(see Asquith 2016). Here we will concentrate on those tools that directly address the GLD. The package is considered to be a core package in the CRAN “Distributions” Task View. It is written purely inRand is shipped with a NAMESPACEfile with export directives for all relevant user functions. The package is quite huge, judged by the size of its manual, which runs to more than 500 pages.
It is worth mentioning that, in addition to estimation methods based on L-moments and their extensions, probability-weighted moment (PWM) estimators are available.
In order to estimate the parameters of the GLD, the L-moments for univariate sample data must be determined first. This can be achieved with the function lmom.ub()for unbiased L-moment estimates, with the functionTLmoms()for trimmed L-moments, or with the functionpwm.ub()for unbiased sample PWMs.
If the latter route is chosen, these PWM estimates can be converted to L-moment estimates with the function pwm2lmom(). Having estimated the L-moments, the resulting object can be used in the call to the functions pargld() and/or parTLgld()to estimate the parameters of the GLD by L-moments or trimmed L-moments, respectively. The package offers routines for checking the validity of the estimated parameters and/or L-moments (functions are.par.valid(),
k k are.pargld.valid(), and are.lmom.valid()) as well as means of
converting between parameter estimates and the associated L-moments for a given distribution (functions vec2par(), lmom2par(), par2lmom(), and lmomgld()).
TheRfunctions that directly relate to the GLD arecdfgld()for the cumulative distribution function,quagld()for the quantile function, andpdfgld()for the density function. Random variates for a given parameterization of the GLD can be generated with the function rlmomco(). The correctness of an empirically determined probability or density function can be assessed with the functions check.fs()andcheck.pdf(), respectively.