Skip to main content
Advertisement
Browse Subject Areas
?

Click through the PLOS taxonomy to find articles in your field.

For more information about PLOS Subject Areas, click here.

  • Loading metrics

Wrapped: An R package for circular data

Abstract

The Wrapped package computes the probability density function, cumulative distribution function, quantile function and also generates random samples for many univariate wrapped distributions. It also computes maximum likelihood estimates, standard errors, confidence intervals and measures of goodness of fit for nearly fifty univariate wrapped distributions. Numerical illustrations of the package are given.

Introduction

Circular data are data recorded in degrees or radii. They arise in a wide variety of scientific areas. Some published applications involving real circular data include: data from fibre composites and from ceramic foams [1]; skeletal representations in medical image analysis and biomechanical gait analysis of the knee joint [2]; worldwide earthquakes with magnitude greater than or equal to 7.0 M W [3]; wave direction data in the Adriatic sea, off the coast of Italy [4]; data set of phase angles of circadian-related genes in heart and liver tissues [5].

Wrapping is a popular method for constructing distributions for circular data. Let g denote a valid probability density function (PDF) defined on the real line. Let G denote the corresponding cumulative distribution function (CDF). The wrapped distribution corresponding to g and G has the PDF and CDF specified by (1) and (2) respectively. g could also be chosen as a PDF on the positive real line or as a probability mass function of a discrete random variable. But usually circular data are recorded between −π and π. So, we stick to (1) and (2).

Many wrapped distributions have been proposed and studied in the literature. These include the wrapped normal distribution [6], wrapped Cauchy distribution [7], wrapped skew normal distribution [8], wrapped exponential and Laplace distributions [9], wrapped stable distribution [10], wrapped gamma distribution [11], wrapped t distribution [12], wrapped lognormal and Weibull distributions [13], wrapped skew Laplace distribution [14], wrapped weighted exponential distribution [15], wrapped hypo exponential distribution [16], wrapped geometric distribution [17], wrapped Poisson distribution [18], wrapped zero inflated Poisson distribution [19] and wrapped Lindley distribution [20]. There are also a number of R [21] packages developed to implement wrapped distributions including: NPCirc [22] giving procedures for wrapped Cauchy, wrapped normal and wrapped skew normal distributions; wle [23] giving procedures for the wrapped normal distribution; circular [24] giving procedures for wrapped normal, wrapped Cauchy and wrapped stable distributions; CircStats [25] giving procedures for wrapped normal, wrapped Cauchy and wrapped stable distributions; BAMBI [26] giving procedures for wrapped normal and wrapped normal mixtures distributions; movehMM [27] giving procedures for the wrapped Cauchy distribution; SpaDES [28] giving procedures for the wrapped normal distribution.

But we are not aware of an R package applicable for computing (1) and (2) for given parametric forms for g and G. The aim of this paper is to introduce an R package developed by the authors that is applicable for computing many wrapped distributions. The package is named Wrapped [29]. The package performs the following:

  1. i) computes (1), (2) and the corresponding quantile function for given parametric forms for g and G. Because (1) and (2) are infinite sums, the following approximations are used (3) and (4) where K ≥ 1 is an integer. We shall refer to (3) and (4) as the approximate PDF and approximate CDF, respectively.
  2. ii) generates random samples from the wrapped distribution for given parametric forms for g and G.
  3. iii) computes maximum likelihood estimates of the parameters, standard errors, 95 percent confidence intervals, value of Cramer von Mises statistic, value of Anderson Darling statistic, value of Kolmogorov Smirnov test statistic and its p-value, value of Akaike Information Criterion, value of Consistent Akaike Information Criterion, value of Bayesian Information Criterion, value of Hannan Quinn Information Criterion, minimum value of the negative log likelihood function and convergence status when some data are fitted by one of the following wrapped distributions: wrapped normal, wrapped Gumbel, wrapped logistic, wrapped Student’s t, wrapped Cauchy, wrapped skew normal, wrapped skew t, wrapped skew Cauchy, wrapped asymmetric Laplace, wrapped normal Laplace, wrapped generalized logistic, wrapped skew Laplace, wrapped exponential power, wrapped skew exponential type 1, wrapped skew exponential type 2, wrapped skew exponential type 3, wrapped skew exponential type 4, wrapped normal exponential t, wrapped skew normal type 2, wrapped ex Gaussian, wrapped skew t type 1, wrapped skew t type 3, wrapped skew t type 4, wrapped skew t type 5, wrapped sinh arcsinh, wrapped exponential generalized beta type 2, wrapped Johnson’s Su, wrapped skew generalized t, wrapped skew hyperbolic, wrapped asymmetric Laplace, wrapped polynomial tail Laplace, wrapped generalized asymmetric t, wrapped variance gamma, wrapped normal inverse Gaussian, wrapped hyperbolic, wrapped skew Laplace, wrapped slash, wrapped beta normal, wrapped Laplace, wrapped short tailed symmetric and wrapped log gamma distributions.
  4. iv) plots PDFs, CDFs, quantile functions and histograms of the radii of 100 random numbers for a specified wrapped distribution. The wrapped distribution must be one of those mentioned in iii).

A description of the program structure of the package is given in the next section. Some numerical illustrations of the package are given in the following section. The paper concludes with a discussion section.

Program structure

The following are the command syntaxes of the Wrapped package:

dwrappedg(x, spec, K = K,…)

pwrappedg(x, spec, K = K,…)

rwrappedg(n, spec,…)

qwrappedg(p, spec, K = K,…)

mwrappedg(g, data, starts, K = K, method = “BFGS”)

plotfour(g, K = K, para, plotit)

dwrappedg computes the approximate PDF for given x, g and K. The g must be specified through the string spec. For example, if spec = “norm” then g is the standard normal PDF. If parameters are needed to specify spec they can be supplied through For example, spec = “norm” with replaced by mean = 1, sd = 10 will mean that g is a normal PDF with unit mean and standard deviation 10. pwrappedg computes the approximate CDF for given x, g and K. For both dwrappedg and pwrappedg, x can be a scalar or a vector.

qwrappedg computes the roots of for given p, g and K. p can be a scalar or a vector.

rwrappedg generates n random numbers from the wrapped distribution specified by g. The random numbers are cos(rspec(n,…)), cos(rspec(n,…)).

To use dwrappedg, pwrappedg and rwrappedg, one must have the functions dg, pg, qg and rg available in the base package of R or one of its contributed packages. In the latter case, the relevant contributed package(s) must be first downloaded. For example, one must have the functions dnorm, pnorm, qnorm and rnorm available for computing the wrapped normal distribution. These functions are indeed available in the base package of R.

mwrappedg fits the wrapped distribution specified by g and K to the data contained in data. starts is a vector of starting values for the parameters of g in the stated order. For example, if g = “norm” then starts = c(0, 1) gives the starting values of 0 for the mean and 1 for the standard deviation of the wrapped normal distribution. The following choices are possible for g:

  • Normal distribution [30, 31]: g = “norm”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0.
  • Gumbel distribution [32]: g = “gumbel”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0. The contributed R package evd due to [33] is used to compute this PDF g.
  • Logistic distribution: g = “logis”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0.
  • Student’s t distribution [34]: g = “t.scaled”, starts = c(a, b, n) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and n > 0, where Γ(⋅) denotes the gamma function defined by
    The contributed R package metRology due to [35] is used to compute this PDF g.
  • Cauchy distribution [34]: g = “cauchy”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0.
  • Skew normal distribution [36]: g = “sn”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and −∞ < c < +∞, where ϕ(⋅) and Φ(⋅) denote, respectively, the PDF and CDF of the standard normal distribution defined by and respectively. The contributed R package sn due to [37] is used to compute this PDF g.
  • Skew t distribution of type 2 [38]: g = “st”, starts = c(a, b, c, n) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and n > 0, where . The contributed R package sn due to [37] is used to compute this PDF g.
  • Skew Cauchy distribution [38]: g = “sc”, starts = c(a, b, c, n) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and n > 0, where . The contributed R package sn due to [37] is used to compute this PDF g.
  • Asymmetric Laplace distribution [39]: g = “ALD”, starts = c(a, b, p) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and 0 < p < 1, where ρp(u) = u[pI{u < 0}] and I {⋅} denotes the indicator function defined by I {A} = 1 if A is true and I {A} = 0 if A is false. The contributed R package ald due to [40] is used to compute this PDF g.
  • Normal Laplace distribution [41]: g = “nl”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0, where R(u) = [1 − Φ(u)]/ϕ(u). The contributed R package ald due to [42] is used to compute this PDF g.
  • Generalized logistic distribution [43]: g = “glogis”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, and c > 0. The contributed R package glogis due to [44] is used to compute this PDF g.
  • Skew Laplace distribution [45]: g = “sld”, starts = c(a, b, c) and for 0 < p < 1, −∞ < a < +∞, b > 0, and 0 < c < 1. The contributed R package sld due to [46] is used to compute this PDF g.
  • Exponential power distribution: g = “normp”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0. The contributed R package normalp due to [47] is used to compute this PDF g.
  • Skew exponential type 1 distribution [48]: g = “SEP1”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew exponential type 2 distribution [48]: g = “SEP2”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew exponential type 3 distribution [48]: g = “SEP3”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew exponential type 4 distribution [48]: g = “SEP4”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Normal exponential t distribution [48]: g = “NET”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 1 and d > c. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew normal type 2 distribution [48]: g = “SN2”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Ex Gaussian distribution [48]: g = “exGAUS”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew t distribution of type 1 [50]: g = “ST1”, starts = c(a, b, n, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and n > 0, where . The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew t distribution of type 3 [51]: g = “ST3”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0, where B(⋅, ⋅) denotes the beta function defined by
    The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew t distribution of type 4: g = “ST4”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew t distribution of type 5 [52]: g = “ST5”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0, where and . The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Sinh arcsinh distribution [53]: g = “SHASH”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0, where and
    The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Sinh arcsinh distribution [54]: g = “SHASHo”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0, where and
    The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Sinh arcsinh distribution [54]: g = “SHASH2”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0, where and
    The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Exponential generalized beta type 2 distribution [55]: g = “EGB2”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, −∞ < b < +∞, c > 0 and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Johnson’s Su distribution [56]: g = “JSU”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0, where , , , w = exp (d2) and Ω = −cd. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Johnson’s Su distribution [56]: g = “JSUo”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0. The contributed R package gamlss.dist due to [49] is used to compute this PDF g.
  • Skew generalized t distribution [57]: g = “sgt”, starts = c(a, b, c, d, e) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −1 < c < 1, d > 0 and e > 0, where and
    The contributed R package sgt due to [58] is used to compute this PDF g.
  • Skew hyperbolic distribution [59]: g = “skewhyp”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0, where Kν(⋅) denotes the modified Bessel function of the second kind of order ν defined by where Iν(⋅) denotes the modified Bessel function of the first kind of order ν defined by
    The contributed R package SkewHyperbolic due to [60] is used to compute this PDF g.
  • Asymmetric Laplace distribution [61]: g = “asl”, starts = c(a, c, b) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and −∞ < c < +∞, where . The contributed R package cubfits due to [62] is used to compute this PDF g.
  • Asymmetric Laplace distribution [61]: g = “asla”, starts = c(a, c, b) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0. The contributed R package cubfits due to [62] is used to compute this PDF g.
  • Asymmetric Laplace distribution [63]: g = “al”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and 0 < c < 1. The contributed R package lqmm due to [64] is used to compute this PDF g.
  • Polynomial tail Laplace distribution: g = “PTL”, starts = c(a, b, c) and for −∞ < x < +∞, a > 0, b > 0 and c > 0. The contributed R package LCA due to [65] is used to compute this PDF g.
  • Generalized asymmetric t distribution [66]: g = “gat”, starts = c(a, b, c, d, e) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0, d > 0 and e > 0. The contributed R package GEVStableGarch due to [67] is used to compute this PDF g.
  • Variance gamma distribution [68]: g = “vg”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, −∞ < c < +∞ and d > 0. The contributed R package VarianceGamma due to [69] is used to compute this PDF g.
  • Normal inverse Gaussian distribution [68]: g = “nig”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and −∞ < d < +∞. The contributed R package GeneralizedHyperbolic due to [70] is used to compute this PDF g.
  • Hyperbolic distribution [68]: g = “hyperb”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and −∞ < d < +∞. The contributed R package GeneralizedHyperbolic due to [70] is used to compute this PDF g.
  • Skew Laplace distribution [71]: g = “skewlap”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0. The contributed R package GeneralizedHyperbolic due to [70] is used to compute this PDF g.
  • Slash distribution [72]: g = “slash”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0. The contributed R package VGAM due to [73] is used to compute this PDF g.
  • Beta normal distribution [74]: g = “betanorm”, starts = c(a, b, c, d) and for −∞ < x < +∞, −∞ < a < +∞, b > 0, c > 0 and d > 0. The contributed R package VGAM due to [73] is used to compute this PDF g.
  • Laplace distribution: g = “laplace”, starts = c(a, b) and for −∞ < x < +∞, −∞ < a < +∞ and b > 0. The contributed R package VGAM due to [73] is used to compute this PDF g.
  • Short tailed symmetric distribution [75]: g = “tikuv”, starts = c(a, b, c) and for −∞ < x < +∞, −∞ < a < +∞, b > 0 and c > 0, where C denotes the normalizing constant. The contributed R package VGAM due to [73] is used to compute this PDF g.
  • Log gamma distribution [76]: g = “lgamma”, starts = c(a) and for −∞ < x < +∞ and −∞ < a < +∞. The contributed R package ordinal due to [77] is used to compute this PDF g.

mwrappedg will output the following: parameter estimates, standard errors, 95 percent confidence intervals, value of Akaike Information Criterion, value of Consistent Akaike Information Criterion, value of Bayesian Information Criterion, value of Hannan Quinn Information Criterion, Cramer von Misses statistic value, Anderson Darling statistic value, minimum value of the negative log likelihood, Kolmogorov Smirnov statistic value, its p value and convergence status of the minimization of the negative log likelihood. These were computed using the R package AdequacyModel due to [78]. There are other packages for fitting univariate distributions, for example, the R package fitdistrplus due to [79]. But none of these packages give as much output as [78] gives.

plotfour draws four plots of the PDF, four plots of the CDF, four plots of the quantile function or four histograms of the radii of 100 random numbers of a specified wrapped distribution. The wrapped distribution must be specified by g and K as explained before. plotit is a character string saying what is to be plotted. It should take one of “pdf”, “cdf”, “quantile” or “random”. para is a list with four components, each component is a vector specifying the parameter values of the chosen wrapped distribution.

Illustrations

Here, we provide several illustrations of the practical use of the package Wrapped.

The first illustration plots the PDFs of the wrapped beta normal, wrapped skew normal, wrapped asymmetric Laplace and wrapped skew t type 3 distributions for selected parameter values.

plotfour(“betanorm”,K = 100,para = list(c(0,1,0.1,9),c(0,1,0.1,20),

c(0,1,20,0.1),c(0,1,3,3)), plotit = “pdf”)

plotfour(“sn”,K = 100,para = list(c(0,1,-2),c(0,1,0),

c(0,1,2),c(0,1,10)), plotit = “pdf”)

plotfour(“asla”,K = 100,para = list(c(0,1,1),c(0,2,1),

c(0,5,1),c(0,50,1)), plotit = “pdf”)

plotfour(“ST3”,K = 100,para = list(c(0,1,1,1),c(0,1,2,5),

c(0,1,0.1,5),c(0,1,50,50)), plotit = “pdf”)

The plots generated are collated in Fig 1.

thumbnail
Fig 1. PDFs of the wrapped beta normal (four plots in the top left), wrapped skew normal (four plots in the top right) wrapped asymmetric Laplace (four plots in the bottom left) and wrapped skew t type 3 (four plots in the bottom right) distributions for selected parameter values.

https://doi.org/10.1371/journal.pone.0188512.g001

The second illustration plots the CDFs of the wrapped beta normal, wrapped skew normal, wrapped asymmetric Laplace and wrapped skew t type 3 distributions for selected parameter values.

plotfour(“betanorm”,K = 100,para = list(c(0,1,0.1,9),c(0,1,0.1,20),

c(0,1,20,0.1),c(0,1,3,3)), plotit = “cdf”)

plotfour(“sn”,K = 100,para = list(c(0,1,-2),c(0,1,0),

c(0,1,2),c(0,1,10)), plotit = “cdf”)

plotfour(“asla”,K = 100,para = list(c(0,1,1),c(0,2,1),

c(0,5,1),c(0,50,1)), plotit = “cdf”)

plotfour(“ST3”,K = 100,para = list(c(0,1,1,1),c(0,1,2,5),

c(0,1,0.1,5),c(0,1,50,50)), plotit = “cdf”)

The plots generated are collated in Fig 2.

thumbnail
Fig 2. CDFs of the wrapped beta normal (four plots in the top left), wrapped skew normal (four plots in the top right) wrapped asymmetric Laplace (four plots in the bottom left) and wrapped skew t type 3 (four plots in the bottom right) distributions for selected parameter values.

https://doi.org/10.1371/journal.pone.0188512.g002

The third illustration plots the quantile functions of the wrapped beta normal, wrapped skew normal, wrapped asymmetric Laplace and wrapped skew t type 3 distributions for selected parameter values.

plotfour(“betanorm”,K = 100,para = list(c(0,1,0.1,9),c(0,1,0.1,20),

c(0,1,20,0.1),c(0,1,3,3)), plotit = “quantile”)

plotfour(“sn”,K = 100,para = list(c(0,1,-2),c(0,1,0),

c(0,1,2),c(0,1,10)), plotit = “quantile”)

plotfour(“asla”,K = 100,para = list(c(0,1,1),c(0,2,1),

c(0,5,1),c(0,50,1)), plotit = “quantile”)

plotfour(“ST3”,K = 100,para = list(c(0,1,1,1),c(0,1,2,5),

c(0,1,0.1,5),c(0,1,50,50)), plotit = “quantile”)

The plots generated are collated in Fig 3.

thumbnail
Fig 3. Qunatile functions of the wrapped beta normal (four plots in the top left), wrapped skew normal (four plots in the top right) wrapped asymmetric Laplace (four plots in the bottom left) and wrapped skew t type 3 (four plots in the bottom right) distributions for selected parameter values.

https://doi.org/10.1371/journal.pone.0188512.g003

The fourth illustration plots the histograms of the radii of 100 random numbers generated from the wrapped beta normal, wrapped skew normal, wrapped asymmetric Laplace and wrapped skew t type 3 distributions for selected parameter values.

plotfour(“betanorm”,K = 100,para = list(c(0,1,0.1,9),c(0,1,0.1,20),

c(0,1,20,0.1),c(0,1,3,3)), plotit = “random”)

plotfour(“sn”,K = 100,para = list(c(0,1,-2),c(0,1,0),

c(0,1,2),c(0,1,10)), plotit = “random”)

plotfour(“asla”,K = 100,para = list(c(0,1,1),c(0,2,1),

c(0,5,1),c(0,50,1)), plotit = “random”)

plotfour(“ST3”,K = 100,para = list(c(0,1,1,1),c(0,1,2,5),

c(0,1,0.1,5),c(0,1,50,50)), plotit = “random”)

The plots generated are collated in Fig 4.

thumbnail
Fig 4. Histograms of 100 random numbers generated from the wrapped beta normal (four plots in the top left), wrapped skew normal (four plots in the top right) wrapped asymmetric Laplace (four plots in the bottom left) and wrapped skew t type 3 (four plots in the bottom right) distributions for selected parameter values.

https://doi.org/10.1371/journal.pone.0188512.g004

We see that a variety of symmetric and asymmetric shapes are possible for the PDFs, CDFs, quantile functions and histograms.

The following code shows how to use Wrapped to fit wrapped normal, wrapped logistic, wrapped Gumbel, wrapped Laplace and wrapped Student’s t distributions to data. The data used are 30 cross-beds azimuths of palaeocurrents from [80].

x = c(294, 177, 257, 301, 257, 267, 329, 177, 241, 315,

 229, 239, 277, 250, 287, 281, 166, 229, 254, 232,

 290, 245, 245, 214, 272, 224, 215, 242, 186, 224)

x = 2 * pi * x / 360 – pi

mwrappedg(“norm”, data = x, starts = c(mean(x), 1),

 K = 100, method = “BFGS”)

mwrappedg(“logis”, data = x, starts = c(mean(x), 1),

 K = 100, method = “BFGS”)

mwrappedg(“gumbel”, data = x, starts = c(mean(x), 1),

 K = 100, method = “BFGS”)

mwrappedg(“laplace”, data = x, starts = c(mean(x), 1),

 K = 100, method = “BFGS”)

mwrappedg(“t.scaled”, data = x, starts = c(mean(x), sd(x), 50),

 K = 100, method = “BFGS”)

For each of the five fitted wrapped distributions, the output gives the parameter estimates, standard errors, 95 percent confidence intervals, value of Akaike Information Criterion, value of Consistent Akaike Information Criterion, value of Bayesian Information Criterion, value of Hannan Quinn Information Criterion, Cramer von Misses statistic value, Anderson Darling statistic value, minimum value of the negative log likelihood, Kolmogorov Smirnov statistic value, its p value and convergence status of the minimization of the negative log likelihood.

The output for the fitted wrapped normal distribution is as follows.

The output for the fitted wrapped logistic distribution is as follows.

The output for the fitted wrapped Gumbel distribution is as follows.

The output for the fitted wrapped Laplace distribution is as follows.

The output for the fitted wrapped Student’s t distribution is as follows.

The standard errors appear small compared to the parameter estimates for each fitted distribution. An exception is the Student’s t wrapped distribution. Also the p-value for each fitted distribution appears acceptable at the five percent significance level.

The wrapped normal distribution gives the smallest values for the Cramer von Misses statistic, Anderson Darling statistic, Akaike Information Criterion, Consistent Akaike Information Criterion, Bayesian Information Criterion, Hannan Quinn information criterion and the minimum of the negative log likelihood function. But the wrapped logistic distribution gives the smallest Kolmogorov Smirnov test statistic and the largest p-value.

The computations of the PDFs, CDFs and quantile functions are based on the approximate PDF and CDF. We now check to the goodness of these approximations and recommend a value for K. Fig 5 plots the relative errors of the approximate PDF and CDF versus K = 100, 200,…,10000. It also plots the central processing unit time for 100 computations of the approximate PDF and CDF versus K = 100, 200,…,10000. The relative errors for the approximate PDF and CDF were computed as and respectively.

thumbnail
Fig 5.

Relative error of the approximate PDF (top left), and CDF (top right). Central processing unit time for 100 computations of the approximate PDF (bottom left), and CDF (right left).

https://doi.org/10.1371/journal.pone.0188512.g005

We see that the order of the relative errors is 10−10 when K = 100. Thereafter it decreases approximately linearly. The central processing unit times are less than 10 seconds when K = 100. Thereafter they increase approximately linearly.

In Fig 5, we have taken g and G to correspond to the beta normal wrapped distribution with a = 0, b = 1, c = 0.1 and d = 0.9. The figures were similar for other wrapped distributions and a wide range of parameter values. In particular, the order of the relative errors when K = 100 was always 10−10 and the central processing unit times when K = 100 were always less than 10 seconds. Furthermore, the variation with respect to K was always approximately linear. Hence, we recommend that users take K = 100.

Discussion

We do not claim that our package is an umbrella for other packages that analyze wrapped distributions. But other packages in R only implement the wrapped Cauchy, wrapped normal, wrapped skew normal, wrapped stable and wrapped normal mixtures distributions. Our package can compute the pdf, cdf, quantile function and random samples for any given parametric forms for g and G (that is, parametric forms for which the functions dg, pg, qg and rg are available in the base package of R or one of its contributed packages). Our package can also compute the following for 41 different wrapped distributions: maximum likelihood estimates of the parameters, standard errors, 95 percent confidence intervals, value of Cramer von Misses statistic, value of Anderson Darling statistic, value of Kolmogorov Smirnov test statistic and its p-value, value of Akaike Information Criterion, value of Consistent Akaike Information Criterion, value of Bayesian Information Criterion, value of Hannan Quinn Information Criterion, minimum value of the negative log likelihood function and convergence status when some data are fitted by the wrapped distribution. Hence, our package is a lot more applicable.

If the chosen g and G do not belong to one of the 41 distributions mentioned here, then our package will need updating to allow performing estimation. Nevertheless, the pdf, cdf, quantile function and random samples of the wrapped distribution can still be computed for the chosen g and G as long as the functions dg, pg, qg and rg are available in the base package of R or one of its contributed packages.

A future work is to develop similar R packages for bivariate and multivariate wrapped distributions. Another future work is to extend the package to cases when g is defined on domains different from the entire real line or when g is the probability mass function of a discrete random variable.

Acknowledgments

The authors would like to thank the two referees and the Editor for careful reading and comments which greatly improved the paper.

References

  1. 1. Franke J, Redenbach C, Zhang N. On a Mixture Model for Directional Data on the Sphere. Scandinavian Journal of Statistics. 2016;43(1):139–155.
  2. 2. Schulz J, Jung S, Huckemann S, Pierrynowski M, Marron JS, Pizer SM. Analysis of Rotational Deformations From Directional Data. Journal of Computational and Graphical Statistics. 2015;24(2):539–560.
  3. 3. Uesu K, Shimizu K, SenGupta A. A possibly asymmetric multivariate generalization of the Mobius distribution for directional data. Journal of Multivariate Analysis. 2015;134:146–162.
  4. 4. Wang F, Gelfand AE. Modeling Space and Space-Time Directional Data Using Projected Gaussian Processes. Journal of the American Statistical Association. 2014;109(508):1565–1580.
  5. 5. Sengupta A, Ong SH. A Unified Approach for Construction of Probability Models for Bivariate Linear and Directional Data. Communications in Statistics—Theory and Methods. 2014;43(10-12, SI):2563–2569.
  6. 6. Breitenberger E. Analogues of the Normal Distribution on the Circle and the Sphere. Biometrika. 1963;50:81–88.
  7. 7. Mardia K. Statistics of Directional Data. Academic Press; 1972.
  8. 8. Pewsey A. The Wrapped Skew-Normal Distribution on the Circle. Communications in Statistics—Theory and Methods. 2000;29:2459–2472.
  9. 9. Jammalamadaka S, Kozubowski T. Families of Wrapped Distributions for Modeling Skew Circular Data. Communications in Statistics—Theory and Methods. 2004;33:2059–2074.
  10. 10. Pewsey A. The Wrapped Stable Family of Distributions as a Flexible Model for Circular Data. Computational Statistics and Data Analysis. 2008;52:1516–1523.
  11. 11. Coelho C. Sums and Linear Combinations of Independent Gamma and Laplace Distributions. Journal of Statistical Theory and Practice. 2007;1:1–29.
  12. 12. Pewsey A, Lewis T, Jones M. The Wrapped t Family of Circular Distributions. Australian and New Zealand Journal of Statistics. 2007;49:79–91.
  13. 13. Sarma R, Rao A, Girija S. On Characteristic Functions of the Wrapped Lognormal and the Wrapped Weibull Distributions. Journal of Statistical Computation and Simulation. 2011;81:579–589.
  14. 14. Jayakumar K, Jacob S. Wrapped Skew Laplace Distribution on Integers: A New Probability Model for Circular Data. Open Journal of Statistics. 2012;2:106–114.
  15. 15. Roy S, Adnan M. Wrapped Weighted Exponential Distributions. Statistics and Probability Letters. 2012;82:77–83.
  16. 16. Adnan M, Roy S. Wrapped Hypo Exponential Distribution. Journal of Statistics and Management Systems. 2013;16:1–11.
  17. 17. Jacob S, Jayakumar K. Wrapped Geometric Distribution: A New Probability Model for Circular Data. Journal of Statistical Theory and Applications. 2013;12:348–355.
  18. 18. Girija S, Rao A, Srihari G. On characteristic Function of Wrapped Poisson Distribution. International Journal of Mathematical Archive. 2014;5:168–173.
  19. 19. Thavaneswaran A, Mandal S, Pathmanathan D. Estimation for Wrapped Zero Inflated Poisson and Wrapped Poisson Distributions. International Journal of Statistics and Probability. 2016;5:1–8.
  20. 20. Joshi S, Jose K. Wrapped Lindley Distribution. Communications in Statistics—Theory and Methods. 2017;.
  21. 21. R Development Core Team. R: A Language and Environment for Statistical Computing; 2017. Available from: http://www.R-project.org.
  22. 22. Oliveira M, Crujeiras R, Rodriguez-Casal A. NPCirc: Nonparametric Circular Methods; 2014. Available from: https://CRAN.R-project.org/package=NPCirc.
  23. 23. Agostinelli C. wle: Weighted Likelihood Estimation; 2015. Available from: https://CRAN.R-project.org/package=wle.
  24. 24. Lund U, Agostinelli C. circular: Circular Statistics; 2013. Available from: https://CRAN.R-project.org/package=circular.
  25. 25. Lund U, Agostinelli C. CircStats: Circular Statistics, from “Topics in Circular Statistics” (2001); 2012. Available from: https://CRAN.R-project.org/package=CircStats.
  26. 26. Chakraborty S, Wong S. BAMBI: Bivariate Angular Mixture Models; 2017. Available from: https://CRAN.R-project.org/package=BAMBI.
  27. 27. Michelot T, Langrock R, Patterson T, Rexstad E. movehMM: Animal Movement Modelling using Hidden Markov Models; 2017. Available from: https://CRAN.R-project.org/package=moveHMM.
  28. 28. Chubaty A, McIntire E, Luo Y, Cumming S, Michelot T, Langrock R, et al. SpaDES: Develop and Run Spatially Explicit Discrete Event Simulation Models; 2016. Available from: https://CRAN.R-project.org/package=SpaDES.
  29. 29. Nadarajah S, Zhang Y. Wrapped: Computes Pdf, Cdf, Quantile, Random Numbers and Provides Estimation for Univariate Wrapped Distributions; 2017. Available from: https://CRAN.R-project.org/package=Wrapped.
  30. 30. Gauss C. Theoria Motvs Corporvm Coelestivm in Sectionibvs Conicis Solem Ambientivm (in Latin). 1809;.
  31. 31. de Moivre A. The Doctrine of Chances. 1738;.
  32. 32. Gumbel E. Statistical Theory of Extreme Values and Some Practical Applications. Applied Mathematics Series. 1954;33.
  33. 33. Stephenson A, Ferro C. evd: Functions for Extreme Value Distributions; 2015. Available from: https://CRAN.R-project.org/package=evd.
  34. 34. Student. The Probable Error of a Mean. Biometrika. 1908;6:1–25.
  35. 35. Ellison S. metRology: Support for Metrological Applications; 2016. Available from: https://CRAN.R-project.org/package=metRology.
  36. 36. Azzalini A. A Class of Distributions Which Includes the Normal Ones. Scandinavian Journal of Statistics. 1985;12:171–178.
  37. 37. Azzalini A. sn: The Skew-Normal and Skew-t Distributions; 2016. Available from: https://CRAN.R-project.org/package=sn.
  38. 38. Azzalini A, Capitanio A. Distributions Generated by Perturbation of Symmetry with Emphasis on a Multivariate Skew-t Distribution. Journal of the Royal Statistical Society B. 2003;65:367–389.
  39. 39. Yu K, Zhang J. A Three-Parameter Asymmetric Laplace Distribution and Its Extension. Communications in Statistics-Theory and Methods. 2005;34:1867–1879.
  40. 40. Galarza C, Lachos V. ald: The Asymmetric Laplace Distribution; 2016. Available from: https://CRAN.R-project.org/package=ald.
  41. 41. Reed W. The Normal-Laplace Distribution and Its Relatives. Advances in Distribution Theory, Order Statistics and Inference. 2006; p. 61–74.
  42. 42. Scott D, Fu J, Potter S. NormalLaplace: The Normal Laplace Distribution; 2015. Available from: https://CRAN.R-project.org/package=NormalLaplace.
  43. 43. Johnson N, Kotz S, Balakrishnan N. Continuous Univariate Distributions, volume 2. John Wiley and Sons; 1995.
  44. 44. Zeileis A, Windberger T. glogis: Fitting and Testing Generalized Logistic Distributions; 2014. Available from: https://CRAN.R-project.org/package=glogis.
  45. 45. van Staden P, King R. The Quantile-based Skew Logistic Distribution. Statistics and Probability Letters. 2015;96:109–116.
  46. 46. King R, van Staden P. sld: Estimation and Use of the Quantile-Based Skew Logistic Distribution; 2016. Available from: https://CRAN.R-project.org/package=sld.
  47. 47. Mineo A. normalp: Routines for Exponential Power Distribution; 2014. Available from: https://CRAN.R-project.org/package=normalp.
  48. 48. Rigby R, Stasinopoulos D. Generalized Additive Models for Location, Scale and Shape (with Discussion). Applied Statistics. 2005;54:507–554.
  49. 49. Stasinopoulos M, Rigby M. gamlss.dist: Distributions to be Used for GAMLSS Modelling; 2016. Available from: https://CRAN.R-project.org/package=gamlss.dist.
  50. 50. Azzalini A. Further Results on a Class of Distributions which Includes the Normal Ones. Statistica. 1986;46:199–208.
  51. 51. Fernandez C, Steel M. On Bayesian Modelling of Fat Tails and Skewness. Journal of the American Statistical Association. 1998;93:359–372.
  52. 52. Jammalamadaka S, SenGupta A. Topics in Circular Statistics. World Scientific Publishing Company; 2001.
  53. 53. Jones M. Discussion of Rigby and Stasinopoulos (2005). Applied Statistics. 2006;54:546–547.
  54. 54. Jones M, Pewsey A. Sinh-Arcsinh Distributions. Biometrika. 2009;96:761–780.
  55. 55. McDonald J, Xu Y. A Generalisation of the Beta Distribution with Applications. Journal of Econometrics. 1995;66:133–152.
  56. 56. Johnson N. Systems of Frequency Curves Derived from the First Law of Laplace. Trabajos de Estadistica. 1954;5:283–291.
  57. 57. Theodossiou P. Financial Data and the Skewed Generalized t Distribution. Management Science. 1998;44:1650–1661.
  58. 58. Davis C. sgt: Skewed Generalized T Distribution Tree; 2015. Available from: https://CRAN.R-project.org/package=sgt.
  59. 59. Aas K, Haff I. The Generalised Hyperbolic Skew Student’s t-Distribution. Journal of Financial Econometrics. 2006;4:275–309.
  60. 60. Davis C, Grimson F. SkewHyperbolic: The Skew Hyperbolic Student t-Distribution; 2015. Available from: https://CRAN.R-project.org/package=SkewHyperbolic.
  61. 61. S K, TJ K, K P. The Laplace Distribution and Generalizations: A Revisit with Applications to Communications, Economics, Engineering, and Finance. Birkhauser; 2001.
  62. 62. Chen W, Zaretzki R, Howell W, Landerer C, Schmidt D, Gilchrist M, et al. cubfits: Codon Usage Bias Fits; 2016. Available from: https://CRAN.R-project.org/package=cubfits.
  63. 63. Geraci M, Bottai M. Quantile Regression for Longitudinal Data using the Asymmetric Laplace Distribution. Biostatistics. 2007;8:140–154. pmid:16636139
  64. 64. Geraci M. lqmm: Linear Quantile Mixed Models; 2016. Available from: https://CRAN.R-project.org/package=lqmm.
  65. 65. Curry E. LCA: Localised Co-Dependency Analysis; 2013. Available from: https://CRAN.R-project.org/package=LCA.
  66. 66. Paolella M. Tail Estimation and Conditional Modeling of Heteroskedstic Time-Series. Institute of Statistics and Econometrics. Christian Albrechts University of Kiel; 1997.
  67. 67. Sousa T, Otiniano C, Lopes S, Wuertz D. GEVStableGarch: ARMA-GARCH/APARCH Models with GEV and Stable Distributions; 2015. Available from: https://CRAN.R-project.org/package=GEVStableGarch.
  68. 68. Barndorff-Nielsen O. Exponentially Decreasing Distributions for the Logarithm of Particle Size. Proceedings of the Royal Society of London: Series A, Mathematical and Physical Sciences. 1977;353:401–409.
  69. 69. Scott D, Dong C. VarianceGamma: The Variance Gamma Distribution; 2015. Available from: https://CRAN.R-project.org/package=VarianceGamma.
  70. 70. Scott D. GeneralizedHyperbolic: The Generalized Hyperbolic Distribution; 2015. Available from: https://CRAN.R-project.org/package=GeneralizedHyperbolic.
  71. 71. Fieller N, Flenley E, Olbricht W. Statistics of Particle Size Data. Applied Statistics. 1992;41:127–146.
  72. 72. Johnson N, Kotz S, Balakrishnan N. Continuous Univariate Distributions, volume 1. John Wiley and Sons; 1994.
  73. 73. Yee T. VGAM: Vector Generalized Linear and Additive Models; 2017. Available from: https://CRAN.R-project.org/package=VGAM.
  74. 74. Gupta A, Nadarajah S. Handbook of Beta Distribution and Its Applications. Marcel Dekker; 2004.
  75. 75. Akkaya A, Tiku M. Short-Tailed Distributions and Inliers. Test. 2008;17:282–296.
  76. 76. Genter F, Farewell V. Short-Tailed Distributions and Inliers. The Canadian Journal of Statistics. 1985;13:37–44.
  77. 77. Haubo R, Christensen B. ordinal: Regression Models for Ordinal Data; 2015. Available from: https://CRAN.R-project.org/package=ordinal.
  78. 78. Marinho P, Bourguignon M, Cicero Rafael Barros Dias C. AdequacyModel: Adequacy of Probabilistic Models and General Purpose Optimization; 2016. Available from: https://CRAN.R-project.org/package=AdequacyModel.
  79. 79. Delignette-Muller M, Dutang C, Pouillot R, Denis J, Siberchicot A. fitdistrplus: Help to Fit of a Parametric Distribution to Non-Censored or Censored Data; 2017. Available from: https://CRAN.R-project.org/package=fitdistrplus.
  80. 80. Fisher N, Powell C. Statistical Analysis of Two-Dimensional Palaeocurrent Data: Methods and Examples. Australian Journal of Earth Sciences. 1989;36:91–107.