NormalLaplace

I was fortunate to undertake a summer studentship with the University of Auckland’s Department of Statistics over the summer of 2010–2011. My project was entitled “Software for the Normal Laplace Distribution”. The purpose of this project was to improve upon the functionality present in the NormalLaplace package that was available via the Rmetrics group on R-Forge. What was present prior to my involvement were functions that calculated theoretical means, variance, skewness and kurtosis in a Normal Laplace (NL) distribution. The standard “dpqr” functions were also present, these are the density, cumulative distribution, quantile and random number generating functions respectively.

A parameter checking function was created in order to validate NL parameters, along with a fitting function that included appropriate S3 methods on the fitted object (e.g. plot, coef, summary).

The NormalLaplace package was then extended to include functions for the Generalised Normal Laplace (GNL) distribution. The same functionality that was implemented for the NL distribution was also implemented for the GNL distribution. The GNL distribution adds an additional parameter, rho, on top of the existing NL parameters and acts as a scaling parameter. Complications arose when implementing the density and cumulative distribution functions for the GNL distribution as they required inversion of the GNL characteristic function and numerical evalution of integrals. This was necessary due to the lack of closed form expressions for these functions. A consequence of this is that calculation is both slow and somewhat inaccurate. On top of this, the characteristic function returns complex numbers and R’s integrate function only works over one dimension. This means that the characteristic function required modification for both the density and cumulative distribution functions in order to return real numbers and allow numerical evalution using the integrate function.

Definitions of the density, cumulative distribution function and random number generating functions are provided below.

ϕ(s)=(αβeσ2s2/2(αis)(β+is))ρ\phi(s)=\left(\frac{\alpha \beta e^{-\sigma^2s^2/2}}{(\alpha - is)(\beta + is)}\right)^{\rho}

r(s)r(s) and θ(s)\theta(s) are defined as the modulus and argument of the complex number returned from the characteristic function.

f(xμ)=1π0r(s)cos(θ(s)sy)dsf(x - \mu)=\frac{1}{\pi} \int_0^\infty r(s)cos(\theta(s) - sy)ds

F(xμ)=12+1π0r(s)ssin(sxθ(s))dsF(x - \mu)=\frac{1}{2} + \frac{1}{\pi} \int_0^\infty \frac{r(s)}{s} sin(sx - \theta(s))ds

Generation of random observations from the GNL distribution is based upon the composition of three random variables, ZZ , G1G_1 and G2G_2 . These are independent with ZN(0,1)Z \sim N(0, 1) and G1G_1 , G2G_2 being gamma random variables with a scale of 1 and a shape of ρ\rho .

A GNL random variable, XGNL(μ,σ,α,β,ρ)X \sim \textrm{GNL}(\mu, \sigma, \alpha, \beta, \rho) can be represented as:

X=ρμ+σρZ+1αG11βG2X = \rho\mu + \sigma\sqrt{\rho}Z + \frac{1}{\alpha}G_1 - \frac{1}{\beta}G_2

Mean, variance, skewness and kurtosis functions were implemented for the GNL distribution and are defined below:

E(X)=ρ(μ+1α1β)\textrm{E}(X)= \rho\left(\mu + \frac{1}{\alpha} - \frac{1}{\beta}\right)

Var(X)=ρ(σ2+1α2+1β2)\textrm{Var}(X)= \rho\left(\sigma^2 + \frac{1}{\alpha^2} + \frac{1}{\beta^2}\right)

Υ=k3k232=2(β3α3)ρ12(σ2α2β2+α2+β2)2\Upsilon = \frac{k_3}{k_2^{\frac{3}{2}}} = \frac{2(\beta^3 - \alpha^3)}{\rho^{\frac{1}{2}}(\sigma^2\alpha^2\beta^2 + \alpha^2 + \beta^2)^2}

Γ=k4k22=6(α4+β4)ρ(σ2α2β2+α2+β2)2\Gamma = \frac{k_4}{k_2^2} = \frac{6(\alpha^4 + \beta^4)}{\rho(\sigma^2\alpha^2\beta^2 + \alpha^2 + \beta^2)^2}