Title: | L-Moments |
---|---|
Description: | Functions related to L-moments: computation of L-moments and trimmed L-moments of distributions and data samples; parameter estimation; L-moment ratio diagram; plot vs. quantiles of an extreme-value distribution. |
Authors: | J. R. M. Hosking [aut, cre] |
Maintainer: | J. R. M. Hosking <[email protected]> |
License: | Common Public License Version 1.0 |
Version: | 3.2 |
Built: | 2024-12-18 06:28:47 UTC |
Source: | CRAN |
R functions for use with the method of -moments
-moments are measures of the location, scale, and shape
of probability distributions or data samples.
They are based on linear combinations of order statistics.
Hosking (1990) and Hosking and Wallis (1997, chap. 2) give expositions
of the theory of
-moments and
-moment ratios. Hosking and Wallis
(1997, Appendix) give, for many distributions in common use, expressions
for the
-moments of the distributions and algorithms for estimating
the parameters of the distributions by equating sample and population
-moments (the “method of
-moments”). This package contains R functions
that should facilitate the use of
-moment-based methods.
For each of 13 probability distributions, the package contains
functions to evaluate the cumulative distribution function and quantile
function of the distribution, to calculate the -moments given the
parameters and to calculate the parameters given the low-order
-moments. These functions are as follows.
cdf...
computes the cumulative distribution function of the distribution.
qua...
computes the quantile function (inverse cumulative distribution function)
of the distribution.
lmr...
calculates the -moment ratios of the distribution given its
parameters.
pel...
calculates the parameters of the distribution given its -moments.
When the
-moments are the sample
-moments of a set of data,
the resulting parameters are of course the
“method of
-moments” estimates of the parameters.
Here ...
is a three-letter code used to identify the distribution,
as given in the table below.
For example the cumulative distribution function of the gamma distribution
is cdfgam
.
exp |
exponential | |
gam |
gamma | |
gev |
generalized extreme-value | |
glo |
generalized logistic | |
gpa |
generalized Pareto | |
gno |
generalized normal | |
gum |
Gumbel (extreme-value type I) | |
kap |
kappa | |
ln3 |
lognormal | |
nor |
normal | |
pe3 |
Pearson type III | |
wak |
Wakeby | |
wei |
Weibull | |
The following functions are also contained in the package.
samlmu
computes the sample -moments of a data vector.
lmrp
and lmrq
compute the -moments of a probability distribution specified
by its cumulative distribution function (for function
lmrp
)
or its quantile function (for function lmrq
).
The computation uses numerical integration applied to
a general expression for the -moments of a distribution.
Functions
lmrp
and lmrq
can be used for any univariate
distribution. They are slower and usually less accurate than the
computations carried out for specific distributions by the
lmr...
functions.
pelp
and pelq
compute the parameters of a probability distribution
as a function of the -moments.
The computation uses function
lmrp
or lmrq
to compute
-moments and numerical optimization to find parameter values
for which the sample and population
-moments are equal.
Functions
pelp
and pelq
can be used for any univariate
distribution. They are slower and usually less accurate than the
computations carried out for specific distributions by the
pel...
functions.
lmrd
draws an -moment ratio diagram.
lmrdpoints
and lmrdlines
add points, or connected line segments, respectively,
to an -moment ratio diagram.
evplot
draws an “extreme-value plot”, i.e. a quantile-quantile plot
in which the horizontal axis is the quantile of an
extreme-value type I (Gumbel) distribution.
evpoints
, evdistp
, and evdistq
add, respectively, a set of points, a cumulative distribution function,
and a quantile function to an extreme-value plot.
-momentsSome functions support the trimmed -moments defined by Elamir and Seheult (2003).
Trimmed
-moments are based on linear combinations of order statistics
that give zero weight to the most extreme order statistics and thereby can be
defined for very heavy-tailed distributions that do not have a finite mean.
Function samlmu
can compute sample trimmed -moments.
Functions
lmrp
and lmrq
can compute trimmed -moments
of probability distributions.
Functions
pelp
and pelq
can calculate parameters
of a probability distribution given its trimmed -moments.
The distribution-specific functions lmr...
and pel...
and the
functions for -moment ratio diagrams (
lmrd
, etc.) currently
do not support trimmed -moments.
The functions cdf...
(cumulative distribution functions)
and qua...
(quantile functions) expect the distribution
parameters to be specified as a single vector.
This differs from the standard R convention, in which
each parameter is a separate argument.
There are two reasons for this.
First, the single-vector parametrization is consistent with
the Fortran routines on which these R functions are based.
Second, the single-vector parametrization is often easier to use.
For example, consider computing the 80th and 90th percentiles
of a normal distribution fitted to a set of -moments
stored in a vector
lmom
.
In the single-vector parametrization, this is achieved by
quanor( c(.8,.9), pelnor(lmom) )
The separate-arguments parametrization would need a more complex expression, such as
do.call( qnorm, c( list(.8,.9), pelnor(lmom) ) )
In functions (lmrp
, lmrq
, pelp
, pelq
, evplot
,
evdistp
, evdistq
) that take a cumulative distribution function
or a quantile function as an argument, the cumulative distribution function
or quantile function can use either form of parametrization.
Functions cdf...
, qua...
, lmr...
, pel...
,
and samlmu
are analogous to Fortran routines from
the LMOMENTS package, version 3.04, available from StatLib at
https://lib.stat.cmu.edu/general/lmoments.
Functions cdfwak
and samlmu
, and all the lmr...
and pel...
functions, internally call Fortran code that is derived from the
LMOMENTS package.
J. R. M. Hosking [email protected]
Elamir, E. A. H., and Seheult, A. H. (2003). Trimmed L-moments. Computational Statistics and Data Analysis, 43, 299-314.
Hosking, J. R. M. (1990).
-moments: analysis and estimation of distributions
using linear combinations of order statistics.
Journal of the Royal Statistical Society, Series B, 52, 105-124.
Hosking, J. R. M., and Wallis, J. R. (1997). Regional frequency analysis: an approach based on L-moments. Cambridge University Press.
Distribution function and quantile function of the exponential distribution.
cdfexp(x, para = c(0, 1)) quaexp(f, para = c(0, 1))
cdfexp(x, para = c(0, 1)) quaexp(f, para = c(0, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The exponential distribution with parameters
(lower bound) and
(mean)
has distribution function
for , and quantile function
cdfexp
gives the distribution function;
quaexp
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R functions
pexp
and qexp
.
pexp
for the standard R version of the exponential distribution.
cdfgam
for the gamma distribution,
cdfgpa
for the generalized Pareto distribution,
cdfkap
for the kappa distribution,
cdfpe3
for the Pearson type III distribution,
and cdfwak
for the Wakeby distribution,
all of which generalize the exponential distribution.
# Random sample from the exponential distribution # with lower bound 0 and mean 3. quaexp(runif(100), c(0,3))
# Random sample from the exponential distribution # with lower bound 0 and mean 3. quaexp(runif(100), c(0,3))
Distribution function and quantile function of the gamma distribution.
cdfgam(x, para = c(1, 1)) quagam(f, para = c(1, 1))
cdfgam(x, para = c(1, 1)) quagam(f, para = c(1, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The gamma distribution with
shape parameter and
scale parameter
has probability density function
for , where
is the gamma function.
cdfgam
gives the distribution function;
quagam
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R functions
pgamma
and qgamma
.
gamma
for the gamma function.
pgamma
for the standard R version of the gamma distribution.
cdfpe3
for the Pearson type III distribution,
which generalizes the gamma distribution.
# Random sample from the gamma distribution # with shape parameter 4 and mean 1. quagam(runif(100), c(4,1/4))
# Random sample from the gamma distribution # with shape parameter 4 and mean 1. quagam(runif(100), c(4,1/4))
Distribution function and quantile function of the generalized extreme-value distribution.
cdfgev(x, para = c(0, 1, 0)) quagev(f, para = c(0, 1, 0))
cdfgev(x, para = c(0, 1, 0)) quagev(f, para = c(0, 1, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The generalized extreme-value distribution with
location parameter ,
scale parameter
and
shape parameter
has distribution function
where
with bounded by
from below if
and from above if
,
and quantile function
Extreme-value distribution types I, II and III (Gumbel, Frechet, Weibull)
correspond to shape parameter values
,
and
respectively.
cdfgev
gives the distribution function;
quagev
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
Two parametrizations of the generalized extreme-value distribution are in common use. When Jenkinson (1955) introduced the distribution he wrote the distribution function in the form
and that is the form used in R package lmom. A slight inconvenience with it is that the
skewness of the distribution is a decreasing function of the shape parameter .
Perhaps for this reason, authors of some other R packages prefer a form in which
the sign of the shape parameter
is changed and the parameters are renamed:
Users should be able to mix functions from packages that use either form; just be aware that
the sign of the shape parameter will need to be changed when converting from one form to the other
(and that is a location parameter in one form and a shape parameter in the other).
Jenkinson, A. F. (1955). The frequency distribution of the annual maximum (or minimum) of meteorological elements. Quarterly Journal of the Royal Meteorological Society, 81, 158-171.
cdfgum
for the Gumbel (extreme-value type I) distribution.
cdfkap
for the kappa distribution,
which generalizes the generalized extreme-value distribution.
cdfwei
for the Weibull distribution,
# Random sample from the generalized extreme-value distribution # with parameters xi=0, alpha=1, k=-0.5. quagev(runif(100), c(0,1,-0.5))
# Random sample from the generalized extreme-value distribution # with parameters xi=0, alpha=1, k=-0.5. quagev(runif(100), c(0,1,-0.5))
Distribution function and quantile function of the generalized logistic distribution.
cdfglo(x, para = c(0, 1, 0)) quaglo(f, para = c(0, 1, 0))
cdfglo(x, para = c(0, 1, 0)) quaglo(f, para = c(0, 1, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The generalized logistic distribution with
location parameter ,
scale parameter
and
shape parameter
has distribution function
where
with bounded by
from below if
and from above if
,
and quantile function
The logistic distribution is the special case .
cdfglo
gives the distribution function;
quaglo
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
cdfkap
for the kappa distribution,
which generalizes the generalized logistic distribution.
# Random sample from the generalized logistic distribution # with parameters xi=0, alpha=1, k=-0.5. quaglo(runif(100), c(0,1,-0.5))
# Random sample from the generalized logistic distribution # with parameters xi=0, alpha=1, k=-0.5. quaglo(runif(100), c(0,1,-0.5))
Distribution function and quantile function of the generalized normal distribution.
cdfgno(x, para = c(0, 1, 0)) quagno(f, para = c(0, 1, 0))
cdfgno(x, para = c(0, 1, 0)) quagno(f, para = c(0, 1, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The generalized normal distribution with
location parameter ,
scale parameter
and
shape parameter
has distribution function
where
and is the distribution function of the standard normal distribution,
with
bounded by
from below if
and from above if
.
The generalized normal distribution contains as special cases the usual
three-parameter lognormal distribution, corresponding to ,
with a finite lower bound and positive skewness;
the normal distribution, corresponding to
;
and the reverse lognormal distribution, corresponding to
,
with a finite upper bound and negative skewness.
The two-parameter lognormal distribution,
with a lower bound of zero and positive skewness,
is obtained when
and
.
cdfgno
gives the distribution function;
quagno
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
cdfln3
for the lmom package's version of the three-parameter
lognormal distribution.
cdfnor
for the lmom package's version of the normal distribution.
pnorm
for the standard R version of the normal distribution.
plnorm
for the standard R version of the two-parameter lognormal distribution.
# Random sample from the generalized normal distribution # with parameters xi=0, alpha=1, k=-0.5. quagno(runif(100), c(0,1,-0.5)) # The generalized normal distribution with parameters xi=1, alpha=1, k=-1, # is the standard lognormal distribution. An illustration: fval<-seq(0.1,0.9,by=0.1) cbind(fval, lognormal=qlnorm(fval), g.normal=quagno(fval, c(1,1,-1)))
# Random sample from the generalized normal distribution # with parameters xi=0, alpha=1, k=-0.5. quagno(runif(100), c(0,1,-0.5)) # The generalized normal distribution with parameters xi=1, alpha=1, k=-1, # is the standard lognormal distribution. An illustration: fval<-seq(0.1,0.9,by=0.1) cbind(fval, lognormal=qlnorm(fval), g.normal=quagno(fval, c(1,1,-1)))
Distribution function and quantile function of the generalized Pareto distribution.
cdfgpa(x, para = c(0, 1, 0)) quagpa(f, para = c(0, 1, 0))
cdfgpa(x, para = c(0, 1, 0)) quagpa(f, para = c(0, 1, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The generalized Pareto distribution with
location parameter ,
scale parameter
and
shape parameter
has distribution function
where
with bounded by
from below if
and from above if
,
and quantile function
The exponential distribution is the special case .
The uniform distribution is the special case
.
cdfgpa
gives the distribution function;
quagpa
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
Two parametrizations of the generalized Pareto distribution are in common use. When Jenkinson (1955) introduced the generalized extreme-value distribution he wrote the distribution function in the form
Hosking and Wallis (1987) wrote the distribution function of the generalized Pareto distribution analogously as
and that is the form used in R package lmom. A slight inconvenience with it is that the
skewness of the distribution is a decreasing function of the shape parameter .
Perhaps for this reason, authors of some other R packages prefer a form in which
the sign of the shape parameter
is changed and the parameters are renamed:
Users should be able to mix functions from packages that use either form; just be aware that
the sign of the shape parameter will need to be changed when converting from one form to the other
(and that is a location parameter in one form and a shape parameter in the other).
Hosking, J. R. M., and Wallis, J. R. (1987). Parameter and quantile estimation for the generalized Pareto distribution. Technometrics, 29, 339-349.
Jenkinson, A. F. (1955). The frequency distribution of the annual maximum (or minimum) of meteorological elements. Quarterly Journal of the Royal Meteorological Society, 81, 158-171.
cdfexp
for the exponential distribution.
cdfkap
for the kappa distribution and
cdfwak
for the Wakeby distribution,
which generalize the generalized Pareto distribution.
# Random sample from the generalized Pareto distribution # with parameters xi=0, alpha=1, k=-0.5. quagpa(runif(100), c(0,1,-0.5))
# Random sample from the generalized Pareto distribution # with parameters xi=0, alpha=1, k=-0.5. quagpa(runif(100), c(0,1,-0.5))
Distribution function and quantile function of the Gumbel distribution.
cdfgum(x, para = c(0, 1)) quagum(f, para = c(0, 1))
cdfgum(x, para = c(0, 1)) quagum(f, para = c(0, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The Gumbel distribution with
location parameter and
scale parameter
has distribution function
and quantile function
cdfgum
gives the distribution function;
quagum
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
cdfgev
for the generalized extreme-value distribution,
which generalizes the Gumbel distribution.
# Random sample from the Gumbel distribution with parameters xi=0, alpha=3. quagum(runif(100), c(0,3))
# Random sample from the Gumbel distribution with parameters xi=0, alpha=3. quagum(runif(100), c(0,3))
Distribution function and quantile function of the kappa distribution.
cdfkap(x, para = c(0, 1, 0, 0)) quakap(f, para = c(0, 1, 0, 0))
cdfkap(x, para = c(0, 1, 0, 0)) quakap(f, para = c(0, 1, 0, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The kappa distribution with
location parameter ,
scale parameter
and
shape parameters
and
has quantile function
Its special cases include the
generalized logistic (),
generalized extreme-value (
),
generalized Pareto (
),
logistic (
,
),
Gumbel (
,
),
exponential (
,
), and
uniform (
,
) distributions.
cdfkap
gives the distribution function;
quakap
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
Hosking, J. R. M. (1994). The four-parameter kappa distribution. IBM Journal of Research and Development, 38, 251-258.
Hosking, J. R. M., and Wallis, J. R. (1997). Regional frequency analysis: an approach based on L-moments, Cambridge University Press, Appendix A.10.
cdfglo
for the generalized logistic distribution,
cdfgev
for the generalized extreme-value distribution,
cdfgpa
for the generalized Pareto distribution,
cdfgum
for the Gumbel distribution,
cdfexp
for the exponential distribution.
# Random sample from the kappa distribution # with parameters xi=0, alpha=1, k=-0.5, h=0.25. quakap(runif(100), c(0,1,-0.5,0.25))
# Random sample from the kappa distribution # with parameters xi=0, alpha=1, k=-0.5, h=0.25. quakap(runif(100), c(0,1,-0.5,0.25))
Distribution function and quantile function of the three-parameter lognormal distribution.
cdfln3(x, para = c(0, 0, 1)) qualn3(f, para = c(0, 0, 1))
cdfln3(x, para = c(0, 0, 1)) qualn3(f, para = c(0, 0, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The three-parameter lognormal distribution with
lower bound ,
mean on log scale
, and
standard deviation on log scale
has distribution function
, where
and is the distribution function of the standard
normal distribution.
cdfln3
gives the distribution function;
qualn3
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
cdfgno
for the generalized normal distribution,
a more general form of the three-parameter lognormal distribution.
qlnorm
for the standard R version of the
two-parameter lognormal distribution.
# Random sample from three-parameter lognormal distribution # with parameters zeta=0, mu=1, sigma=0.5. qualn3(runif(100), c(0,1,0.5)) ## Functions for the three-parameter lognormal distribution can ## also be used with the two-parameter lognormal distribution # Generate a random sample from a standard lognormal distribution xx <- qualn3(runif(50)) # Fit 2-parameter LN distribution pelln3(samlmu(xx), bound=0) # Fit 2-parameter LN distribution "in log space", # i.e. fit normal distribution to log-transformed data pelnor(samlmu(log(xx)))
# Random sample from three-parameter lognormal distribution # with parameters zeta=0, mu=1, sigma=0.5. qualn3(runif(100), c(0,1,0.5)) ## Functions for the three-parameter lognormal distribution can ## also be used with the two-parameter lognormal distribution # Generate a random sample from a standard lognormal distribution xx <- qualn3(runif(50)) # Fit 2-parameter LN distribution pelln3(samlmu(xx), bound=0) # Fit 2-parameter LN distribution "in log space", # i.e. fit normal distribution to log-transformed data pelnor(samlmu(log(xx)))
Distribution function and quantile function of the normal distribution.
cdfnor(x, para = c(0, 1)) quanor(f, para = c(0, 1))
cdfnor(x, para = c(0, 1)) quanor(f, para = c(0, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The normal distribution with
location parameter and
scale parameter
has probability density function
cdfnor
gives the distribution function;
quanor
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
and qnorm
.
pnorm
for the standard R version of the normal distribution.
cdfgno
for the generalized normal distribution,
which generalizes the normal distribution.
# Random sample from the normal distribution # with mean 0 and standard deviation 3. quanor(runif(100), c(0,3))
# Random sample from the normal distribution # with mean 0 and standard deviation 3. quanor(runif(100), c(0,3))
Distribution function and quantile function of the Pearson type III distribution
cdfpe3(x, para = c(0, 1, 0)) quape3(f, para = c(0, 1, 0))
cdfpe3(x, para = c(0, 1, 0)) quape3(f, para = c(0, 1, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The Pearson type III distribution contains as special cases
the usual three-parameter gamma distribution
(a shifted version of the gamma distribution)
with a finite lower bound and positive skewness;
the normal distribution,
and the reverse three-parameter gamma distribution,
with a finite upper bound and negative skewness.
The distribution's parameters are the first three (ordinary) moment ratios:
(the mean, a location parameter),
(the standard deviation, a scale parameter) and
(the skewness, a shape parameter).
If , let
,
,
.
The probability density function is
with bounded by
from below if
and from above if
.
If
, the distribution is a normal distribution
with mean
and standard deviation
.
The Pearson type III distribution is usually regarded as consisting of
just the case given above, and is usually
parametrized by
,
and
.
Our parametrization extends the distribution to include
the usual Pearson type III distributions,
with positive skewness and lower bound
,
reverse Pearson type III distributions,
with negative skewness and upper bound
,
and the Normal distribution, which is included as a special
case of the distribution rather than as the unattainable limit
.
This enables the Pearson type III distribution to be used when the skewness of
the observed data may be negative.
The parameters
,
and
are the conventional moments of the distribution.
The gamma distribution is obtained when
and
.
The normal distribution is the special case
.
The exponential distribution is the special case
.
cdfpe3
gives the distribution function;
quape3
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
Hosking, J. R. M. and Wallis, J. R. (1997). Regional frequency analysis: an approach based on L-moments, Cambridge University Press, Appendix A.10.
cdfgam
for the gamma distribution.
cdfnor
for the normal distribution.
# Random sample from the Pearson type III distribution # with parameters mu=1, alpha=2, gamma=3. quape3(runif(100), c(1,2,3)) # The Pearson type III distribution with parameters # mu=12, sigma=6, gamma=1, is the gamma distribution # with parameters alpha=4, beta=3. An illustration: fval<-seq(0.1,0.9,by=0.1) cbind(fval, qgamma(fval, shape=4, scale=3), quape3(fval, c(12,6,1)))
# Random sample from the Pearson type III distribution # with parameters mu=1, alpha=2, gamma=3. quape3(runif(100), c(1,2,3)) # The Pearson type III distribution with parameters # mu=12, sigma=6, gamma=1, is the gamma distribution # with parameters alpha=4, beta=3. An illustration: fval<-seq(0.1,0.9,by=0.1) cbind(fval, qgamma(fval, shape=4, scale=3), quape3(fval, c(12,6,1)))
Distribution function and quantile function of the Wakeby distribution.
cdfwak(x, para = c(0, 1, 0, 0, 0)) quawak(f, para = c(0, 1, 0, 0, 0))
cdfwak(x, para = c(0, 1, 0, 0, 0)) quawak(f, para = c(0, 1, 0, 0, 0))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order
|
The Wakeby distribution with
parameters ,
,
,
and
has quantile function
The parameters are restricted as in Hosking and Wallis (1997, Appendix A.11):
either or
;
if then
;
if then
;
;
.
The distribution has a lower bound at and,
if
, an upper bound at
.
The generalized Pareto distribution is the special case
or
.
The exponential distribution is the special case
.
The uniform distribution is the special case
,
.
cdfwak
gives the distribution function;
quawak
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
Hosking, J. R. M. and Wallis, J. R. (1997). Regional frequency analysis: an approach based on L-moments, Cambridge University Press, Appendix A.11.
cdfgpa
for the generalized Pareto distribution.
cdfexp
for the exponential distribution.
# Random sample from the Wakeby distribution # with parameters xi=0, alpha=30, beta=20, gamma=1, delta=0.3. quawak(runif(100), c(0,30,20,1,0.3))
# Random sample from the Wakeby distribution # with parameters xi=0, alpha=30, beta=20, gamma=1, delta=0.3. quawak(runif(100), c(0,30,20,1,0.3))
Distribution function and quantile function of the Weibull distribution.
cdfwei(x, para = c(0, 1, 1)) quawei(f, para = c(0, 1, 1))
cdfwei(x, para = c(0, 1, 1)) quawei(f, para = c(0, 1, 1))
x |
Vector of quantiles. |
f |
Vector of probabilities. |
para |
Numeric vector containing the parameters of the distribution,
in the order |
The Weibull distribution with
location parameter ,
scale parameter
and
shape parameter
has distribution function
for .
cdfwei
gives the distribution function;
quawei
gives the quantile function.
The functions expect the distribution parameters in a vector,
rather than as separate arguments as in the standard R
distribution functions pnorm
, qnorm
, etc.
cdfgev
for the generalized extreme-value distribution,
of which the Weibull (reflected through the origin) is a special case.
# Random sample from a 2-parameter Weibull distribution # with scale parameter 2 and shape parameter 1.5. quawei(runif(100), c(0,2,1.5)) # Illustrate the relation between Weibull and GEV distributions. # weifit() fits a Weibull distribution to data and returns # quantiles of the fitted distribution # gevfit() fits a Weibull distribution as a "reverse GEV", # i.e. fits a GEV distribution to the negated data, # then computes negated quantiles weifit <- function(qval, x) quawei(qval, pelwei(samlmu(x))) gevfit <- function(qval, x) -quagev(1-qval, pelgev(samlmu(-x))) # Compare on Ozone data data(airquality) weifit(c(0.2,0.5,0.8), airquality$Ozone) gevfit(c(0.2,0.5,0.8), airquality$Ozone)
# Random sample from a 2-parameter Weibull distribution # with scale parameter 2 and shape parameter 1.5. quawei(runif(100), c(0,2,1.5)) # Illustrate the relation between Weibull and GEV distributions. # weifit() fits a Weibull distribution to data and returns # quantiles of the fitted distribution # gevfit() fits a Weibull distribution as a "reverse GEV", # i.e. fits a GEV distribution to the negated data, # then computes negated quantiles weifit <- function(qval, x) quawei(qval, pelwei(samlmu(x))) gevfit <- function(qval, x) -quagev(1-qval, pelgev(samlmu(-x))) # Compare on Ozone data data(airquality) weifit(c(0.2,0.5,0.8), airquality$Ozone) gevfit(c(0.2,0.5,0.8), airquality$Ozone)
evplot
draws an “extreme-value plot”, i.e. a quantile-quantile plot
in which the horizontal axis is the quantile of an
extreme-value type I (Gumbel) distribution.
evdistp
adds the cumulative distribution function of a distribution
to an extreme-value plot.
evdistq
adds the quantile function of a distribution
to an extreme-value plot.
evpoints
adds a set of data points to an extreme-value plot.
evplot(y, ...) ## Default S3 method: evplot(y, qfunc, para, npoints = 101, plim, xlim = c(-2, 5), ylim, type, xlab = expression("Reduced variate, " * -log(-log(italic(F)))), ylab = "Quantile", rp.axis = TRUE, ...) evdistp(pfunc, para, npoints = 101, ...) evdistq(qfunc, para, npoints = 101, ...) evpoints(y, ...)
evplot(y, ...) ## Default S3 method: evplot(y, qfunc, para, npoints = 101, plim, xlim = c(-2, 5), ylim, type, xlab = expression("Reduced variate, " * -log(-log(italic(F)))), ylab = "Quantile", rp.axis = TRUE, ...) evdistp(pfunc, para, npoints = 101, ...) evdistq(qfunc, para, npoints = 101, ...) evpoints(y, ...)
y |
Numeric vector. The data values in the vector are plotted on the extreme-value plot. |
qfunc |
A quantile function. The function is drawn as a curve on the extreme-value plot. |
pfunc |
A cumulative distribution function. The function is drawn as a curve on the extreme-value plot. |
para |
Distribution parameters for the quantile function If If In |
npoints |
Number of points to use in drawing the quantile function.
The points are equally spaced along the x axis.
Not used if |
plim |
X axis limits, specified as probabilities. |
xlim |
X axis limits, specified as values of the Gumbel reduced variate
|
ylim |
Y axis limits. |
type |
Plot type. Determines how the data values in |
xlab |
X axis label. |
ylab |
Y axis label. |
rp.axis |
Logical. Whether to draw the “Return period” axis, a secondary horizontal axis. |
... |
Additional arguments are passed to the plotting routine. |
pfunc
and qfunc
can be either the standard R form of
cumulative distribution function or quantile function
(i.e. for a distribution with parameters, the first argument is the
variate
or the probability
and the next
arguments
are the parameters of the distribution) or the
cdf...
or
qua...
forms used throughout the lmom package
(i.e. the first argument is the variate or probability
and the second argument is a vector containing the parameter values).
Data points are plotted at the Gringorten plotting position,
i.e. the th smallest of
data points is plotted
at the horizontal position corresponding to nonexceedance probability
.
J. R. M. Hosking [email protected]
# Extreme-value plot of Ozone from the airquality data data(airquality) evplot(airquality$Ozone) # Fit a GEV distribution and add it to the plot evdistq(quagev, pelgev(samlmu(airquality$Ozone))) # Not too good -- try a kappa distribution instead evdistq(quakap, pelkap(samlmu(airquality$Ozone)), col="red")
# Extreme-value plot of Ozone from the airquality data data(airquality) evplot(airquality$Ozone) # Fit a GEV distribution and add it to the plot evdistq(quagev, pelgev(samlmu(airquality$Ozone))) # Not too good -- try a kappa distribution instead evdistq(quakap, pelkap(samlmu(airquality$Ozone)), col="red")
Computes the -moments of a probability distribution
given its parameters.
The following distributions are recognized:
lmrexp |
exponential | |
lmrgam |
gamma | |
lmrgev |
generalized extreme-value | |
lmrglo |
generalized logistic | |
lmrgpa |
generalized Pareto | |
lmrgno |
generalized normal | |
lmrgum |
Gumbel (extreme-value type I) | |
lmrkap |
kappa | |
lmrln3 |
three-parameter lognormal | |
lmrnor |
normal | |
lmrpe3 |
Pearson type III | |
lmrwak |
Wakeby | |
lmrwei |
Weibull | |
lmrexp(para = c(0, 1), nmom = 2) lmrgam(para = c(1, 1), nmom = 2) lmrgev(para = c(0, 1, 0), nmom = 3) lmrglo(para = c(0, 1, 0), nmom = 3) lmrgno(para = c(0, 1, 0), nmom = 3) lmrgpa(para = c(0, 1, 0), nmom = 3) lmrgum(para = c(0, 1), nmom = 2) lmrkap(para = c(0, 1, 0, 0), nmom = 4) lmrln3(para = c(0, 0, 1), nmom = 3) lmrnor(para = c(0, 1), nmom = 2) lmrpe3(para = c(0, 1, 0), nmom = 3) lmrwak(para = c(0, 1, 0, 0, 0), nmom = 5) lmrwei(para = c(0, 1, 1), nmom = 3)
lmrexp(para = c(0, 1), nmom = 2) lmrgam(para = c(1, 1), nmom = 2) lmrgev(para = c(0, 1, 0), nmom = 3) lmrglo(para = c(0, 1, 0), nmom = 3) lmrgno(para = c(0, 1, 0), nmom = 3) lmrgpa(para = c(0, 1, 0), nmom = 3) lmrgum(para = c(0, 1), nmom = 2) lmrkap(para = c(0, 1, 0, 0), nmom = 4) lmrln3(para = c(0, 0, 1), nmom = 3) lmrnor(para = c(0, 1), nmom = 2) lmrpe3(para = c(0, 1, 0), nmom = 3) lmrwak(para = c(0, 1, 0, 0, 0), nmom = 5) lmrwei(para = c(0, 1, 1), nmom = 3)
para |
Numeric vector containing the parameters of the distribution. |
nmom |
The number of |
Numerical methods and accuracy are as described in Hosking (1996, pp. 8–9).
Numeric vector containing the -moments.
J. R. M. Hosking [email protected]
Hosking, J. R. M. (1996).
Fortran routines for use with the method of -moments, Version 3.
Research Report RC20525, IBM Research Division, Yorktown Heights, N.Y.
lmrp
to compute -moments of a general distribution
specified by its cumulative distribution function or quantile function.
samlmu
to compute -moments of a data sample.
pelexp
, etc., to compute the parameters
of a distribution given its -moments.
For individual distributions, see their cumulative distribution functions:
cdfexp |
exponential | |
cdfgam |
gamma | |
cdfgev |
generalized extreme-value | |
cdfglo |
generalized logistic | |
cdfgpa |
generalized Pareto | |
cdfgno |
generalized normal | |
cdfgum |
Gumbel (extreme-value type I) | |
cdfkap |
kappa | |
cdfln3 |
three-parameter lognormal | |
cdfnor |
normal | |
cdfpe3 |
Pearson type III | |
cdfwak |
Wakeby | |
cdfwei |
Weibull | |
# Compare sample L-moments of Ozone from the airquality data # with the L-moments of a GEV distribution fitted to the data data(airquality) smom <- samlmu(airquality$Ozone, nmom=6) gevpar <- pelgev(smom) pmom <- lmrgev(gevpar, nmom=6) print(smom) print(pmom)
# Compare sample L-moments of Ozone from the airquality data # with the L-moments of a GEV distribution fitted to the data data(airquality) smom <- samlmu(airquality$Ozone, nmom=6) gevpar <- pelgev(smom) pmom <- lmrgev(gevpar, nmom=6) print(smom) print(pmom)
Draws an -moment ratio diagram.
lmrd(x, y, distributions = "GLO GEV GPA GNO PE3", twopar, xlim, ylim, pch=3, cex, col, lty, lwd=1, legend.lmrd = TRUE, xlegend, ylegend, xlab = expression(italic(L) * "-skewness"), ylab = expression(italic(L) * "-kurtosis"), ...)
lmrd(x, y, distributions = "GLO GEV GPA GNO PE3", twopar, xlim, ylim, pch=3, cex, col, lty, lwd=1, legend.lmrd = TRUE, xlegend, ylegend, xlab = expression(italic(L) * "-skewness"), ylab = expression(italic(L) * "-kurtosis"), ...)
x |
Numeric vector of Alternatively, if argument |
|||||||||||||||||||||||||||
y |
Numeric vector of |
|||||||||||||||||||||||||||
distributions |
Indicates the three-parameter distributions
whose
The argument should be either a character vector each of whose elements
is one of the above abbreviations or a character string
containing one or more of the abbreviations separated by blanks.
The specified If no three-parameter distributions are to be plotted,
specify |
|||||||||||||||||||||||||||
twopar |
Two-parameter distributions whose (
The argument should be either a character vector each of whose elements
is one of the above abbreviations or a character string
containing one or more of the abbreviations separated by blanks.
The default is to plot the two-parameter distributions that are special
cases of the three-parameter distributions specified in
argument If no two-parameter distributions are to be plotted,
specify |
|||||||||||||||||||||||||||
xlim |
x axis limits.
Default: |
|||||||||||||||||||||||||||
ylim |
y axis limits.
Default: |
|||||||||||||||||||||||||||
pch |
Plotting character to be used for the plotted
( |
|||||||||||||||||||||||||||
cex |
Symbol size for plotted points, like graphics parameter |
|||||||||||||||||||||||||||
col |
Vector specifying the colors. If it is of length 1
and |
|||||||||||||||||||||||||||
lty |
Vector specifying the line types to be used for the lines on the plot. By default, colors and line types are matched to the distributions given
in argument
The green and cyan colors are less bright than the standard
|
|||||||||||||||||||||||||||
lwd |
Vector specifying the line widths to be used for the lines on the plot. |
|||||||||||||||||||||||||||
legend.lmrd |
Controls whether a legend,
identifying the Not used if |
|||||||||||||||||||||||||||
xlegend , ylegend
|
x and y coordinates of the upper left corner of the legend. Default: coordinates of the upper left corner of the plot region, shifted to the right and downwards, each by an amount equal to 1% of the range of the x axis. Not used if |
|||||||||||||||||||||||||||
xlab |
X axis label. |
|||||||||||||||||||||||||||
ylab |
Y axis label. |
|||||||||||||||||||||||||||
... |
Additional arguments are passed to the function |
lmrd
calls a sequence of graphics functions:
matplot
for the axis box and the curves for three-parameter distributions;
points
for the points for two-parameter distributions and
text
for their labels; legend
for the legend; and
points
for the data points.
Note that the only graphics parameters passed to points
are col
(if of length 1), cex
, and pch
.
If more complex features are required, such as different colors for
different points, follow lmrd
by an additional call to points
,
e.g. follow lmrd(t3, t4)
by points(t3, t4, col=c("red", "green"))
.
A list, returned invisibly, describing what was plotted. Useful for customization of the legend, as in one of the examples below. List elements:
lines |
List containing elements describing the plotted distribution curves (if any).
Each element is a vector with the same length as |
twopar |
Character vector containing the 1-character symbols for the two-parameter distributions that were plotted. |
points |
List containing elements describing the plot (if any) of the data points.
List elements |
If any of the above items was not plotted, the corresponding list element is NULL
.
J. R. M. Hosking [email protected]
For adding to an -moment ratio diagram:
lmrdpoints
, lmrdlines
.
data(airquality) lmrd(samlmu(airquality$Ozone)) # Tweaking a few graphics parameters makes the graph look better # (in the author's opinion) lmrd(samlmu(airquality$Ozone), xaxs="i", yaxs="i", las=1) # An example that illustrates the sampling variability of L-moments # # Generate 50 random samples of size 30 from the Gumbel distribution # - stored in the rows of matrix mm mm <- matrix(quagum(runif(1500)), nrow=50) # # Compute the first four sample L-moments of each sample # - stored in the rows of matrix aa aa <- apply(mm, 1, samlmu) # # Plot the L-skewness and L-kurtosis values on an L-moment ratio # diagram that also shows (only) the population L-moment ratios # of the Gumbel distribution lmrd(t(aa), dist="", twopar="G", col="red") # L-moment ratio diagram with curves for GLO, GEV, GPA, and Weibull. # The Weibull curve is added manually. A legend is added, # using information returned from lmrd(). # # - Draw the diagram, with the GLO, GEV, and GPA curves info <- lmrd(distributions="GLO GEV GPA", xaxs="i", yaxs="i", las=1, legend=FALSE) # # - Compute L-skewness and L-kurtosis values for Weibull sa <- sapply(seq(0, 0.6, by=0.01), function(tau3) lmrwei(pelwei(c(0,1,tau3)), nmom=4)[3:4]) # # - Plot the Weibull curve lmrdlines(sa["tau_3",], sa["tau_4",], col="magenta", lwd=2) # # - Add a legend legend("topleft", bty="n", legend = c(info$lines$distributions, "WEI"), col = c(info$lines$col.lines, "magenta"), lwd = c(info$lines$lwd, 3))
data(airquality) lmrd(samlmu(airquality$Ozone)) # Tweaking a few graphics parameters makes the graph look better # (in the author's opinion) lmrd(samlmu(airquality$Ozone), xaxs="i", yaxs="i", las=1) # An example that illustrates the sampling variability of L-moments # # Generate 50 random samples of size 30 from the Gumbel distribution # - stored in the rows of matrix mm mm <- matrix(quagum(runif(1500)), nrow=50) # # Compute the first four sample L-moments of each sample # - stored in the rows of matrix aa aa <- apply(mm, 1, samlmu) # # Plot the L-skewness and L-kurtosis values on an L-moment ratio # diagram that also shows (only) the population L-moment ratios # of the Gumbel distribution lmrd(t(aa), dist="", twopar="G", col="red") # L-moment ratio diagram with curves for GLO, GEV, GPA, and Weibull. # The Weibull curve is added manually. A legend is added, # using information returned from lmrd(). # # - Draw the diagram, with the GLO, GEV, and GPA curves info <- lmrd(distributions="GLO GEV GPA", xaxs="i", yaxs="i", las=1, legend=FALSE) # # - Compute L-skewness and L-kurtosis values for Weibull sa <- sapply(seq(0, 0.6, by=0.01), function(tau3) lmrwei(pelwei(c(0,1,tau3)), nmom=4)[3:4]) # # - Plot the Weibull curve lmrdlines(sa["tau_3",], sa["tau_4",], col="magenta", lwd=2) # # - Add a legend legend("topleft", bty="n", legend = c(info$lines$distributions, "WEI"), col = c(info$lines$col.lines, "magenta"), lwd = c(info$lines$lwd, 3))
lmrdpoints
adds points,
and lmrdlines
adds connected line segments,
to an -moment ratio diagram.
lmrdpoints(x, y=NULL, type="p", ...) lmrdlines(x, y=NULL, type="l", ...)
lmrdpoints(x, y=NULL, type="p", ...) lmrdlines(x, y=NULL, type="l", ...)
x |
Numeric vector of |
y |
Numeric vector of |
type |
Character indicating the type of plotting.
Can be any valid value for the |
... |
Further arguments (graphics parameters),
passed to |
The functions lmrdpoints
and lmrdlines
are equivalent to
points
and lines
respectively,
except that if argument y
is omitted, x
is assumed to be
an object that contains both -skewness and
-kurtosis values.
As in
lmrd
, it can be a vector with elements named
"t_3"
and "t_4"
(or "tau_3"
and "tau_4"
),
a matrix or data frame with columns named
"t_3"
and "t_4"
(or "tau_3"
and "tau_4"
),
or an object of class "regdata"
(as defined in package lmomRFA).
J. R. M. Hosking [email protected]
# Plot L-moment ratio diagram of Wind from the airquality data set data(airquality) lmrd(samlmu(airquality$Wind), xlim=c(-0.2, 0.2)) # Sample L-moments of each month's data ( lmom.monthly <- with(airquality, t(sapply(5:9, function(mo) samlmu(Wind[Month==mo])))) ) # Add the monthly values to the plot lmrdpoints(lmom.monthly, pch=19, col="blue") # Draw an L-moment ratio diagram and add a line for the # Weibull distribution lmrd(xaxs="i", yaxs="i", las=1) weimom <- sapply( seq(0, 0.9, by=0.01), function(tau3) lmrwei(pelwei(c(0,1,tau3)), nmom=4) ) lmrdlines(t(weimom), col='darkgreen', lwd=2)
# Plot L-moment ratio diagram of Wind from the airquality data set data(airquality) lmrd(samlmu(airquality$Wind), xlim=c(-0.2, 0.2)) # Sample L-moments of each month's data ( lmom.monthly <- with(airquality, t(sapply(5:9, function(mo) samlmu(Wind[Month==mo])))) ) # Add the monthly values to the plot lmrdpoints(lmom.monthly, pch=19, col="blue") # Draw an L-moment ratio diagram and add a line for the # Weibull distribution lmrd(xaxs="i", yaxs="i", las=1) weimom <- sapply( seq(0, 0.9, by=0.01), function(tau3) lmrwei(pelwei(c(0,1,tau3)), nmom=4) ) lmrdlines(t(weimom), col='darkgreen', lwd=2)
Computes the -moments or trimmed
-moments
of a probability distribution
given its cumulative distribution function (for function
lmrp
)
or quantile function (for function lmrq
).
lmrp(pfunc, ..., bounds=c(-Inf,Inf), symm=FALSE, order=1:4, ratios=TRUE, trim=0, acc=1e-6, subdiv=100, verbose=FALSE) lmrq(qfunc, ..., symm=FALSE, order=1:4, ratios=TRUE, trim=0, acc=1e-6, subdiv=100, verbose=FALSE)
lmrp(pfunc, ..., bounds=c(-Inf,Inf), symm=FALSE, order=1:4, ratios=TRUE, trim=0, acc=1e-6, subdiv=100, verbose=FALSE) lmrq(qfunc, ..., symm=FALSE, order=1:4, ratios=TRUE, trim=0, acc=1e-6, subdiv=100, verbose=FALSE)
pfunc |
Cumulative distribution function. |
qfunc |
Quantile function. |
... |
Arguments to |
bounds |
Either a vector of length 2, containing the lower and upper bounds of the distribution, or a function that calculates these bounds given the distribution parameters as inputs. |
symm |
For For If the distribution is symmetric, odd-order |
order |
Orders of the |
ratios |
Logical. If |
trim |
Degree of trimming.
If a single value, symmetric trimming of the specified degree will be used.
If a vector of length 2, the two values
indicate the degrees of trimming at the lower and upper ends of the
“conceptual sample” (Elamir and Seheult, 2003) of order statistics
that is used to define the trimmed |
acc |
Requested accuracy. The function will try to achieve
this level of accuracy, as relative error for |
subdiv |
Maximum number of subintervals used in numerical integration. |
verbose |
Logical. If |
Computations use expressions in Hosking (2007):
eq. (7) for lmrp
, eq. (5) for lmrq
.
Integrals in those expressions are computed by numerical integration.
If verbose
is FALSE
and ratios
is FALSE
,
a numeric vector containing the -moments.
If verbose
is FALSE
and ratios
is TRUE
,
a numeric vector containing the -moments (of orders 1 and 2)
and
-moment ratios (of orders 3 and higher).
If verbose
is TRUE
, a data frame with columns as follows:
value |
|
abs.error |
Estimate of the absolute error in the computed value. |
message |
|
pfunc
and qfunc
can be either the standard R form of
cumulative distribution function or quantile function
(i.e. for a distribution with parameters, the first argument is the
variate
or the probability
and the next
arguments
are the parameters of the distribution) or the
cdf...
or
qua...
forms used throughout the lmom package
(i.e. the first argument is the variate or probability
and the second argument is a vector containing the parameter values).
Even for the R form, however, starting values for the parameters
are supplied as a vector
start
.
If bounds
is a function, its arguments must match
the distribution parameter arguments of pfunc
:
either a single vector, or a separate argument for each parameter.
Arguments bounds
, symm
, order
,
ratios
, trim
, acc
, subdiv
, and verbose
cannot be abbreviated and must be specified by their full names
(if abbreviated, the names would be matched to the arguments of
pfunc
or qfunc
).
In package lmom versions 1.6 and earlier, the “Details” section stated that
“Integrals in those expressions are computed by numerical integration,
using the R function integrate
”.
As of version 2.0, numerical integration uses an internal function that directly calls
(slightly modified versions of) Fortran routines in QUADPACK (Piessens et al. 1983).
R's own integrate
function uses C code “based on” the QUADPACK routines,
but in R versions 2.12.0 through 3.0.1 did not in every case reproduce the results
that would have been obtained with the Fortran code (this is R bug PR#15219).
J. R. M. Hosking [email protected]
Elamir, E. A. H., and Seheult, A. H. (2003). Trimmed L-moments. Computational Statistics and Data Analysis, 43, 299-314.
Hosking, J. R. M. (2007). Some theory and practical uses of trimmed L-moments. Journal of Statistical Planning and Inference, 137, 3024-3039.
Piessens, R., deDoncker-Kapenga, E., Uberhuber, C., and Kahaner, D. (1983). Quadpack: a Subroutine Package for Automatic Integration. Springer Verlag.
lmrexp
to compute (untrimmed) -moments of specific distributions.
samlmu
to compute (trimmed or untrimmed) -moments of a data sample.
pelp
and pelexp
,
to compute the parameters of a distribution given its (trimmed or untrimmed) -moments.
## Generalized extreme-value (GEV) distribution ## - three ways to get its L-moments lmrp(cdfgev, c(2,3,-0.2)) lmrq(quagev, c(2,3,-0.2)) lmrgev(c(2,3,-0.2), nmom=4) ## GEV bounds specified as a vector lmrp(cdfgev, c(2,3,-0.2), bounds=c(-13,Inf)) ## GEV bounds specified as a function -- single vector of parameters gevbounds <- function(para) { k <- para[3] b <- para[1]+para[2]/k c(ifelse(k<0, b, -Inf), ifelse(k>0, b, Inf)) } lmrp(cdfgev, c(2,3,-0.2), bounds=gevbounds) ## GEV bounds specified as a function -- separate parameters pgev <- function(x, xi, alpha, k) pmin(1, pmax(0, exp(-((1-k*(x-xi)/alpha)^(1/k))))) pgevbounds <- function(xi,alpha,k) { b <- xi+alpha/k c(ifelse(k<0, b, -Inf), ifelse(k>0, b, Inf)) } lmrp(pgev, xi=2, alpha=3, k=-0.2, bounds=pgevbounds) ## Normal distribution lmrp(pnorm) lmrp(pnorm, symm=0) lmrp(pnorm, mean=2, sd=3, symm=2) # For comparison, the exact values lmrnor(c(2,3), nmom=4) # Many L-moment ratios of the exponential distribution # This may warn that "the integral is probably divergent" lmrq(qexp, order=3:20) # ... nonetheless the computed values seem accurate: # compare with the exact values, tau_r = 2/(r*(r-1)): cbind(exact=2/(3:20)/(2:19), lmrq(qexp, order=3:20, verbose=TRUE)) # Of course, sometimes the integral really is divergent ## Not run: lmrq(function(p) (1-p)^(-1.5)) ## End(Not run) # And sometimes the integral is divergent but that's not what # the warning says (at least on the author's system) lmrp(pcauchy) # Trimmed L-moments for Cauchy distribution are finite lmrp(pcauchy, symm=0, trim=1) # Works for discrete distributions too, but often requires # a larger-than-default value of 'subdiv' lmrp(ppois, lambda=5, subdiv=1000)
## Generalized extreme-value (GEV) distribution ## - three ways to get its L-moments lmrp(cdfgev, c(2,3,-0.2)) lmrq(quagev, c(2,3,-0.2)) lmrgev(c(2,3,-0.2), nmom=4) ## GEV bounds specified as a vector lmrp(cdfgev, c(2,3,-0.2), bounds=c(-13,Inf)) ## GEV bounds specified as a function -- single vector of parameters gevbounds <- function(para) { k <- para[3] b <- para[1]+para[2]/k c(ifelse(k<0, b, -Inf), ifelse(k>0, b, Inf)) } lmrp(cdfgev, c(2,3,-0.2), bounds=gevbounds) ## GEV bounds specified as a function -- separate parameters pgev <- function(x, xi, alpha, k) pmin(1, pmax(0, exp(-((1-k*(x-xi)/alpha)^(1/k))))) pgevbounds <- function(xi,alpha,k) { b <- xi+alpha/k c(ifelse(k<0, b, -Inf), ifelse(k>0, b, Inf)) } lmrp(pgev, xi=2, alpha=3, k=-0.2, bounds=pgevbounds) ## Normal distribution lmrp(pnorm) lmrp(pnorm, symm=0) lmrp(pnorm, mean=2, sd=3, symm=2) # For comparison, the exact values lmrnor(c(2,3), nmom=4) # Many L-moment ratios of the exponential distribution # This may warn that "the integral is probably divergent" lmrq(qexp, order=3:20) # ... nonetheless the computed values seem accurate: # compare with the exact values, tau_r = 2/(r*(r-1)): cbind(exact=2/(3:20)/(2:19), lmrq(qexp, order=3:20, verbose=TRUE)) # Of course, sometimes the integral really is divergent ## Not run: lmrq(function(p) (1-p)^(-1.5)) ## End(Not run) # And sometimes the integral is divergent but that's not what # the warning says (at least on the author's system) lmrp(pcauchy) # Trimmed L-moments for Cauchy distribution are finite lmrp(pcauchy, symm=0, trim=1) # Works for discrete distributions too, but often requires # a larger-than-default value of 'subdiv' lmrp(ppois, lambda=5, subdiv=1000)
Computes the parameters of a probability distribution
as a function of the -moments.
The following distributions are recognized:
pelexp |
exponential | |
pelgam |
gamma | |
pelgev |
generalized extreme-value | |
pelglo |
generalized logistic | |
pelgpa |
generalized Pareto | |
pelgno |
generalized normal | |
pelgum |
Gumbel (extreme-value type I) | |
pelkap |
kappa | |
pelln3 |
three-parameter lognormal | |
pelnor |
normal | |
pelpe3 |
Pearson type III | |
pelwak |
Wakeby | |
pelwei |
Weibull | |
pelexp(lmom) pelgam(lmom) pelgev(lmom) pelglo(lmom) pelgno(lmom) pelgpa(lmom, bound = NULL) pelgum(lmom) pelkap(lmom) pelln3(lmom, bound = NULL) pelnor(lmom) pelpe3(lmom) pelwak(lmom, bound = NULL, verbose = FALSE) pelwei(lmom, bound = NULL)
pelexp(lmom) pelgam(lmom) pelgev(lmom) pelglo(lmom) pelgno(lmom) pelgpa(lmom, bound = NULL) pelgum(lmom) pelkap(lmom) pelln3(lmom, bound = NULL) pelnor(lmom) pelpe3(lmom) pelwak(lmom, bound = NULL, verbose = FALSE) pelwei(lmom, bound = NULL)
lmom |
Numeric vector containing the |
bound |
Lower bound of the distribution. If |
verbose |
Logical: whether to print a message when not all parameters of the distribution can be computed. |
Numerical methods and accuracy are as described in
Hosking (1996, pp. 10–11).
Exception:
if pelwak
is unable to fit a Wakeby distribution using all 5 -moments,
it instead fits a generalized Pareto distribution to the first 3
-moments.
(The corresponding routine in the LMOMENTS Fortran package
would attempt to fit a Wakeby distribution with lower bound zero.)
The kappa and Wakeby distributions have 4 and 5 parameters respectively
but cannot attain all possible values of the first 4 or 5 -moments.
Function
pelkap
can fit only kappa distributions with
(the limit is the
relation satisfied by the generalized logistic distribution),
and will give an error if
lmom
does not satisfy this constraint.
Function pelwak
can fit a Wakeby distribution only if
the values, when plotted on an
-moment ratio diagram,
lie above a line plotted by
lmrd(distributions="WAK.LB")
,
and if satisfies additional constraints;
in other cases
pelwak
will fit a generalized Pareto distribution
(a special case of the Wakeby distribution) to the first three -moments.
A numeric vector containing the parameters of the distribution.
J. R. M. Hosking [email protected]
Hosking, J. R. M. (1996).
Fortran routines for use with the method of -moments, Version 3.
Research Report RC20525, IBM Research Division, Yorktown Heights, N.Y.
pelp
for parameter estimation of a general distribution
specified by its cumulative distribution function or quantile function.
lmrexp
, etc., to compute the -moments
of a distribution given its parameters.
For individual distributions, see their cumulative distribution functions:
cdfexp |
exponential | |
cdfgam |
gamma | |
cdfgev |
generalized extreme-value | |
cdfglo |
generalized logistic | |
cdfgpa |
generalized Pareto | |
cdfgno |
generalized normal | |
cdfgum |
Gumbel (extreme-value type I) | |
cdfkap |
kappa | |
cdfln3 |
three-parameter lognormal | |
cdfnor |
normal | |
cdfpe3 |
Pearson type III | |
cdfwak |
Wakeby | |
cdfwei |
Weibull | |
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone) # Fit a GEV distribution pelgev(lmom)
# Sample L-moments of Ozone from the airquality data data(airquality) lmom <- samlmu(airquality$Ozone) # Fit a GEV distribution pelgev(lmom)
Computes the parameters of a probability distribution
as a function of the -moments or trimmed
-moments.
pelp(lmom, pfunc, start, bounds = c(-Inf, Inf), type = c("n", "s", "ls", "lss"), ratios = NULL, trim = NULL, method = "nlm", acc = 1e-5, subdiv = 100, ...) pelq(lmom, qfunc, start, type = c("n", "s", "ls", "lss"), ratios = NULL, trim = NULL, method = "nlm", acc = 1e-5, subdiv = 100, ...)
pelp(lmom, pfunc, start, bounds = c(-Inf, Inf), type = c("n", "s", "ls", "lss"), ratios = NULL, trim = NULL, method = "nlm", acc = 1e-5, subdiv = 100, ...) pelq(lmom, qfunc, start, type = c("n", "s", "ls", "lss"), ratios = NULL, trim = NULL, method = "nlm", acc = 1e-5, subdiv = 100, ...)
lmom |
Numeric vector containing the |
pfunc |
Cumulative distribution function of the distribution. |
qfunc |
Quantile function of the distribution. |
start |
Vector of starting values for the parameters. |
bounds |
Either a vector of length 2, containing the lower and upper bounds of the distribution, or a function that calculates these bounds given the distribution parameters as inputs. |
type |
Type of distribution, i.e. how it is parametrized. Must be one of the following:
For more details, see the “Distribution type” section below. |
ratios |
Logical or |
trim |
The degree of trimming corresponding to the |
method |
Method used to estimate the shape parameters
(i.e. all parameters other than the location and scale parameters, if any).
Valid values are |
acc |
Requested accuracy for the estimated parameters. This will be absolute accuracy for shape parameters, relative accuracy for a scale parameter, and absolute accuracy of the location parameter divided by the scale parameter for a location parameter. |
subdiv |
Maximum number of subintervals used in the numerical integration
that computes |
... |
Further arguments will be passed to the optimization function
( |
For shape parameters, numerical optimization is used to
find parameter values for which the population -moments or
-moment ratios
are equal to the values supplied in
lmom
.
Computation of -moments or
-moment ratios
uses functions
lmrp
(for pelp
) or lmrq
(for pelq
).
Numerical optimization uses R functions nlm
(if method="nlm"
),
uniroot
(if method="uniroot"
), or
optim
with the specified method (for the other values of method
).
Function uniroot
uses one-dimensional root-finding,
while functions nlm
and optim
try to minimize
a criterion function that is the sum of squared differences between the
population -moments or
-moment ratios and the values supplied in
lmom
.
Location and scale parameters are then estimated noniteratively.
In all cases, the calculation of population -moments and
-moment ratios is performed by function
lmrp
or lmrq
(when using pelp
or pelq
respectively).
This approach is very crude. Nonetheless, it is often effective in practice. As in all numerical optimizations, success may depend on the way that the distribution is parametrized and on the particular choice of starting values for the parameters.
A list with components:
para |
Numeric vector containing the estimated parameters of the distribution. |
code |
An integer indicating the result of the numerical optimization
used to estimate the shape parameters. It is For method For method For the other methods, the |
The length of lmom
should be (at least) the highest
order of -moment used in the estimation procedure. For a distribution
with
parameters this is
if
type="lss"
and otherwise.
pfunc
and qfunc
can be either the standard R form of
cumulative distribution function or quantile function
(i.e. for a distribution with parameters, the first argument is the
variate
or the probability
and the next
arguments
are the parameters of the distribution) or the
cdf...
or
qua...
forms used throughout the lmom package
(i.e. the first argument is the variate or probability
and the second argument is a vector containing the parameter values).
Even for the R form, however, starting values for the parameters
are supplied as a vector
start
.
If bounds
is a function, its arguments must match
the distribution parameter arguments of pfunc
:
either a single vector, or a separate argument for each parameter.
It is assumed that location and scale parameters come first in
the set of parameters of the distribution. Specifically:
if type="ls"
or type="lss"
, it is assumed
that the first parameter is the location parameter and
that the second parameter is the scale parameter;
if type="s"
it is assumed
that the first parameter is the scale parameter.
It is important that the length of start
be equal to the number
of parameters of the distribution. Starting values for
location and scale parameters should be included in start
,
even though they are not used.
If start
has the wrong length, it is possible that
meaningless results will be returned without any warning being issued.
The type
argument affects estimation as follows.
We assume that location and scale parameters are and
respectively, and that the shape parameters (if there are any)
are collectively designated by
.
If type="ls"
, then the -moment ratios
depend only on the shape parameters. If there are any shape parameters,
they are estimated by equating the sample
-moment ratios of orders
3, 4, etc., to the population
-moment ratios
and solving the resulting equations for the shape parameters
(using as many equations as there are shape parameters).
The
-moment
is a multiple of
, the multiplier
being a function only of
.
is estimated by dividing the second sample
-moment
by the multiplier function evaluated at the estimated value of
.
The
-moment
is
plus
a function of
and
.
is estimated by subtracting from the first sample
-moment
the function evaluated at the estimated values of
and
.
If type="lss"
, then
the -moment ratios of odd order,
, are zero and
the
-moment ratios of even order,
,
depend only on the shape parameters. If there are any shape parameters,
they are estimated by equating the sample
-moment ratios of orders
4, 6, etc., to the population
-moment ratios
and solving the resulting equations for the shape parameters
(using as many equations as there are shape parameters).
Parameters
and
are estimated as in case when
type="ls"
.
If type="s"
, then the -moments divided by
,
i.e.
,
depend only on the shape parameters. If there are any shape parameters,
they are estimated by equating the sample
-moments
(divided by the first sample
-moment) of orders 2, 3, etc.,
to the corresponding population
-moments
(divided by the first population
-moment)
and solving the resulting equations
(as many equations as there are shape parameters).
The
-moment
is a multiple of
, the multiplier
being a function only of
.
is estimated by dividing the first sample
-moment
by the multiplier function evaluated at the estimated value of
.
If type="n"
, then all parameters are shape parameters.
They are estimated by equating the sample -moments of orders
1, 2, etc., to the population
-moments
and solving the resulting equations for the parameters
(using as many equations as there are parameters).
If ratios
or trim
is NULL
, appropriate values will be inferred
by inspecting the names of lmom
. It is assumed that lmom
was generated by a call to samlmu
, lmrp
, or lmrq
;
in this case its names will reflect the values of ratios
and trim
used in that call.
If in this case lmom
has no names, default values
ratios=TRUE
and trim=0
will be used.
This inference is made in order to reduce the need to specify the
orders of trimming repetitively.
For example, a distribution with quantile function qfunc
can be
fitted to (1,1)-trimmed -moments of data in
x
by
lmom <- samlmu(x, trim=1) fit <- pelq(lmom, qfunc, start=...)
There is no need to specify trim
both in the call to samlmu
and the call to pelq
.
J. R. M. Hosking [email protected]
pelexp
for parameter estimation of specific distributions.
## Gamma distribution -- rewritten so that its first parameter ## is a scale parameter my.pgamma <- function(x, scale, shape) pgamma(x, shape=shape, scale=scale) pelp(c(5,2), my.pgamma, start=c(1,1), bounds=c(0,Inf), type="s") # We can also do the estimation suppressing our knowledge # that one parameter is a shape parameter. pelp(c(5,2), my.pgamma, start=c(1,1), bounds=c(0,Inf), type="n") rm(my.pgamma) ## Kappa distribution -- has location, scale and 2 shape parameters # Estimate via pelq pel.out <- pelq(c(10,5,0.3,0.15), quakap, start=c(0,1,0,0), type="ls") pel.out # Check that L-moments of estimated distribution agree with the # L-moments input to pelq() lmrkap(pel.out$para) # Compare with the distribution-specific routine pelkap pelkap(c(10,5,0.3,0.15)) rm(pel.out) # Similar results -- what's the advantage of the specific routine? system.time(pelq(c(10,5,0.3,0.15), quakap, start=c(0,1,0,0), type="ls")) system.time(pelkap(c(10,5,0.3,0.15))) # Caution -- pelq() will not check that estimates are reasonable lmom <- c(10,5,0.2,0.25) pel.out <- pelq(lmom, quakap, start=c(0,1,0,0), type="ls") pel.out lmrkap(pel.out$para) # should be close to lmom, but tau_3 and tau_4 are not # What happened? pelkap will tell us try(pelkap(lmom)) rm(lmom, pel.out) ## Inverse Gaussian -- don't have explicit estimators for this ## distribution, but can use numerical methods # # CDF of inverse gaussian distribution pig <- function(x, mu, lambda) { temp <- suppressWarnings(sqrt(lambda/x)) xx <- pnorm(temp*(x/mu-1))+exp(2*lambda/mu+pnorm(temp*(x/mu+1), lower.tail=FALSE, log.p=TRUE)) out <- ifelse(x<=0, 0, xx) out } # Fit to ozone data data(airquality) (lmom<-samlmu(airquality$Ozone)) pel.out <- pelp(lmom[1:2], pig, start=c(10,10), bounds=c(0,Inf)) pel.out # First four L-moments of fitted distribution, # for comparison with sample L-moments lmrp(pig, pel.out$para[1], pel.out$para[2], bounds=c(0,Inf)) rm(pel.out) ## A Student t distribution with location and scale parameters # qstu <- function(p, xi, alpha, df) xi + alpha * qt(p, df) # Estimate parameters. Distribution is symmetric: use type="lss" pelq(c(3,5,0,0.2345), qstu, start=c(0,1,10), type="lss") # Doesn't converge (at least on the author's system) -- # try a different parametrization qstu2 <- function(p, xi, alpha, shape) xi + alpha * qt(p, 1/shape) # Now it converges pelq(c(3,5,0,0.2345), qstu2, start=c(0,1,0.1), type="lss") # Or try a different optimization method pelq(c(3,5,0,0.2345), qstu, start=c(0,1,10), type="lss", method="uniroot", lower=2, upper=100) ## With trimmed L-moments, we can fit this distribution even when ## it does not have a finite mean ('df' less than 1) set.seed(123456) dat <- qstu(runif(1000), xi=3, alpha=5, df=0.75) lmom <- samlmu(dat, trim=1) lmom # Note that pelq() infers 'trim=1' from the names of 'lmom' pelq(lmom, qstu, start=c(0,1,10), type="lss", method="uniroot", lower=0.51, upper=100) rm(qstu, qstu2, dat, lmom)
## Gamma distribution -- rewritten so that its first parameter ## is a scale parameter my.pgamma <- function(x, scale, shape) pgamma(x, shape=shape, scale=scale) pelp(c(5,2), my.pgamma, start=c(1,1), bounds=c(0,Inf), type="s") # We can also do the estimation suppressing our knowledge # that one parameter is a shape parameter. pelp(c(5,2), my.pgamma, start=c(1,1), bounds=c(0,Inf), type="n") rm(my.pgamma) ## Kappa distribution -- has location, scale and 2 shape parameters # Estimate via pelq pel.out <- pelq(c(10,5,0.3,0.15), quakap, start=c(0,1,0,0), type="ls") pel.out # Check that L-moments of estimated distribution agree with the # L-moments input to pelq() lmrkap(pel.out$para) # Compare with the distribution-specific routine pelkap pelkap(c(10,5,0.3,0.15)) rm(pel.out) # Similar results -- what's the advantage of the specific routine? system.time(pelq(c(10,5,0.3,0.15), quakap, start=c(0,1,0,0), type="ls")) system.time(pelkap(c(10,5,0.3,0.15))) # Caution -- pelq() will not check that estimates are reasonable lmom <- c(10,5,0.2,0.25) pel.out <- pelq(lmom, quakap, start=c(0,1,0,0), type="ls") pel.out lmrkap(pel.out$para) # should be close to lmom, but tau_3 and tau_4 are not # What happened? pelkap will tell us try(pelkap(lmom)) rm(lmom, pel.out) ## Inverse Gaussian -- don't have explicit estimators for this ## distribution, but can use numerical methods # # CDF of inverse gaussian distribution pig <- function(x, mu, lambda) { temp <- suppressWarnings(sqrt(lambda/x)) xx <- pnorm(temp*(x/mu-1))+exp(2*lambda/mu+pnorm(temp*(x/mu+1), lower.tail=FALSE, log.p=TRUE)) out <- ifelse(x<=0, 0, xx) out } # Fit to ozone data data(airquality) (lmom<-samlmu(airquality$Ozone)) pel.out <- pelp(lmom[1:2], pig, start=c(10,10), bounds=c(0,Inf)) pel.out # First four L-moments of fitted distribution, # for comparison with sample L-moments lmrp(pig, pel.out$para[1], pel.out$para[2], bounds=c(0,Inf)) rm(pel.out) ## A Student t distribution with location and scale parameters # qstu <- function(p, xi, alpha, df) xi + alpha * qt(p, df) # Estimate parameters. Distribution is symmetric: use type="lss" pelq(c(3,5,0,0.2345), qstu, start=c(0,1,10), type="lss") # Doesn't converge (at least on the author's system) -- # try a different parametrization qstu2 <- function(p, xi, alpha, shape) xi + alpha * qt(p, 1/shape) # Now it converges pelq(c(3,5,0,0.2345), qstu2, start=c(0,1,0.1), type="lss") # Or try a different optimization method pelq(c(3,5,0,0.2345), qstu, start=c(0,1,10), type="lss", method="uniroot", lower=2, upper=100) ## With trimmed L-moments, we can fit this distribution even when ## it does not have a finite mean ('df' less than 1) set.seed(123456) dat <- qstu(runif(1000), xi=3, alpha=5, df=0.75) lmom <- samlmu(dat, trim=1) lmom # Note that pelq() infers 'trim=1' from the names of 'lmom' pelq(lmom, qstu, start=c(0,1,10), type="lss", method="uniroot", lower=0.51, upper=100) rm(qstu, qstu2, dat, lmom)
Computes the “unbiased” sample (trimmed) -moments
and
-moment ratios of a data vector.
samlmu(x, nmom=4, sort.data=TRUE, ratios=sort.data, trim=0) samlmu.s(x, nmom=4, sort.data=TRUE, ratios=sort.data, trim=0) .samlmu(x, nmom=4)
samlmu(x, nmom=4, sort.data=TRUE, ratios=sort.data, trim=0) samlmu.s(x, nmom=4, sort.data=TRUE, ratios=sort.data, trim=0) .samlmu(x, nmom=4)
x |
A numeric vector. |
nmom |
Number of |
sort.data |
Logical: whether the |
ratios |
Logical. If |
trim |
Degree of trimming.
If a single value, symmetric trimming of the specified degree will be used.
If a vector of length 2, the two values
indicate the degrees of trimming at the lower and upper ends of the
“conceptual sample” (Elamir and Seheult, 2003) of order statistics
that is used to define the trimmed |
samlmu
and samlmu.s
are functionally identical.
samlmu
calls a Fortran routine internally, and is usually faster.
samlmu.s
is written entirely in the S language; it is provided
so that users can conveniently see how the calculations are done.
.samlmu
is a “bare-bones” version for use in programming.
It gives an error if x
contains missing values,
computes -moment ratios and not
-moments,
does not give a warning if all the elements of
x
are equal,
and returns its result in an unnamed vector.
Sample -moments are defined in Hosking (1990).
Calculations use the algorithm given in Hosking (1996, p.14).
Trimmed sample -moments are defined as in Hosking (2007), eq. (15)
(a small extension of Elamir and Seheult (2003), eq. (16)).
They are calculated from the untrimmed sample
-moments
using the recursions of Hosking (2007), eqs. (12)-(13).
If ratios
is TRUE
, a numeric vector containing
the -moments and
-moment ratios,
in the order
,
,
,
, etc.
If
ratios
is FALSE
, a numeric vector containing the -moments
in the order
,
,
,
, etc.
The term “trimmed” is used in a different sense from
its usual meaning in robust statistics.
In particular, the first trimmed -moment is in general not equal to
any trimmed mean of the data sample.
J. R. M. Hosking [email protected]
Elamir, E. A. H., and Seheult, A. H. (2003). Trimmed L-moments. Computational Statistics and Data Analysis, 43, 299-314.
Hosking, J. R. M. (1990).
-moments: analysis and estimation of distributions
using linear combinations of order statistics.
Journal of the Royal Statistical Society, Series B, 52, 105-124.
Hosking, J. R. M. (1996).
Fortran routines for use with the method of -moments, Version 3.
Research Report RC20525, IBM Research Division, Yorktown Heights, N.Y.
Hosking, J. R. M. (2007). Some theory and practical uses of trimmed L-moments. Journal of Statistical Planning and Inference, 137, 3024-3039.
data(airquality) samlmu(airquality$Ozone, 6) # Trimmed L-moment ratios samlmu(airquality$Ozone, trim=1)
data(airquality) samlmu(airquality$Ozone, 6) # Trimmed L-moment ratios samlmu(airquality$Ozone, trim=1)