2017-11-04

The R package extremeStat, available at github.com/brry, contains code to fit, plot and compare several (extreme value) distribution functions. It can also compute (truncated) distribution quantile estimates and draw a plot with return periods on a linear scale.

Main focus of this document:Quantile estimation via distribution fitting
Comparison of GPD implementations in several R packages

Note: in some disciplines, quantiles are called percentiles, but technically, percentiles are only one kind of quantiles (as are deciles, quartiles, etc).

Package installation

install.packages("extremeStat")
# install the development version from github:
berryFunctions::instGit("brry/berryFunctions")
berryFunctions::instGit("brry/extremeStat")

extremeStat has 33 dependencies, because of the GPD comparison across the packages.

Fitting distributions

The function distLfit fits 17 of the distribution types avalable in the R package lmomco (there are more, but some of these require quite a bit of computation time and are prone to not be able to be fitted to this type of data distribution anyways. Turn them on with speed=FALSE).

The parameters are estimated via L-moments. These are analogous to the conventional statistical moments (mean, variance, skewness and kurtosis), but “robust [and] suitable for analysis of rare events of non-Normal data. L-moments are consistent and often have smaller sampling variances than maximum likelihood in small to moderate sample sizes. L-moments are especially useful in the context of quantile functions” Asquith, W. (2015): lmomco package

distLfit ranks the distributions according to their goodness of fit (RMSE between ecdf and cdf), see section GOF.

The first 17 rows for each distribution function are sorted by their goodness of fit (see below). They each yield different results, epecially for very high quantile probailities (values that are exceeded very rarely). Note that the deviation from each other increases for badly fitted distributions.

The row quantileMean is an average of R’s 9 methods implemented in stats::quantile to determine empirical quantiles (order based statistic, keyword plotting positions).

The rows GPD_* are the General Pareto Distribution quantiles, as estimated by a range of different R packages and methods (specified in the row names), computed by q_gpd. More on that in the next section GPD.

The rows weighted* are averages of the quantiles estimated from the distribution functions, weighted by their goodness of fit (RMSE ecdf / cdf) in three default (and a custom) weighting schemes (see next section).

POT, GPD

The General Pareto Distribution (‘GPD’, or ‘gpa’ in the package lmomco) is often used to obtain parametric quantile values because of the Pickands-Balkema-DeHaan theorem. It states that the tails of many (empirical) distributions converge to the GPD if a Peak-Over-Threshold (POT) method is used, i.e. the distribution is fitted only to the largest values of a sample. The resulting percentiles can be called censored or truncated quantiles.

This package is based on the philosophy that, in order to compare parametric with empirical quantiles, the threshold must be at some percentage of the full sample. That way, the probabilities given to the quantile functions can be updated.
For example, if the censored Q0.99 ( p = 0.99 ) is to be computed from the top 20 % of the full dataset (the truncated proportion is 80%: t = 0.8 ), then Q0.95 ( p2 = 0.95 ) of the truncated sample must be used. The probability adjustment for censored quantiles with truncation percentage t happens with the equation \[ p2 = \frac{p-t}{1-t} \]

Truncation effect

To examine the effect of the truncation percentage, we can compute the quantiles for different cutoff percentages. This computes for a few minutes, so the code is not performed upon vignette creation. The result is loaded instead.

The 17 different distribution quantiles (and 11 different GPD estimates, not in figure) seem to converge with increasing truncation percentage. However, at least 5 remaining values in the truncated sample are necessary to fit distributions via L-moments, so don’t truncate too much. I found a good cutoff percentage is 0.8. If you fit to the top 20% of the data, you get good results, while needing ‘only’ approximately 25 values in a sample to infer a quantile estimate.

The goodness of fit also has an optimum (lowest RMSE) up to 0.8, before increasing again:

Sample size dependency

One motivation behind the development of this package is the finding that high empirical quantiles depend not only on the values of a sample (as it should be), but also on the number of observations available. That is not surprising: Given a distribution of a population, small samples tend to less often include the high (and rare) values. The cool thing about parametric quantiles is that they don’t systematically underestimate the actual quantile in small samples. Here’s a quick demonstration.

Extreme value statistics, Return Periods

Once you have a quantile estimator, you can easily compute extremes (= return levels) for given return periods.
A value x in a time series has a certain expected frequency to occur or be exceeded: the exceedance probability Pe. The Return Period (RP) of x can be computed as follows:

\[ RP = \frac{1}{Pe} = \frac{1}{1-Pne} \] From that follows for the probability of non-exceedance Pne: \[ Pne = 1 - \frac{1}{RP} \] The Return Level RL can be computed as \[ RL = quantile(x, ~~ prob=Pne) \] The Return Periods are given in years, thus if you use daily values in a POT approach, you should set npy=365.24, as the formula in this package uses \[ returnlev = distLquantile(x, ~~ probs=1-\frac{1}{RP*npy}) \]

An example with actual numbers (only valid in stationary cases!!): A once-in-a-century-flood (event with a return period of 100 years) is expected to be exceeded ca. ten times in a dataset spanning a millennium. Let the associated discharge (river flow) be 5400 m^3/s. The exceedance probability of 5400 m^3/s is 1%, which means that in any given year, the probability to have a flood larger than that is 1%. The probability that the largest flood in 2017 is smaller than 5400 is thus 99 %. RP = 100, Pe=0.01, Pne=0.99. Let there be 60 years of daily discharge records. In the annual block maxima approach with 60 values, the probability passed to the quantile function to compute the 100-year flood is 0.99. In the peak over threshold approach with daily values above a threshold, it is 0.9999726.

Here is an example with annual block maxima of stream discharge in Austria: