# TLMoments: Trimmed L-moments In TLMoments: Calculate TL-Moments and Convert Them to Distribution Parameters

## Description

Calculates empirical or theoretical Trimmed L-moments and -ratios up to a specific order. If empirical moments should be calculated, acceptable input types are numeric vectors, matrices, lists, data.frames. TLMoments is type-preservative, so the input type is also the output type. If theoretical moments should be calculated, the input type has to be of class parameters or PWMs, so an object returned by parameters, as.parameters or PWMs, as.PWMs.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58``` ```TLMoments(x, ...) ## S3 method for class 'numeric' TLMoments( x, leftrim = 0L, rightrim = 0L, max.order = 4L, na.rm = FALSE, computation.method = "auto", ... ) ## S3 method for class 'matrix' TLMoments( x, leftrim = 0L, rightrim = 0L, max.order = 4L, na.rm = FALSE, computation.method = "auto", ... ) ## S3 method for class 'list' TLMoments( x, leftrim = 0L, rightrim = 0L, max.order = 4L, na.rm = FALSE, computation.method = "auto", ... ) ## S3 method for class 'data.frame' TLMoments( x, formula, leftrim = 0L, rightrim = 0L, max.order = 4L, na.rm = FALSE, computation.method = "auto", ... ) ## S3 method for class 'PWMs' TLMoments(x, leftrim = 0L, rightrim = 0L, ...) ## S3 method for class 'parameters' TLMoments( x, leftrim = attr(x, "source")\$trimmings[1], rightrim = attr(x, "source")\$trimmings[2], max.order = 4L, ... ) ```

## Arguments

 `x` numeric data in form of vector, matrix, list, or data.frame OR an object of class parameters or PWMs. `...` additional arguments. `leftrim` integer indicating lower trimming parameter, has to be greater than 0. `rightrim` integer indicating upper trimming parameter, has to be greater than 0. `max.order` integer, maximum order of Trimmed L-moments/ratios, has to be greater than 1. `na.rm` logical, indicates if NAs should be removed. Only if empirical moments are calculated. `computation.method` character, indicating if the computation is performed via PWMs, direct, recursive, or recurrence (see References Hosking & Balakrishnan, 2015). Possible values are `auto` (default, automatically choose appropriate method), `pwm`, `direct`, `recursive`, or `recurrence`. Only if empirical moments are calculated. `formula` if `x` is data.frame. See examples.

## Value

list of two dimensions: `lambdas`/`ratios` are a numeric vector, matrix, list, or data.frame consisting of the TL-moments/TL-moment-ratios. The list has the class `TLMoments`. The object contains the following attributes:

• `leftrim`: a numeric giving the used leftrim-argument

• `rightrim`: a numeric giving the used rightrim-argument

• `order`: a integer vector with corresponding TL-moment orders

• `source`: a list with background information (used function, data, n, formula, computation method; mainly for internal purposes)

The attributes are hidden in the print-function for a clearer presentation.

## Methods (by class)

• `numeric`: TLMoments for numeric vector of data

• `matrix`: TLMoments for numeric matrix of data

• `list`: TLMoments for numeric list of data

• `data.frame`: TLMoments for numeric data.frame of data

• `PWMs`: TLMoments for PWMs-object

• `parameters`: TLMoments for parameters-object

## References

Elamir, E. A., & Seheult, A. H. (2003). Trimmed L-moments. Computational Statistics & Data Analysis, 43(3), 299-314.

Hosking, J. R. M. (1990). L-moments: analysis and estimation of distributions using linear combinations of order statistics. Journal of the Royal Statistical Society. Series B (Methodological), 105-124.

Hosking, J. R. M. (2007). Some theory and practical uses of trimmed L-moments. Journal of Statistical Planning and Inference, 137(9), 3024-3039.

Hosking, J. R. M., & Balakrishnan, N. (2015). A uniqueness result for L-estimators, with applications to L-moments. Statistical Methodology, 24, 69-80.

`PWMs`, `parameters`, `quantiles`, `summary.TLMoments`, `as.TLMoments`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52``` ```# Generating data sets: xmat <- matrix(rnorm(100), nc = 4) xvec <- xmat[, 3] xlist <- lapply(1L:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = rep(letters[1:2], each = 50), season = rep(c("S", "W"), 50), hq = as.vector(xmat) ) # Calculating TL-moments from data: TLMoments(xvec, leftrim = 0, rightrim = 1) TLMoments(xmat, leftrim = 1, rightrim = 1) TLMoments(xlist, max.order = 7) TLMoments(xdat, hq ~ station, leftrim = 0, rightrim = 2) TLMoments(xdat, hq ~ season, leftrim = 0, rightrim = 2) TLMoments(xdat, hq ~ ., leftrim = 0, rightrim = 2) # Calculating TL-moments from PWMs: TLMoments(PWMs(xvec)) TLMoments(PWMs(xmat), rightrim = 1) TLMoments(PWMs(xlist), leftrim = 1, rightrim = 1) TLMoments(PWMs(xdat, hq ~ station), leftrim = 0, rightrim = 2) TLMoments(PWMs(xdat, hq ~ station + season), leftrim = 0, rightrim = 2) TLMoments(as.PWMs(cbind(c(0.12, .41, .38, .33), c(.05, 0.28, .25, .22))), 0, 1) # Calculating TL-moments from parameters: (tlm <- TLMoments(xmat, leftrim = 0, rightrim = 1)) TLMoments(parameters(tlm, "gev")) (tlm <- TLMoments(xdat, hq ~ station, leftrim = 0, rightrim = 2)) TLMoments(parameters(tlm, "gev")) p <- as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") TLMoments(p, rightrim = 1) p <- as.parameters(cbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "gev") TLMoments(p, max.order = 6) p <- as.parameters(list( list(loc = 3, scale = 2, shape = .4), list(loc = 3, scale = 2, shape = .2) ), distr = "gev") TLMoments(p) p <- as.parameters(data.frame( station = letters[1:2], loc = c(2, 3), scale = c(2, 2), shape = c(.4, .2) ), .~station, distr = "gev") TLMoments(p) ```