Skip to content

Commit

Permalink
version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
swihart authored and cran-robot committed Aug 14, 2023
0 parents commit 298da7c
Show file tree
Hide file tree
Showing 35 changed files with 6,132 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Package: libstable4u
Version: 1.0.2
Date: 2023-07-30
Title: Stable Distribution Functions...For You
Authors@R: c(
person("Javier", "Royuela del Val", role = c("aut")),
person("Federico", "Simmross-Wattenberg", role = "aut"),
person("Carlos", "Alberola López", role = "aut"),
person("Bob", "Rudis", role = "ctb", comment = "Several bugs fixed and added macOS compatibility"),
person("Bruce", "Swihart", role = c("ctb","cre"), email = "bruce.swihart@gmail.com", comment = "Several bugs fixed and added macOS compatibility"))
Description: Tools for fast and accurate evaluation of skew stable distributions
(CDF, PDF and quantile functions), random number generation, and parameter
estimation. This is 'libstableR' as per Royuela del Val, Simmross-Wattenberg,
and Alberola López (2017) <doi:10.18637/jss.v078.i01> under a new maintainer.
Author: Javier Royuela del Val [aut],
Federico Simmross-Wattenberg [aut],
Carlos Alberola López [aut],
Bob Rudis [ctb] (Several bugs fixed and added macOS compatibility),
Bruce Swihart [ctb, cre] (Several bugs fixed and added macOS
compatibility)
License: GPL-3
Imports: Rcpp (>= 0.12.9)
LinkingTo: Rcpp, RcppGSL
SystemRequirements: GNU GSL
Encoding: UTF-8
NeedsCompilation: yes
Maintainer: Bruce Swihart <bruce.swihart@gmail.com>
Repository: CRAN
RoxygenNote: 7.2.1
Suggests: testthat
Packaged: 2023-08-11 14:17:32 UTC; bruce
Date/Publication: 2023-08-14 08:50:02 UTC
34 changes: 34 additions & 0 deletions MD5
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
b1dc3a24f10e27c9d4b858ed660685b5 *DESCRIPTION
15ae49177bef8caae852efb3cacc2687 *NAMESPACE
d470f53ffb063dfad64cf69df1b480da *NEWS.md
be94a383285ccfa41fb39421d98bdcb2 *R/RcppExports.R
1384d637ac4ca5c16f415f731a2387fa *R/libstable4u-pkg.r
027e8f59840a17710f16fb178a4b4430 *demo/00Index
9c9c187b3fc20b9825b33dccf65d8a83 *demo/libstable4u_demo.R
2dea68e1b3905bfbe92842394f79f9a0 *inst/CITATION
dafffffef0bc305f9747cd58b3e686e9 *man/libstable4u.Rd
59ebda57644630ef107df8d5f9866059 *man/stable_fit.Rd
c20aead0e493daa2191ce340fb884f8a *man/stable_pdf_and_cdf.Rd
e9750952f96753e0802abe5c447d4187 *man/stable_q.Rd
68773d6596ae684ba17fca075ed92ae4 *man/stable_rnd.Rd
ea23ea2a1d8638bc8e095aaea8bbd943 *src/Makevars
609a1b18d56e547625d73675f5d8125f *src/RcppExports.cpp
c0c5b95f8dac7376b29802b624d63146 *src/mcculloch.c
a820b5f0f12af98e50aa79db4243b793 *src/mcculloch.h
a7c8080b609d51a8c3f33fad4bb89d83 *src/methods.c
6ae1fe5df27f307dabe7ba13ea178484 *src/methods.h
48aaa55aec84d21ec40fe67722ee69f7 *src/stable.h
c6920925bca9c20a13885051cd5bd62f *src/stable_R.cpp
0b4d755d69d9daa1eef48dbc74ad890a *src/stable_cdf.c
8c19b32ffd56269c34db070b51ad8251 *src/stable_common.c
0942e6eeba0e8464d1cae1fb39fdb1ae *src/stable_dist.c
fc9c67363a585715bf45eac31b3d4ef9 *src/stable_fit.c
e453f4516766b7287609c052389ca7ba *src/stable_fit.h
fabe616c7f30b3e769e7402b5d2aa583 *src/stable_integration.c
f60ae7b92d5965fb417ec9168177b6a4 *src/stable_integration.h
602c7881db70969222a2dced8c2ae39b *src/stable_koutrouvelis.c
1aeee1acd665933ad8623fa8c0707858 *src/stable_pdf.c
316f8181470ce89d304a2103cfa7fdab *src/stable_q.c
0b0a55f0408b7ff5cd94755cf5c8a844 *src/stable_rnd.c
0e8f7d1a818cd996497e07ff938b27ea *tests/testthat.R
591b8c85fbaa87a2f9760ae14f0e559f *tests/testthat/test-stable-df.R
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(stable_cdf)
export(stable_fit_init)
export(stable_fit_koutrouvelis)
export(stable_fit_mle)
export(stable_fit_mle2d)
export(stable_pdf)
export(stable_q)
export(stable_rnd)
importFrom(Rcpp,evalCpp)
importFrom(Rcpp,sourceCpp)
useDynLib(libstable4u, .registration=TRUE)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
------------------------------------------------------------------------------
version 1.0.2
------------------------------------------------------------------------------

* Posted as copy of (recently archived) `libstableR v1.0.2` + minor edits for CRAN acceptance
168 changes: 168 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @md
#' @name stable_pdf_and_cdf
#' @aliases stable_cdf stable_pdf
#' @title PDF and CDF of a skew stable distribution.
#' @description Evaluate the PDF or the CDF of the skew stable distribution with parameters
#' pars = c(alpha, beta, sigma, mu) at the points given in x.\cr\cr
#' _parametrization_ argument specifies the parametrization used for the distribution
#' as described by JP Nolan (1997). The default value is _parametrization_ = 0.\cr\cr
#' _tol_ sets the relative error tolerance (precision) to _tol_. The default value is tol = 1e-12.
#' @param x Vector of points where the pdf will be evaluated.
#' @param pars Vector with an initial estimation of the parameters. `pars_init = c(alpha, beta, sigma, mu)`, where
#' * alpha: shape / stability parameter, with 0 < alpha <= 2.
#' * beta: skewness parameter, with -1 <= beta <= 1.
#' * sigma: scale parameter, with 0 < sigma.
#' * mu: location parameter, with mu real.
#' @param parametrization Parametrization used for the skew stable distribution, as defined by JP Nolan (1997). By default, parametrization = 0.
#' @param tol Relative error tolerance (precission) of the calculated values. By default, tol = 1e-12.
#' @return A numeric vector.
#' @author Javier Royuela del Val, Federico Simmross Wattenberg and Carlos Alberola López\cr\cr
#' Maintainer: Javier Royuela del Val <jroyval@@lpi.tel.uva.es>
#' @references Nolan JP (1997). Numerical Calculation of Stable Densities and Distribution Functions. Stochastic Models, 13(4) 759-774.
#' @keywords distribution
#' @examples
#' pars <- c(1.5, 0.9, 1, 0)
#' x <- seq(-5, 10, 0.001)
#'
#' pdf <- stable_pdf(x, pars)
#' cdf <- stable_cdf(x, pars)
#'
#' plot(x, pdf, type = "l")
#' @export
stable_pdf <- function(x, pars, parametrization = 0L, tol = 1e-12) {
.Call(`_libstable4u_stable_pdf`, x, pars, parametrization, tol)
}

#' @export
stable_cdf <- function(x, pars, parametrization = 0L, tol = 1e-12) {
.Call(`_libstable4u_stable_cdf`, x, pars, parametrization, tol)
}

#' @md
#' @title Quantile function of skew stable distributions
#' @description Evaluate the quantile function (CDF^-1) of the skew stable distribution
#' with parameters pars = c(alpha, beta, sigma, mu) at the points given in p.\cr\cr
#' _parametrization_ argument specifies the parametrization used for the distribution
#' as described by JP Nolan (1997). The default value is _parametrization_ = 0.\cr\cr
#' _tol_ sets the relative error tolerance (precission) to _tol_. The default value is tol = 1e-12.
#' @param p Vector of points where the quantile function will be evaluated, with 0 < p\[i] < 1.0
#' @param pars Vector with an initial estimation of the parameters. `pars_init = c(alpha, beta, sigma, mu)`, where
#' * alpha: shape / stability parameter, with 0 < alpha <= 2.
#' * beta: skewness parameter, with -1 <= beta <= 1.
#' * sigma: scale parameter, with 0 < sigma.
#' * mu: location parameter, with mu real.
#' @param parametrization Parametrization used for the skew stable distribution, as defined by JP Nolan (1997). By default, parametrization = 0.
#' @param tol Relative error tolerance (precission) of the calculated values. By default, tol = 1e-12.
#' @return A numeric vector.
#' @author Javier Royuela del Val, Federico Simmross Wattenberg and Carlos Alberola López\cr\cr
#' Maintainer: Javier Royuela del Val <jroyval@@lpi.tel.uva.es>
#' @keywords distribution
#' @export
stable_q <- function(p, pars, parametrization = 0L, tol = 1e-12) {
.Call(`_libstable4u_stable_q`, p, pars, parametrization, tol)
}

#' @md
#' @title Skew stable distribution random sample generation.
#' @description `stable_rnd(N, pars)` generates N random samples of a skew stable distribuiton
#' with parameters pars = c(alpha, beta, sigma, mu) using the Chambers, Mallows,
#' and Stuck (1976) method.\cr\cr
#' @param N Number of values to generate.
#' @param pars Vector with an initial estimation of the parameters. `pars_init = c(alpha, beta, sigma, mu)`, where
#' * alpha: shape / stability parameter, with 0 < alpha <= 2.
#' * beta: skewness parameter, with -1 <= beta <= 1.
#' * sigma: scale parameter, with 0 < sigma.
#' * mu: location parameter, with mu real.
#' @param parametrization Parametrization used for the skew stable distribution, as defined by JP Nolan (1997). By default, parametrization = 0.
#' @references Chambers JM, Mallows CL, Stuck BW (1976). A Method for Simulating Stable Random Variables. Journal of the American Statistical Association, 71(354), 340-344. doi:10.1080/01621459.1976.10480344.
#' @return A numeric vector.
#' @author Javier Royuela del Val, Federico Simmross Wattenberg and Carlos Alberola López\cr\cr
#' Maintainer: Javier Royuela del Val <jroyval@@lpi.tel.uva.es>
#' @keywords distribution
#' @examples
#' N <- 1000
#' pars <- c(1.25, 0.95, 1.0, 0.0)
#' rnd <- stable_rnd(N, pars)
#'
#' hist(rnd)
#' @export
stable_rnd <- function(N, pars, parametrization = 0L) {
.Call(`_libstable4u_stable_rnd`, N, pars, parametrization)
}

#' @md
#' @title Methods for parameter estimation of skew stable distributions.
#' @name stable_fit
#' @aliases stable_fit_init stable_fit_koutrouvelis stable_fit_mle stable_fit_mle2d
#' @description A set of functions are provided that perform the parameter estimation of skew stable distributions with different methods.
#' @details
#' * `stable_fit_init()` uses McCulloch's method of quantiles \[3]. This is usually a good initialization for the rest of the methods.
#' * `stable_fit_koutrouvelis()` implements Koutrouvellis' method based on the characteristic function \[4].
#' * `stable_fit_mle()` implements a Maximum likelihood estimation.
#' * `stable_fit_mle2()` implements a modified maximum likelihood estimation as described in \[1].
#' @param rnd Random sample
#' @param parametrization Parametrization used for the skew stable distribution, as defined by JP Nolan (1997). By default, parametrization = 0.
#' @return A numeric vector.
#' @references
#' * \[1] Royuela-del-Val J, Simmross-Wattenberg F, Alberola López C (2017). libstable: Fast, Parallel and High-Precision Computation of alpha-stable Distributions in R, C/C++ and MATLAB. Journal of Statistical Software, 78(1), 1-25. doi:10.18637/jss.v078.i01
#' * \[2] Chambers JM, Mallows CL, Stuck BW (1976). A Method for Simulating Stable Random Variables. Journal of the American Statistical Association, 71(354), 340-344. doi:10.1080/01621459.1976.10480344.
#' * \[3] McCulloch JH (1986). Simple Consistent Estimators of Stable Distribution Parameters. Communications in Statistics - Simulation and Computation, 15(4), 1109-1136. doi:10.1080/03610918608812563.
#' * \[4] Koutrouvelis IA (1981). An Iterative Procedure for the Estimation of the Parameters of Stable Laws. Communications in Statistics - Simulation and Computation, 10(1), 17-28. doi:10.1080/03610918108812189.
#' * \[5] Nolan JP (1997). Numerical Calculation of Stable Densities and Distribution Functions. Stochastic Models, 13(4) 759-774. doi:10.1080/15326349708807450.
#' @keywords distribution
#' @author Javier Royuela del Val, Federico Simmross Wattenberg and Carlos Alberola López\cr\cr
#' Maintainer: Javier Royuela del Val <jroyval@@lpi.tel.uva.es>
#' @examples
#' # Set alpha, beta, sigma and mu stable parameters in a vector
#' pars <- c(1.5, 0.9, 1, 0)
#'
#' # Generate random values
#' set.seed(1)
#' rnd <- stable_rnd(100, pars)
#' head(rnd)
#'
#' # Estimate the parameters of the skew stable distribution given
#' # the generated sample:
#'
#' # Using the McCulloch's estimator:
#' pars_init <- stable_fit_init(rnd)
#'
#' # Using the Koutrouvelis' estimator, with McCulloch estimation
#' # as a starting point:
#' pars_est_K <- stable_fit_koutrouvelis(rnd, pars_init)
#'
#' # Using maximum likelihood estimator:
#' pars_est_ML <- stable_fit_mle(rnd, pars_est_K)
#'
#' # Using modified maximum likelihood estimator (see [1]):
#' pars_est_ML2 <- stable_fit_mle2d(rnd, pars_est_K)
#' @export
stable_fit_init <- function(rnd, parametrization = 0L) {
.Call(`_libstable4u_stable_fit_init`, rnd, parametrization)
}

#' @md
#' @rdname stable_fit
#' @param pars_init Vector with an initial estimation of the parameters. `pars_init = c(alpha, beta, sigma, mu)`, where
#' * alpha: shape / stability parameter, with 0 < alpha <= 2.
#' * beta: skewness parameter, with -1 <= beta <= 1.
#' * sigma: scale parameter, with 0 < sigma.
#' * mu: location parameter, with mu real.
#' @export
stable_fit_koutrouvelis <- function(rnd, pars_init = as.numeric( c()), parametrization = 0L) {
.Call(`_libstable4u_stable_fit_koutrouvelis`, rnd, pars_init, parametrization)
}

#' @export
stable_fit_mle <- function(rnd, pars_init = as.numeric( c()), parametrization = 0L) {
.Call(`_libstable4u_stable_fit_mle`, rnd, pars_init, parametrization)
}

#' @export
stable_fit_mle2d <- function(rnd, pars_init = as.numeric( c()), parametrization = 0L) {
.Call(`_libstable4u_stable_fit_mle2d`, rnd, pars_init, parametrization)
}

64 changes: 64 additions & 0 deletions R/libstable4u-pkg.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#' libstable4u: Fast and accurate evaluation, random number generation
#' and parameter estimation of skew stable distributions.
#'
#' libstable4u provides functions to work with skew stable distributions
#' in a fast and accurate way \[1]. It performs:
#'
#' * Fast and accurate evaluation of the probability density function (PDF) and cumulative density function (CDF).
#' * Fast and accurate evaluation of the quantile function (CDF^{-1}).
#' * Random numbers generation \[2].
#' * Skew stable parameter estimation with:
#' * McCulloch's method of quantiles \[3].
#' * Koutrouvellis' method based on the characteristic function \[4].
#' * Maximum likelihood estimation.
#' * Modified maximum likelihood estimation as described in \[1].
#' *The evaluation of the PDF and CDF is based on the formulas provided by John P Nolan in \[5].
#'
#' @md
#' @author Javier Royuela del Val, Federico Simmross Wattenberg and Carlos Alberola López;\cr\cr
#' Maintainer: Javier Royuela del Val <jroyval@@lpi.tel.uva.es>
#' @references
#' * \[1] Royuela-del-Val J, Simmross-Wattenberg F, Alberola López C (2017). libstable: Fast, Parallel and High-Precision Computation of alpha-stable Distributions in R, C/C++ and MATLAB. Journal of Statistical Software, 78(1), 1-25. doi:10.18637/jss.v078.i01
#' * \[2] Chambers JM, Mallows CL, Stuck BW (1976). A Method for Simulating Stable Random Variables. Journal of the American Statistical Association, 71(354), 340-344. doi:10.1080/01621459.1976.10480344
#' * \[3] McCulloch JH (1986). Simple Consistent Estimators of Stable Distribution Parameters. Communications in Statistics - Simulation and Computation, 15(4), 1109-1136. doi:10.1080/03610918608812563
#' * \[4] Koutrouvelis IA (1981). An Iterative Procedure for the Estimation of the Parameters of Stable Laws. Communications in Statistics - Simulation and Computation, 10(1), 17-28. doi:10.1080/03610918108812189
#' * \[5] Nolan JP (1997). Numerical Calculation of Stable Densities and Distribution Functions. Stochastic Models, 13(4), 759-774. doi:10.1080/15326349708807450
#' @name libstable4u
#' @docType package
#' @keywords package
#' @useDynLib libstable4u, .registration=TRUE
#' @importFrom Rcpp sourceCpp evalCpp
#' @examples
#' # Set alpha, beta, sigma and mu stable parameters in a vector
#' pars <- c(1.5, 0.9, 1, 0)
#'
#' # Generate an abscissas axis and probabilities vector
#' x <- seq(-5, 10, 0.05)
#' p <- seq(0.01, 0.99, 0.01)
#'
#' # Calculate pdf, cdf and quantiles
#' pdf <- stable_pdf(x, pars)
#' cdf <- stable_cdf(x, pars)
#' xq <- stable_q(p, pars)
#'
#' # Generate random values
#' set.seed(1)
#' rnd <- stable_rnd(100, pars)
#' head(rnd)
#'
#' # Estimate the parameters of the skew stable distribution given
#' # the generated sample:
#'
#' # Using the McCulloch's estimator:
#' pars_init <- stable_fit_init(rnd)
#'
#' # Using the Koutrouvelis' estimator, with McCulloch estimation
#' # as a starting point:
#' pars_est_K <- stable_fit_koutrouvelis(rnd, pars_init)
#'
#' # Using maximum likelihood estimator:
#' pars_est_ML <- stable_fit_mle(rnd, pars_est_K)
#'
#' # Using modified maximum likelihood estimator (see [1]):
#' pars_est_ML2 <- stable_fit_mle2d(rnd, pars_est_K)
NULL
1 change: 1 addition & 0 deletions demo/00Index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libstable4u_demo libstable4u package demo

0 comments on commit 298da7c

Please sign in to comment.