/quantile

Agnostic (re)implementations (R/SAS/Python/C) of common quantile estimation algorithms.

Primary LanguagePythonEuropean Union Public License 1.1EUPL-1.1

DOI quantile

Software-agnostic (re)implementations of common quantile estimation algorithms

This material is meant as a proof of concept for Grazzini and Lamarche's article and aims at promoting software/language-agnostic development and deployment of statistical processes.

Rationale

We consider here the implementation of quantile estimates based on order statistics. Although quantiles are often implemented throughout various packages of statistical software (R, Python, SAS, Stata, Maple, etc...), the different implementations may not be consistent with each other and, therefore, provide different output estimates. Typically, this happens because different estimation methods are available in the literature, and each one of them corresponds to a specific implementation.

Let us consider, for instance, the (broad) range of techniques for quantile estimation implemented ad-hoc in both SAS and R software. They are respectively made available through the SAS procedure UNIVARIATE and the R function quantile, whose documentations are displayed below:

SAS UNIVARIATE R quantile
doc SAS doc R

Looking at which of Hyndman and Fan's (HF#n), Cunnane's (C), and/or Filliben's (F) algorithms (see references below) are actually available (or not: n.a.) on either software, it appears that there is no one-to-one correspondance between the implementations:

algorithm HF#1 HF#2 HF#3 HF#4 HF#5 HF#6 HF#7 HF#8 HF#9 C F
quantile type 1 2 3 4 5 6 7 8 9 n.a. n.a.
UNIVARIATE PCTLDEF 3 5 2 1 n.a. 4 n.a. n.a. n.a. n.a. n.a.

In particular, the algorithms implemented by default (i.e., when no parameter type, or PCTLDEF, is passed) differ, since indeed HF#7 (type=7) is the default algorithm in R quantile implementation, while HF#2 (PCTLDEF=5) is the default one in SAS UNIVARIATE implementation. Similarly, note that Python method mquantiles implements Cunnane's algorithm as its default option (through (α,β)=(.4,.4) parameter).

Altogether, a user may be left at a disadvantage since he may neither understand all the implications of the estimation process – depending on which platform he performs his calculations, depending on whether he chooses default parameters or not, ... – nor how to test the validity of results produced by the software. A stronger control of the practical and effective implementation of statistical methods and techniques is required.

Objectives

We propose to go back to the original algorithms and provide with a canonical implementation of quantile estimates on different software platforms and/or using different programming languages, so as to show that a consistent implementation is possible accross platforms. In practice, we implement 10 algorithms, 9 derived from Hyndman and Fan's framework, plus 1 described in Cunnane's article and 1 proposed by Filiben, in R, Python, C and SAS. To do so, we either extend/complement (wrap) already existing implementations for quantile estimation (R function quantile, Python method mquantiles, C function gsl_stats, or SAS procedure UNIVARIATE), or actually reimplement the algorithm from scratch (SAS, C and Python). In the former case, we provide with consistent parameterisation/configuration accross the different software so as to ensure consistency and transparency for the user.

However, unnecessary duplication (the same algorithm is being, above, implemented on 4 different platforms) shall be avoided, and, instead the choice of statistical software/packages should be transparent to the user, i.e. the quantile estimation should be provided in a "software-agnostic" manner. To this end, we show that it is possible to easily implement microservices (SOA) that run the quantile estimation (either operated using R or Python) through a web interface (shiny for R, flask for Python).

About

documentation available at: https://eurostat.github.io/quantile/
version 0.9
status since Thu Jan 5 10:22:03 2017 – closed
contributors
license EUPL (cite the source code or the reference above!)

References