Title: | Calculate TL-Moments and Convert Them to Distribution Parameters |
---|---|
Description: | Calculates empirical TL-moments (trimmed L-moments) of arbitrary order and trimming, and converts them to distribution parameters. |
Authors: | Jona Lilienthal |
Maintainer: | Jona Lilienthal <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.7.5.3 |
Built: | 2024-11-28 06:52:50 UTC |
Source: | CRAN |
Convert vector, matrix, list, or data.frame to parameters-objects.
as.parameters(..., distr = NULL) ## S3 method for class 'numeric' as.parameters(..., distr) ## S3 method for class 'matrix' as.parameters(x, distr, ...) ## S3 method for class 'list' as.parameters(x, distr, ...) ## S3 method for class 'data.frame' as.parameters(x, formula, distr, ...)
as.parameters(..., distr = NULL) ## S3 method for class 'numeric' as.parameters(..., distr) ## S3 method for class 'matrix' as.parameters(x, distr, ...) ## S3 method for class 'list' as.parameters(x, distr, ...) ## S3 method for class 'data.frame' as.parameters(x, formula, distr, ...)
... |
parameters of distribution. This can be named vectors or lists, matrices, or data.frames. See examples below. |
distr |
character giving the distribution. Function of name q\"distr\" has to be available. |
x |
numeric vector, matrix, list, or data.frame of parameters. |
formula |
if |
object of class parameters, see parameters help page.
numeric
: as.parameters for numeric data vectors
matrix
: as.parameters for numeric data matrices
list
: as.parameters for numeric data lists
data.frame
: as.parameters for numeric data.frames
# Vector input: as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") as.parameters(c(loc = 3, scale = 2, shape = .4), distr = "gev") # Names can be shortened if unambiguous: as.parameters(l = 3, sc = 2, sh = .4, distr = "gev") as.parameters(m = 3, s = 1, distr = "norm") # Wrong or ambiguous names lead to errors! ## Not run: as.parameters(l = 3, s = 2, s = .4, distr = "gev") as.parameters(loc2 = 3, scale = 2, shape = .4, distr = "gev") ## End(Not run) # If no names are given, a warning is given and they are guessed for gev, gpd, gum, and ln3. as.parameters(3, 2, .4, distr = "gev") as.parameters(c(3, 2, .4), distr = "gev") ## Not run: as.parameters(3, 2, .2, .4, distr = "gev") #=> doesn't work ## End(Not run) # Matrix input: # Parameters in matrices must have either matching rownames or colnames! as.parameters(cbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "gev") as.parameters(rbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "ln3") # If no names are given, a guess is made based on number of rows # or cols according to distribution (and a warning is given). as.parameters(matrix(1:9, nr = 3), distr = "gev") as.parameters(matrix(1:8, nc = 2), distr = "gum") # The same principles apply for list input and data.frames: # List input: as.parameters(list(list(mean = 2, sd = 1), list(mean = 0, sd = 1)), distr = "norm") as.parameters(list(c(m = 2, s = 1), c(m = 0, s = 1)), distr = "norm") as.parameters(list(c(loc = 2, scale = 1), c(0, 1)), distr = "gum") ## Not run: as.parameters(list(c(loc = 2, scale = 1), c(0, 1, 2)), distr = "gum") ## End(Not run) # Dataframe input: xdat <- data.frame(station = c(1, 2), mean = c(2, 0), sd = c(1, 1)) as.parameters(xdat, cbind(mean, sd) ~ station, distr = "norm") as.parameters(xdat, . ~ station, distr = "norm") as.parameters(xdat, cbind(mean, sd) ~ ., distr = "norm") xdat <- data.frame(station = c(1, 2), m = c(2, 0), s = c(1, 1)) as.parameters(xdat, cbind(m, s) ~ station, distr = "norm") ## Not run: as.parameters(xdat, cbind(m, s) ~ station, distr = "gev") ## End(Not run) ### # Results of as.parameters can be used in the normal TLMoments-scheme: # they can be transfered to quantiles or to TLMoments. xdat <- data.frame(station = c(1, 2), mean = c(2, 0), sd = c(1, 1)) quantiles(as.parameters(xdat, cbind(mean, sd) ~ ., distr = "norm"), c(.99)) # quantile estimation p <- as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") quantiles(p, c(.9, .95)) p <- as.parameters(cbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "gev") quantiles(p, c(.9, .95)) p <- as.parameters(list(list(mean = 2, sd = 1), list(mean = 0, sd = 1)), distr = "norm") quantiles(p, c(.95, .975)) # With magrittr library(magrittr) as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") %>% quantiles(c(.9, .99))
# Vector input: as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") as.parameters(c(loc = 3, scale = 2, shape = .4), distr = "gev") # Names can be shortened if unambiguous: as.parameters(l = 3, sc = 2, sh = .4, distr = "gev") as.parameters(m = 3, s = 1, distr = "norm") # Wrong or ambiguous names lead to errors! ## Not run: as.parameters(l = 3, s = 2, s = .4, distr = "gev") as.parameters(loc2 = 3, scale = 2, shape = .4, distr = "gev") ## End(Not run) # If no names are given, a warning is given and they are guessed for gev, gpd, gum, and ln3. as.parameters(3, 2, .4, distr = "gev") as.parameters(c(3, 2, .4), distr = "gev") ## Not run: as.parameters(3, 2, .2, .4, distr = "gev") #=> doesn't work ## End(Not run) # Matrix input: # Parameters in matrices must have either matching rownames or colnames! as.parameters(cbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "gev") as.parameters(rbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "ln3") # If no names are given, a guess is made based on number of rows # or cols according to distribution (and a warning is given). as.parameters(matrix(1:9, nr = 3), distr = "gev") as.parameters(matrix(1:8, nc = 2), distr = "gum") # The same principles apply for list input and data.frames: # List input: as.parameters(list(list(mean = 2, sd = 1), list(mean = 0, sd = 1)), distr = "norm") as.parameters(list(c(m = 2, s = 1), c(m = 0, s = 1)), distr = "norm") as.parameters(list(c(loc = 2, scale = 1), c(0, 1)), distr = "gum") ## Not run: as.parameters(list(c(loc = 2, scale = 1), c(0, 1, 2)), distr = "gum") ## End(Not run) # Dataframe input: xdat <- data.frame(station = c(1, 2), mean = c(2, 0), sd = c(1, 1)) as.parameters(xdat, cbind(mean, sd) ~ station, distr = "norm") as.parameters(xdat, . ~ station, distr = "norm") as.parameters(xdat, cbind(mean, sd) ~ ., distr = "norm") xdat <- data.frame(station = c(1, 2), m = c(2, 0), s = c(1, 1)) as.parameters(xdat, cbind(m, s) ~ station, distr = "norm") ## Not run: as.parameters(xdat, cbind(m, s) ~ station, distr = "gev") ## End(Not run) ### # Results of as.parameters can be used in the normal TLMoments-scheme: # they can be transfered to quantiles or to TLMoments. xdat <- data.frame(station = c(1, 2), mean = c(2, 0), sd = c(1, 1)) quantiles(as.parameters(xdat, cbind(mean, sd) ~ ., distr = "norm"), c(.99)) # quantile estimation p <- as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") quantiles(p, c(.9, .95)) p <- as.parameters(cbind(loc = 10, scale = 4, shape = seq(0, .4, .1)), distr = "gev") quantiles(p, c(.9, .95)) p <- as.parameters(list(list(mean = 2, sd = 1), list(mean = 0, sd = 1)), distr = "norm") quantiles(p, c(.95, .975)) # With magrittr library(magrittr) as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") %>% quantiles(c(.9, .99))
Convert vector, matrix, list, or data.frame to PWMs-objects.
as.PWMs(x, ..., order = NULL) ## S3 method for class 'numeric' as.PWMs(x, order = seq_along(x) - 1, ...) ## S3 method for class 'matrix' as.PWMs(x, order = row(x)[, 1] - 1, ...) ## S3 method for class 'list' as.PWMs(x, order = seq_along(x[[1]]) - 1, ...) ## S3 method for class 'data.frame' as.PWMs(x, formula, order = NULL, ...)
as.PWMs(x, ..., order = NULL) ## S3 method for class 'numeric' as.PWMs(x, order = seq_along(x) - 1, ...) ## S3 method for class 'matrix' as.PWMs(x, order = row(x)[, 1] - 1, ...) ## S3 method for class 'list' as.PWMs(x, order = seq_along(x[[1]]) - 1, ...) ## S3 method for class 'data.frame' as.PWMs(x, formula, order = NULL, ...)
x |
vector or matrix of PWMs. |
... |
additional arguments. |
order |
integer, corresponding order to given PWMs. If NULL, order is set to 0:(length(x)-1). |
formula |
if |
object of class PWMs, see PWMs help page.
numeric
: as.PWMs for numeric data vectors
matrix
: as.PWMs for numeric data matrices
list
: as.PWMs for numeric data lists
data.frame
: as.PWMs for numeric data.frames
xmat <- cbind(c(0.12, .41, .38, .33), c(.05, 0.28, .25, .22)) xvec <- xmat[, 1] xlist <- lapply(1:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = letters[1:3], season = c("S", "W", "S"), b0 = c(.12, .15, .05), b1 = c(.41, .33, .28), b2 = c(.38, .18, .25) ) as.PWMs(xvec) as.PWMs(xvec[-2], order = c(0, 2, 3)) as.PWMs(xmat) as.PWMs(xmat[-2, ], order = c(0, 2, 3)) as.PWMs(xlist) as.PWMs(xdat, cbind(b0, b1, b2) ~ station) as.PWMs(xdat, . ~ station + season) as.PWMs(xdat, cbind(b0, b2) ~ station, order = c(0, 2)) p <- as.PWMs(xdat, cbind(b0, b1, b2) ~ station) TLMoments(p) (p <- as.PWMs(xdat, cbind(b0, b1) ~ station)) #parameters(TLMoments(p), "gev") # => error #parameters(TLMoments(p), "gpd") # => error parameters(TLMoments(p), "gpd", u = 10) (p <- as.PWMs(xdat, cbind(b0, b2) ~ station, order = c(0, 2))) #TLMoments(p) # => error
xmat <- cbind(c(0.12, .41, .38, .33), c(.05, 0.28, .25, .22)) xvec <- xmat[, 1] xlist <- lapply(1:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = letters[1:3], season = c("S", "W", "S"), b0 = c(.12, .15, .05), b1 = c(.41, .33, .28), b2 = c(.38, .18, .25) ) as.PWMs(xvec) as.PWMs(xvec[-2], order = c(0, 2, 3)) as.PWMs(xmat) as.PWMs(xmat[-2, ], order = c(0, 2, 3)) as.PWMs(xlist) as.PWMs(xdat, cbind(b0, b1, b2) ~ station) as.PWMs(xdat, . ~ station + season) as.PWMs(xdat, cbind(b0, b2) ~ station, order = c(0, 2)) p <- as.PWMs(xdat, cbind(b0, b1, b2) ~ station) TLMoments(p) (p <- as.PWMs(xdat, cbind(b0, b1) ~ station)) #parameters(TLMoments(p), "gev") # => error #parameters(TLMoments(p), "gpd") # => error parameters(TLMoments(p), "gpd", u = 10) (p <- as.PWMs(xdat, cbind(b0, b2) ~ station, order = c(0, 2))) #TLMoments(p) # => error
Convert vector, matrix, list, or data.frame of TL-moments
or TL-moment ratios or a PWMs-object to a TLMoments-object in order
to be used with TLMoments-functions.
The first position of a vector or the first row of a matrix is
always used as the L1-moment. The ratios
argument determines if the
following positions or rows are used as TL-moments oder TL-moments ratios.
The trimming has to be given using the leftrim
and rightrim
arguments.
as.TLMoments(x, ..., leftrim, rightrim, ratios) ## S3 method for class 'numeric' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'matrix' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'list' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'data.frame' as.TLMoments(x, formula, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...)
as.TLMoments(x, ..., leftrim, rightrim, ratios) ## S3 method for class 'numeric' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'matrix' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'list' as.TLMoments(x, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...) ## S3 method for class 'data.frame' as.TLMoments(x, formula, leftrim = 0L, rightrim = 0L, ratios = FALSE, ...)
x |
vector or matrix of TL-moments (or TL-moment ratios if ratios is TRUE) or a PWMs-object. The first position or row is always used as the L1-moment, if vector or matrix are given. |
... |
additional arguments. |
leftrim , rightrim
|
integer, order of trimmed L-moments. |
ratios |
boolean, if TRUE the non-first positions or rows of x give L-moment ratios, if FALSE (default) they give L-moments. If ratios are used and the first position or row is NA, L1 is assumed to be 1! |
formula |
if |
object of class TLMoments, see PWMs help page.
numeric
: as.TLMoments for numeric data vectors
matrix
: as.TLMoments for numeric data matrices
list
: as.TLMoments for numeric data lists
data.frame
: as.TLMoments for numeric data.frames
### Vector or matrix as input xmat <- cbind(c(1, .2, .05), c(1, .2, NA), c(1.3, NA, .1)) xvec <- xmat[, 1] xlist <- lapply(1:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = rep(letters[1:3], each = 1), season = c("S", "W", "S"), L1 = c(1, 1, 1.3), L2 = c(.2, .2, .3), L3 = c(.05, .04, .1) ) as.TLMoments(xvec, rightrim = 1) as.TLMoments(xmat, rightrim = 1) as.TLMoments(xlist, rightrim = 1) as.TLMoments(xdat, cbind(L1, L2, L3) ~ station) as.TLMoments(xdat, .~station+season) as.TLMoments(xdat, cbind(L1, L2, L3) ~ .) parameters(as.TLMoments(xvec, rightrim = 0), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(1, .2, .25)), "gev")$para xmat <- cbind(c(NA, .2, -.05), c(NA, .2, .2)) xvec <- xmat[, 1] as.TLMoments(xvec, ratios = TRUE) as.TLMoments(xmat, ratios = TRUE) parameters(as.TLMoments(xvec, ratios = TRUE), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(1, .2, -.05)), "gev")$para xmat <- cbind(c(10, .2, -.05), c(10, .2, .2)) xvec <- xmat[, 1] as.TLMoments(xvec, ratios = TRUE) as.TLMoments(xmat, ratios = TRUE) parameters(as.TLMoments(xvec, ratios = TRUE), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(10, .2, -.05)), "gev")$para
### Vector or matrix as input xmat <- cbind(c(1, .2, .05), c(1, .2, NA), c(1.3, NA, .1)) xvec <- xmat[, 1] xlist <- lapply(1:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = rep(letters[1:3], each = 1), season = c("S", "W", "S"), L1 = c(1, 1, 1.3), L2 = c(.2, .2, .3), L3 = c(.05, .04, .1) ) as.TLMoments(xvec, rightrim = 1) as.TLMoments(xmat, rightrim = 1) as.TLMoments(xlist, rightrim = 1) as.TLMoments(xdat, cbind(L1, L2, L3) ~ station) as.TLMoments(xdat, .~station+season) as.TLMoments(xdat, cbind(L1, L2, L3) ~ .) parameters(as.TLMoments(xvec, rightrim = 0), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(1, .2, .25)), "gev")$para xmat <- cbind(c(NA, .2, -.05), c(NA, .2, .2)) xvec <- xmat[, 1] as.TLMoments(xvec, ratios = TRUE) as.TLMoments(xmat, ratios = TRUE) parameters(as.TLMoments(xvec, ratios = TRUE), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(1, .2, -.05)), "gev")$para xmat <- cbind(c(10, .2, -.05), c(10, .2, .2)) xvec <- xmat[, 1] as.TLMoments(xvec, ratios = TRUE) as.TLMoments(xmat, ratios = TRUE) parameters(as.TLMoments(xvec, ratios = TRUE), "gev") #lmomco::lmom2par(lmomco::vec2lmom(c(10, .2, -.05)), "gev")$para
Calculation of the empirical or theoretical covariance matrix of objects
of the classes PWMs
, TLMoments
, parameters
, or quantiles
.
est_cov(x, ...) ## S3 method for class 'PWMs' est_cov(x, select = attr(x, "order"), ...) ## S3 method for class 'TLMoments' est_cov(x, select = attr(x, "order"), ...) ## S3 method for class 'parameters' est_cov(x, select = c("loc", "scale", "shape"), ...) ## S3 method for class 'quantiles' est_cov(x, select = attr(x, "p"), ...)
est_cov(x, ...) ## S3 method for class 'PWMs' est_cov(x, select = attr(x, "order"), ...) ## S3 method for class 'TLMoments' est_cov(x, select = attr(x, "order"), ...) ## S3 method for class 'parameters' est_cov(x, select = c("loc", "scale", "shape"), ...) ## S3 method for class 'quantiles' est_cov(x, select = attr(x, "p"), ...)
x |
object of |
... |
additional arguments given to the sub-functions: |
select |
numeric oder character vector specifying a subset of the covariance matrix. If not specified the full covariance matrix is returned. |
Covariance matrices of PWMs
and TLMoments
are calculated without parametric
assumption by default. Covariance matrices of parameters
and quantiles
use
parametric assumption based on their stored distribution attribute (only GEV at the moment).
Parametric (GEV) calculation can be enforced by specifying distr=\"gev\"
, non-parametric
calculation by using np.cov=TRUE
.
numeric matrix (if x
is of class PWMs
, parameters
, or
quantiles
) or a list of two matrices (lambdas
and ratios
, if
x
is of class TLMoments
).
PWMs
, TLMoments
, parameters
, quantiles
### 1: PWMs: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of PWMs normally without parametric assumption: est_cov(PWMs(xvec)) est_cov(PWMs(xvec), select = 0:1) est_cov(PWMs(xmat)) est_cov(PWMs(xmat), select = 3) est_cov(PWMs(xmat[, 1, drop = FALSE]), select = 2:3) # Parametric assumptions (only GEV by now) can be used: est_cov(PWMs(xvec), distr = "gev") est_cov(PWMs(xvec), distr = "gev", select = c(1, 3)) ## Not run: cov(t(replicate(100000, as.vector(PWMs(cbind(rgev(100, shape = .1), rgev(100, shape = .3)), max.order = 1))) )) ## End(Not run) ### 2. TLMoments: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of TLMoments normally without parametric assumption: est_cov(TLMoments(xvec)) est_cov(TLMoments(xvec, rightrim = 1)) est_cov(TLMoments(xvec), select = 3:4) # Parametric assumptions (only GEV by now) can be used: est_cov(TLMoments(xvec), distr = "gev") # Matrix inputs est_cov(TLMoments(xmat)) est_cov(TLMoments(xmat), select = 3:4) est_cov(TLMoments(xmat[, 1, drop = FALSE]), select = 3:4) # Covariance of theoretical TLMoments only with parametric assumption: est_cov(as.TLMoments(c(14, 4, 1)), distr = "gev", set.n = 100) est_cov(as.TLMoments(c(14, 4, 1), rightrim = 1), distr = "gev", set.n = 100) # Regionalized TLMoments est_cov(regionalize(TLMoments(xmat), c(.75, .25))) est_cov(regionalize(TLMoments(xmat), c(.75, .25)), distr = "gev", select = 3:4) ### 3. Parameters: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of parameters normally with parametric assumption: est_cov(parameters(TLMoments(xvec), "gev")) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev")) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev"), select = c("scale", "shape")) # A nonparametric estimation can be enforced with np.cov: est_cov(parameters(TLMoments(xvec), "gev"), np.cov = TRUE) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev"), np.cov = TRUE) # Matrix inputs est_cov(parameters(TLMoments(xmat), "gev")) est_cov(parameters(TLMoments(xmat), "gev"), select = "shape") est_cov(parameters(TLMoments(xmat[, 1]), "gev"), select = "shape") # Theoretical values (leftrim and/or rightrim have to be specified) para <- as.parameters(loc = 10, scale = 5, shape = .2, distr = "gev") est_cov(para, set.n = 100) est_cov(para, rightrim = 1, set.n = 100) ## Not run: var(t(replicate(10000, parameters(TLMoments(rgev(100, 10, 5, .2)), "gev")))) ## End(Not run) ## Not run: var(t(replicate(10000, parameters(TLMoments(rgev(100, 10, 5, .2), rightrim = 1), "gev")))) ## End(Not run) # Parameter estimates from regionalized TLMoments: est_cov(parameters(regionalize(TLMoments(xmat), c(.75, .25)), "gev")) ### 4. Quantiles: xvec <- rgev(100, shape = .2) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of parameters normally with parametric assumption: q <- quantiles(parameters(TLMoments(xvec), "gev"), c(.9, .95, .99)) est_cov(q) est_cov(q, select = c("0.9", "0.99")) est_cov(q, select = .95) # A nonparametric estimation can be enforced with np.cov: est_cov(q, np.cov = TRUE) # Matrix inputs param <- parameters(TLMoments(xmat, 0, 1), "gev") q <- quantiles(param, c(.9, .95, .99)) est_cov(q) est_cov(q, select = .99) param <- parameters(TLMoments(xmat[, 1, drop = FALSE], 0, 1), "gev") q <- quantiles(param, c(.9, .95, .99)) est_cov(q, select = .99) # Theoretical values q <- quantiles(as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev"), c(.9, .99)) est_cov(q) est_cov(q, leftrim = 0, rightrim = 1) est_cov(q, leftrim = 0, rightrim = 1, set.n = 100) # Quantile estimates from regionalized TLMoments: param <- parameters(regionalize(TLMoments(xmat), c(.75, .25)), "gev") est_cov(quantiles(param, c(.9, .99)))
### 1: PWMs: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of PWMs normally without parametric assumption: est_cov(PWMs(xvec)) est_cov(PWMs(xvec), select = 0:1) est_cov(PWMs(xmat)) est_cov(PWMs(xmat), select = 3) est_cov(PWMs(xmat[, 1, drop = FALSE]), select = 2:3) # Parametric assumptions (only GEV by now) can be used: est_cov(PWMs(xvec), distr = "gev") est_cov(PWMs(xvec), distr = "gev", select = c(1, 3)) ## Not run: cov(t(replicate(100000, as.vector(PWMs(cbind(rgev(100, shape = .1), rgev(100, shape = .3)), max.order = 1))) )) ## End(Not run) ### 2. TLMoments: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of TLMoments normally without parametric assumption: est_cov(TLMoments(xvec)) est_cov(TLMoments(xvec, rightrim = 1)) est_cov(TLMoments(xvec), select = 3:4) # Parametric assumptions (only GEV by now) can be used: est_cov(TLMoments(xvec), distr = "gev") # Matrix inputs est_cov(TLMoments(xmat)) est_cov(TLMoments(xmat), select = 3:4) est_cov(TLMoments(xmat[, 1, drop = FALSE]), select = 3:4) # Covariance of theoretical TLMoments only with parametric assumption: est_cov(as.TLMoments(c(14, 4, 1)), distr = "gev", set.n = 100) est_cov(as.TLMoments(c(14, 4, 1), rightrim = 1), distr = "gev", set.n = 100) # Regionalized TLMoments est_cov(regionalize(TLMoments(xmat), c(.75, .25))) est_cov(regionalize(TLMoments(xmat), c(.75, .25)), distr = "gev", select = 3:4) ### 3. Parameters: xvec <- rgev(100, shape = .1) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of parameters normally with parametric assumption: est_cov(parameters(TLMoments(xvec), "gev")) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev")) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev"), select = c("scale", "shape")) # A nonparametric estimation can be enforced with np.cov: est_cov(parameters(TLMoments(xvec), "gev"), np.cov = TRUE) est_cov(parameters(TLMoments(xvec, rightrim = 1), "gev"), np.cov = TRUE) # Matrix inputs est_cov(parameters(TLMoments(xmat), "gev")) est_cov(parameters(TLMoments(xmat), "gev"), select = "shape") est_cov(parameters(TLMoments(xmat[, 1]), "gev"), select = "shape") # Theoretical values (leftrim and/or rightrim have to be specified) para <- as.parameters(loc = 10, scale = 5, shape = .2, distr = "gev") est_cov(para, set.n = 100) est_cov(para, rightrim = 1, set.n = 100) ## Not run: var(t(replicate(10000, parameters(TLMoments(rgev(100, 10, 5, .2)), "gev")))) ## End(Not run) ## Not run: var(t(replicate(10000, parameters(TLMoments(rgev(100, 10, 5, .2), rightrim = 1), "gev")))) ## End(Not run) # Parameter estimates from regionalized TLMoments: est_cov(parameters(regionalize(TLMoments(xmat), c(.75, .25)), "gev")) ### 4. Quantiles: xvec <- rgev(100, shape = .2) xmat <- cbind(rgev(100, shape = .1), rgev(100, shape = .3)) # Covariance estimation of parameters normally with parametric assumption: q <- quantiles(parameters(TLMoments(xvec), "gev"), c(.9, .95, .99)) est_cov(q) est_cov(q, select = c("0.9", "0.99")) est_cov(q, select = .95) # A nonparametric estimation can be enforced with np.cov: est_cov(q, np.cov = TRUE) # Matrix inputs param <- parameters(TLMoments(xmat, 0, 1), "gev") q <- quantiles(param, c(.9, .95, .99)) est_cov(q) est_cov(q, select = .99) param <- parameters(TLMoments(xmat[, 1, drop = FALSE], 0, 1), "gev") q <- quantiles(param, c(.9, .95, .99)) est_cov(q, select = .99) # Theoretical values q <- quantiles(as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev"), c(.9, .99)) est_cov(q) est_cov(q, leftrim = 0, rightrim = 1) est_cov(q, leftrim = 0, rightrim = 1, set.n = 100) # Quantile estimates from regionalized TLMoments: param <- parameters(regionalize(TLMoments(xmat), c(.75, .25)), "gev") est_cov(quantiles(param, c(.9, .99)))
Internal function. Use est_cov. Description not done yet.
est_paramcov(x, distr = "", leftrim = 0L, rightrim = 0L, ...) ## S3 method for class 'numeric' est_paramcov(x, distr, leftrim = 0L, rightrim = 0L, np.cov = FALSE, ...) ## S3 method for class 'matrix' est_paramcov( x, distr, leftrim = 0L, rightrim = 0L, np.cov = FALSE, reg.weights = NULL, ... ) ## S3 method for class 'parameters' est_paramcov( x, distr = attr(x, "distribution"), leftrim = attr(x, "source")$trimmings[1], rightrim = attr(x, "source")$trimmings[2], set.n = NA, ... )
est_paramcov(x, distr = "", leftrim = 0L, rightrim = 0L, ...) ## S3 method for class 'numeric' est_paramcov(x, distr, leftrim = 0L, rightrim = 0L, np.cov = FALSE, ...) ## S3 method for class 'matrix' est_paramcov( x, distr, leftrim = 0L, rightrim = 0L, np.cov = FALSE, reg.weights = NULL, ... ) ## S3 method for class 'parameters' est_paramcov( x, distr = attr(x, "distribution"), leftrim = attr(x, "source")$trimmings[1], rightrim = attr(x, "source")$trimmings[2], set.n = NA, ... )
x |
numeric vector or matrix containing data OR an object of parameters. |
distr |
character indicating the distribution from which the parameters are calculated. If x is parameters-object, distr does not need to be specified. |
leftrim , rightrim
|
lower and upper trimming parameter used for parameter calculation, have to be non-negative integers. |
... |
additional arguments. |
np.cov |
boolean, if TRUE no parametric assumptions are used to calculate the covariance matrix (default FALSE). |
reg.weights |
numeric vector of weights for regionalized TLMoments. |
set.n |
hypothetical data length n if theoretical values are given. |
numeric matrix
### Numeric vectors x <- rgev(500, shape = .2) parameters(TLMoments(x), "gev") est_paramcov(x, "gev", 0, 0) #cov(t(replicate(10000, parameters(TLMoments(rgev(500, shape = .2)), "gev")))) parameters(TLMoments(x, rightrim = 1), "gev") est_paramcov(x, "gev", 0, 1) #cov(t(replicate(10000, # parameters(TLMoments(rgev(500, shape = .2), rightrim = 1), "gev") #))) parameters(TLMoments(x, rightrim = 2), "gev") est_paramcov(x, "gev", 0, 2) #cov(t(replicate(10000, # parameters(TLMoments(rgev(500, shape = .2), rightrim = 2), "gev") #))) ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) parameters(TLMoments(x), "gev") est_paramcov(x, "gev", 0, 0) #cov(t(replicate(5000, # as.vector(parameters(TLMoments(matrix(rgev(600, shape = .2), nc = 3)), "gev"))) #)) ### parameters-object x <- as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") est_paramcov(x) est_paramcov(x, leftrim = 0, rightrim = 0) est_paramcov(x, leftrim = 0, rightrim = 0, set.n = 100) # distr-argument can be neglected
### Numeric vectors x <- rgev(500, shape = .2) parameters(TLMoments(x), "gev") est_paramcov(x, "gev", 0, 0) #cov(t(replicate(10000, parameters(TLMoments(rgev(500, shape = .2)), "gev")))) parameters(TLMoments(x, rightrim = 1), "gev") est_paramcov(x, "gev", 0, 1) #cov(t(replicate(10000, # parameters(TLMoments(rgev(500, shape = .2), rightrim = 1), "gev") #))) parameters(TLMoments(x, rightrim = 2), "gev") est_paramcov(x, "gev", 0, 2) #cov(t(replicate(10000, # parameters(TLMoments(rgev(500, shape = .2), rightrim = 2), "gev") #))) ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) parameters(TLMoments(x), "gev") est_paramcov(x, "gev", 0, 0) #cov(t(replicate(5000, # as.vector(parameters(TLMoments(matrix(rgev(600, shape = .2), nc = 3)), "gev"))) #)) ### parameters-object x <- as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev") est_paramcov(x) est_paramcov(x, leftrim = 0, rightrim = 0) est_paramcov(x, leftrim = 0, rightrim = 0, set.n = 100) # distr-argument can be neglected
Internal function. Use est_cov. Description not done yet.
est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0)) ## S3 method for class 'numeric' est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0)) ## S3 method for class 'matrix' est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0))
est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0)) ## S3 method for class 'numeric' est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0)) ## S3 method for class 'matrix' est_pwmcov(x, order = 0:3, distr = NULL, distr.trim = c(0, 0))
x |
numeric vector or matrix of data. |
order |
numeric vector giving the orders that are returned. |
distr |
character of length 1 which indicates a distribution if a parametric assumption should be used. |
distr.trim |
integer vector of length 2 indicating the trimming used
to calculate parameters if a parametric assumption is used (i.e. |
numeric matrix
### Numeric vectors x <- rgev(500, shape = .2) est_pwmcov(x) est_pwmcov(x, distr = "gev") ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) est_pwmcov(x, order = 0:2) est_pwmcov(x, order = 0:2, distr = "gev")
### Numeric vectors x <- rgev(500, shape = .2) est_pwmcov(x) est_pwmcov(x, distr = "gev") ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) est_pwmcov(x, order = 0:2) est_pwmcov(x, order = 0:2, distr = "gev")
Internal function. Use est_cov. Description not done yet.
est_quancov(x, distr = "", p = NULL, leftrim = 0L, rightrim = 0L, ...) ## S3 method for class 'numeric' est_quancov(x, distr, p, leftrim = 0L, rightrim = 0L, np.cov = FALSE, ...) ## S3 method for class 'matrix' est_quancov( x, distr, p, leftrim = 0L, rightrim = 0L, np.cov = FALSE, reg.weights = NULL, ... ) ## S3 method for class 'quantiles' est_quancov( x, distr = attr(x, "distribution"), p = attr(x, "p"), leftrim = attr(x, "source")$trimmings[1], rightrim = attr(x, "source")$trimmings[2], set.n = NA, ... )
est_quancov(x, distr = "", p = NULL, leftrim = 0L, rightrim = 0L, ...) ## S3 method for class 'numeric' est_quancov(x, distr, p, leftrim = 0L, rightrim = 0L, np.cov = FALSE, ...) ## S3 method for class 'matrix' est_quancov( x, distr, p, leftrim = 0L, rightrim = 0L, np.cov = FALSE, reg.weights = NULL, ... ) ## S3 method for class 'quantiles' est_quancov( x, distr = attr(x, "distribution"), p = attr(x, "p"), leftrim = attr(x, "source")$trimmings[1], rightrim = attr(x, "source")$trimmings[2], set.n = NA, ... )
x |
numeric vector or matrix containing data. |
distr |
character of length 1 giving the distribution if parametric assumption should be used. |
p |
quantile levels from which the covariance should be calculated. |
leftrim , rightrim
|
lower and upper trimming parameter used for parameter calculation, have to be non-negative integers. |
... |
additional arguments. |
np.cov |
boolean, if TRUE no parametric assumptions are used to calculate the covariance matrix (default FALSE). |
reg.weights |
numeric vector of weights for regionalized TLMoments. |
set.n |
hypothetical data length n if theoretical values are given. |
numeric matrix
### Numeric vectors x <- rgev(500, shape = .2) quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 0) #cov(t(replicate(5000, # quantiles(parameters(TLMoments(rgev(500, shape = .2)), "gev"), c(.9, .95, .99)) #))) quantiles(parameters(TLMoments(x, rightrim = 1), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 1) #cov(t(replicate(5000, # quantiles( # parameters(TLMoments(rgev(500, shape = .2), rightrim = 1), "gev"), # c(.9, .95, .99) # ) #))) ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 0) est_quancov(x, "gev", .9, 0, 0) #cov(t(replicate(5000, # quantiles( # parameters(TLMoments(matrix(rgev(600, shape = .2), nc = 3)), # "gev"), .9) # ) #)) ### quantiles object q <- quantiles(as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev"), c(.9, .99)) est_quancov(q) est_quancov(q, leftrim = 0, rightrim = 0) est_quancov(q, leftrim = 0, rightrim = 0, set.n = 10)
### Numeric vectors x <- rgev(500, shape = .2) quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 0) #cov(t(replicate(5000, # quantiles(parameters(TLMoments(rgev(500, shape = .2)), "gev"), c(.9, .95, .99)) #))) quantiles(parameters(TLMoments(x, rightrim = 1), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 1) #cov(t(replicate(5000, # quantiles( # parameters(TLMoments(rgev(500, shape = .2), rightrim = 1), "gev"), # c(.9, .95, .99) # ) #))) ### Numeric matrices x <- matrix(rgev(600, shape = .2), nc = 3) quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) est_quancov(x, "gev", c(.9, .95, .99), 0, 0) est_quancov(x, "gev", .9, 0, 0) #cov(t(replicate(5000, # quantiles( # parameters(TLMoments(matrix(rgev(600, shape = .2), nc = 3)), # "gev"), .9) # ) #)) ### quantiles object q <- quantiles(as.parameters(loc = 3, scale = 2, shape = .4, distr = "gev"), c(.9, .99)) est_quancov(q) est_quancov(q, leftrim = 0, rightrim = 0) est_quancov(q, leftrim = 0, rightrim = 0, set.n = 10)
Internal function. Use est_cov. Description not done yet.
est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, ... ) ## S3 method for class 'numeric' est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, ... ) ## S3 method for class 'matrix' est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, reg.weights = NULL, ... ) ## S3 method for class 'TLMoments' est_tlmcov( x, leftrim = attr(x, "leftrim"), rightrim = attr(x, "rightrim"), order = attr(x, "order"), distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, set.n = NA, ... )
est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, ... ) ## S3 method for class 'numeric' est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, ... ) ## S3 method for class 'matrix' est_tlmcov( x, leftrim = 0L, rightrim = 0L, order = 1:3, distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, reg.weights = NULL, ... ) ## S3 method for class 'TLMoments' est_tlmcov( x, leftrim = attr(x, "leftrim"), rightrim = attr(x, "rightrim"), order = attr(x, "order"), distr = NULL, lambda.cov = TRUE, ratio.cov = TRUE, set.n = NA, ... )
x |
numeric vector or matrix containing data OR an object of TLMoments. |
leftrim , rightrim
|
integer indicating lower and upper trimming parameters, have to be non-negative integers. |
order |
numeric vector giving the orders that are returned (default is first three L-moments). |
distr |
character of length 1 giving the distribution if parametric assumption should be used. |
lambda.cov |
boolean, if TRUE (default) TL-moment estimation covariance matrix is calculated. |
ratio.cov |
boolean, if TRUE (default) TL-moment-ratio estimation covariance matrix is calculated. |
... |
additional arguments. |
reg.weights |
numeric vector of weights for regionalized TLMoments. |
set.n |
hypothetical data length n if theoretical values are given. |
a list of numeric matrices (if lambda.cov
and ratio.cov
are TRUE (default)), or a single matrix.
### Numeric vectors x <- rgev(500, loc = 10, scale = 5, shape = .1) est_tlmcov(x) est_tlmcov(x, order = 2:3) est_tlmcov(x, rightrim = 1, order = 4:5) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1))$lambdas) # )) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1))$ratios) # )) est_tlmcov(x, ratio.cov = FALSE) est_tlmcov(x, lambda.cov = FALSE) est_tlmcov(x, distr = "gev") est_tlmcov(x, leftrim = 0, rightrim = 1) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1), 0, 1, 3)$lambdas # ))) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1), 0, 1, 3)$ratios # ))) ### Numeric matrices x <- matrix(rgev(600), nc = 3) est_tlmcov(x) est_tlmcov(x, order = 3:4) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$lambdas[3:4, ]) # ))) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$ratios[3:4, ]) # ))) est_tlmcov(x, ratio.cov = FALSE) est_tlmcov(x, lambda.cov = FALSE) TLMoments:::est_tlmcov(x, order = 2:3, distr = "gev") # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$lambdas[2:3, ]) # ))) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$ratios[2:3, ]) # ))) ### TLMoments-object (theoretical calculation) tlm <- TLMoments(as.parameters(loc = 10, scale = 5, shape = .1, distr = "gev"), 0, 1) est_tlmcov(tlm, distr = "gev", set.n = 100) est_tlmcov(tlm, distr = "gev", set.n = 100, ratio.cov = FALSE) est_tlmcov(tlm, distr = "gev", set.n = 100, lambda.cov = FALSE)
### Numeric vectors x <- rgev(500, loc = 10, scale = 5, shape = .1) est_tlmcov(x) est_tlmcov(x, order = 2:3) est_tlmcov(x, rightrim = 1, order = 4:5) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1))$lambdas) # )) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1))$ratios) # )) est_tlmcov(x, ratio.cov = FALSE) est_tlmcov(x, lambda.cov = FALSE) est_tlmcov(x, distr = "gev") est_tlmcov(x, leftrim = 0, rightrim = 1) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1), 0, 1, 3)$lambdas # ))) # cov(t(replicate(10000, # TLMoments(rgev(500, loc = 10, scale = 5, shape = .1), 0, 1, 3)$ratios # ))) ### Numeric matrices x <- matrix(rgev(600), nc = 3) est_tlmcov(x) est_tlmcov(x, order = 3:4) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$lambdas[3:4, ]) # ))) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$ratios[3:4, ]) # ))) est_tlmcov(x, ratio.cov = FALSE) est_tlmcov(x, lambda.cov = FALSE) TLMoments:::est_tlmcov(x, order = 2:3, distr = "gev") # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$lambdas[2:3, ]) # ))) # cov(t(replicate(10000, # as.vector(TLMoments(matrix(rgev(600), nc = 3))$ratios[2:3, ]) # ))) ### TLMoments-object (theoretical calculation) tlm <- TLMoments(as.parameters(loc = 10, scale = 5, shape = .1, distr = "gev"), 0, 1) est_tlmcov(tlm, distr = "gev", set.n = 100) est_tlmcov(tlm, distr = "gev", set.n = 100, ratio.cov = FALSE) est_tlmcov(tlm, distr = "gev", set.n = 100, lambda.cov = FALSE)
Converts TL-moments (or PWMs) to distribution parameters. By now, conversions for gev, gumbel, gpd, and ln3 are available. Important trimming options are calculated through known formulas (see references for some of them), other options are calculated through a numerical optimization.
parameters(x, distr, ...) ## S3 method for class 'PWMs' parameters(x, distr, ...) ## S3 method for class 'TLMoments' parameters(x, distr, ...)
parameters(x, distr, ...) ## S3 method for class 'PWMs' parameters(x, distr, ...) ## S3 method for class 'TLMoments' parameters(x, distr, ...)
x |
object returned by TLMoments (or PWMs, in which case TLMoments with no trimming is used). |
distr |
character object defining the distribution. Supported types are "gev", "gum", "gpd", and "ln3". |
... |
additional arguments. |
numeric vector, matrix, list, or data.frame of parameter estimates with
class parameters
. The object contains the following attributes:
distribution
: a character indicating the used distribution
source
: a list with background information (used function, data, n, formula, trimmings; mainly for internal purposes)
The attributes are hidden in the print-function for a clearer presentation.
PWMs
: parameters for PWMs-object
TLMoments
: parameters for TLMoments-object
Elamir, E. A. H. (2010). Optimal choices for trimming in trimmed L-moment method. Applied Mathematical Sciences, 4(58), 2881-2890.
Fischer, S., Fried, R., & Schumann, A. (2015). Examination for robustness of parametric estimators for flood statistics in the context of extraordinary extreme events. Hydrology and Earth System Sciences Discussions, 12, 8553-8576.
Hosking, J. R. (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.
PWMs
, TLMoments
, quantiles
, summary.parameters
, as.parameters
. Built-in distributions: pgev
, pgum
, pgpd
, pln3
.
xmat <- matrix(rgev(100, shape = .2), 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) ) # TLMoments-objects or PWMs-objects can be used. However, in case of PWMs # simply the TLMoments(., leftrim = 0, rightrim = 0)-variant is used. parameters(PWMs(xvec), "gev") tlm <- TLMoments(xvec, leftrim = 0, rightrim = 0) parameters(tlm, "gev") tlm <- TLMoments(xmat, leftrim = 1, rightrim = 1) parameters(tlm, "gum") tlm <- TLMoments(xlist) parameters(tlm, "gpd") tlm <- TLMoments(xdat, hq ~ station, leftrim = 0, rightrim = 2) parameters(tlm, "gev") tlm <- TLMoments(xdat, hq ~ station + season, leftrim = 0, rightrim = 2) parameters(tlm, "gev") # If no explicit formula is implemented, it is tried to calculate # parameters numerically. The attribute source$param.computation.method # indicates if this is the case. tlm <- TLMoments(rgum(200, loc = 5, scale = 2), leftrim = 1, rightrim = 4) parameters(tlm, "gum") tlm <- TLMoments(rgev(200, loc = 10, scale = 5, shape = .4), leftrim = 2, rightrim = 2) parameters(tlm, "gev") tlm <- TLMoments(rln3(200, loc = 3, scale = 1.5, shape = 2), leftrim = 0, rightrim = 1) parameters(tlm, "ln3") # Numerical calculation is A LOT slower: ## Not run: system.time(replicate(500, parameters(TLMoments(rgum(100, loc = 5, scale = 2), 1, 1), "gum") ))[3] system.time(replicate(500, parameters(TLMoments(rgum(100, loc = 5, scale = 2), 1, 2), "gum") ))[3] ## End(Not run) # Using magrittr library(magrittr) TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 0) %>% parameters("gpd") TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 0) %>% parameters("gpd", u = 10) TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 1) %>% parameters("gpd") TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 2) %>% parameters("gpd")
xmat <- matrix(rgev(100, shape = .2), 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) ) # TLMoments-objects or PWMs-objects can be used. However, in case of PWMs # simply the TLMoments(., leftrim = 0, rightrim = 0)-variant is used. parameters(PWMs(xvec), "gev") tlm <- TLMoments(xvec, leftrim = 0, rightrim = 0) parameters(tlm, "gev") tlm <- TLMoments(xmat, leftrim = 1, rightrim = 1) parameters(tlm, "gum") tlm <- TLMoments(xlist) parameters(tlm, "gpd") tlm <- TLMoments(xdat, hq ~ station, leftrim = 0, rightrim = 2) parameters(tlm, "gev") tlm <- TLMoments(xdat, hq ~ station + season, leftrim = 0, rightrim = 2) parameters(tlm, "gev") # If no explicit formula is implemented, it is tried to calculate # parameters numerically. The attribute source$param.computation.method # indicates if this is the case. tlm <- TLMoments(rgum(200, loc = 5, scale = 2), leftrim = 1, rightrim = 4) parameters(tlm, "gum") tlm <- TLMoments(rgev(200, loc = 10, scale = 5, shape = .4), leftrim = 2, rightrim = 2) parameters(tlm, "gev") tlm <- TLMoments(rln3(200, loc = 3, scale = 1.5, shape = 2), leftrim = 0, rightrim = 1) parameters(tlm, "ln3") # Numerical calculation is A LOT slower: ## Not run: system.time(replicate(500, parameters(TLMoments(rgum(100, loc = 5, scale = 2), 1, 1), "gum") ))[3] system.time(replicate(500, parameters(TLMoments(rgum(100, loc = 5, scale = 2), 1, 2), "gum") ))[3] ## End(Not run) # Using magrittr library(magrittr) TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 0) %>% parameters("gpd") TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 0) %>% parameters("gpd", u = 10) TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 1) %>% parameters("gpd") TLMoments(rgpd(500, loc = 10, scale = 3, shape = .3), rightrim = 2) %>% parameters("gpd")
Cumulative distribution function, density function, quantile function and generation of random variates of the generalized extreme value distribution.
pgev(q, loc = 0, scale = 1, shape = 0) dgev(x, loc = 0, scale = 1, shape = 0) qgev(p, loc = 0, scale = 1, shape = 0) rgev(n, loc = 0, scale = 1, shape = 0)
pgev(q, loc = 0, scale = 1, shape = 0) dgev(x, loc = 0, scale = 1, shape = 0) qgev(p, loc = 0, scale = 1, shape = 0) rgev(n, loc = 0, scale = 1, shape = 0)
loc , scale , shape
|
location, scale, and shape parameter of the generalized extreme value distribution. All must be of length one. |
x , q , p
|
numeric vector of values, quantiles, or probabilites. |
n |
numeric, number of random variates. |
Cumulative distribution function, density function, quantile function and generation of random variates of the generalized Pareto distribution.
pgpd(q, loc = 0, scale = 1, shape = 0) dgpd(x, loc = 0, scale = 1, shape = 0) qgpd(p, loc = 0, scale = 1, shape = 0) rgpd(n, loc = 0, scale = 1, shape = 0)
pgpd(q, loc = 0, scale = 1, shape = 0) dgpd(x, loc = 0, scale = 1, shape = 0) qgpd(p, loc = 0, scale = 1, shape = 0) rgpd(n, loc = 0, scale = 1, shape = 0)
loc , scale , shape
|
location, scale, and shape parameter of the generalized Pareto distribution. All must be of length one. |
x , q , p
|
numeric vector of values, quantiles, or probabilites. |
n |
numeric, number of random variates. |
Cumulative distribution function, density function, quantile function and generation of random variates of the Gumbel distribution.
pgum(q, loc = 0, scale = 1) dgum(x, loc = 0, scale = 1) qgum(p, loc = 0, scale = 1) rgum(n, loc = 0, scale = 1)
pgum(q, loc = 0, scale = 1) dgum(x, loc = 0, scale = 1) qgum(p, loc = 0, scale = 1) rgum(n, loc = 0, scale = 1)
loc , scale
|
location and scale parameter of the Gumbel distribution. All must be of length one. |
x , q , p
|
numeric vector of values, quantiles, or probabilites. |
n |
numeric, number of random variates. |
Cumulative distribution function, density function, quantile function and generation of random variates of the three-parameter lognormal distribution.
pln3(q, loc = 0, scale = 1, shape = 1) dln3(x, loc = 0, scale = 1, shape = 1) qln3(p, loc = 0, scale = 1, shape = 1) rln3(n, loc = 0, scale = 1, shape = 1)
pln3(q, loc = 0, scale = 1, shape = 1) dln3(x, loc = 0, scale = 1, shape = 1) qln3(p, loc = 0, scale = 1, shape = 1) rln3(n, loc = 0, scale = 1, shape = 1)
loc , scale , shape
|
location, scale, and shape parameter of the three-parameter lognormal distribution. All must be of length one. |
x , q , p
|
numeric vector of values, quantiles, or probabilites. |
n |
numeric, number of random variates. |
Generates a ggplot2 object containing a scatterplot of TL skewness and TL kurtosis as well as the theoretical curves and points of several distributions (for now: GEV, GPD, LN3, GUM, EXP, NORM).
## S3 method for class 'TLMoments' plot(x, ...) ## S3 method for class 'numeric' plot.TLMoments(x, distr = "all", add_center = FALSE, use_internal = TRUE, ...) ## S3 method for class 'matrix' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...) ## S3 method for class 'list' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...) ## S3 method for class 'data.frame' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...)
## S3 method for class 'TLMoments' plot(x, ...) ## S3 method for class 'numeric' plot.TLMoments(x, distr = "all", add_center = FALSE, use_internal = TRUE, ...) ## S3 method for class 'matrix' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...) ## S3 method for class 'list' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...) ## S3 method for class 'data.frame' plot.TLMoments(x, distr = "all", add_center = TRUE, use_internal = TRUE, ...)
x |
object of TLMoments. |
... |
additional arguments, not used at the moment. |
distr |
character indicating the plotted theoretical distributions, see details. |
add_center |
boolean, if TRUE (default, except for vector TLMoments) the center of all TL-moment ratios is printed as a cross. |
use_internal |
boolean, if TRUE (default) internal pre-calculated values (if available) are used to print curves and points. |
distr
: this can either be a vector containing the abbreviations of the
theoretical distributions (gev, gpd, ln3, pe3, glo, gum, exp, or norm) or one of the
shortcuts \"all\" (default), \"only-lines\", or \"only-points\" that indicate
all distributions, all distributions displayed as lines (i.e. gev, gpd, ln3, pe3, glo),
or all distributions displayed as points (ie. gum, exp, norm), respectively.
Values of theoretical distributions are pre-calculated for several trimmings. If other trimmings are selected this results in a (small) delay for calculation.
A ggplot object.
numeric
: plot.TLMoments for numeric vector
matrix
: plot.TLMoments for numeric matrix
list
: plot.TLMoments for numeric list
data.frame
: plot.TLMoments for numeric data.frame
## Not run: xmat <- matrix(rgev(1000, shape = .1), nc = 10) xvec <- xmat[, 3] xlist <- lapply(1L:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = rep(letters[1:10], each = 100), season = rep(c("S", "W"), 50), hq = as.vector(xmat) ) library(ggplot2) plot(TLMoments(xvec)) plot(TLMoments(xlist), distr = c("gev", "gum"), add_center = FALSE) plot(TLMoments(xmat), distr = "only-points") plot(TLMoments(xmat), distr = "only-lines") + scale_colour_viridis_d() plot(TLMoments(xmat, 0, 1)) plot(TLMoments(xmat, 0, 1)) + coord_cartesian(xlim = c(-.05, .4), ylim = c(.05, .2)) plot(TLMoments(xdat, hq ~ station, 1, 0)) plot(TLMoments(xmat), add_center = FALSE) plot(TLMoments(xmat), use_internal = FALSE) plot(TLMoments(xmat, 2, 3)) ## End(Not run)
## Not run: xmat <- matrix(rgev(1000, shape = .1), nc = 10) xvec <- xmat[, 3] xlist <- lapply(1L:ncol(xmat), function(i) xmat[, i]) xdat <- data.frame( station = rep(letters[1:10], each = 100), season = rep(c("S", "W"), 50), hq = as.vector(xmat) ) library(ggplot2) plot(TLMoments(xvec)) plot(TLMoments(xlist), distr = c("gev", "gum"), add_center = FALSE) plot(TLMoments(xmat), distr = "only-points") plot(TLMoments(xmat), distr = "only-lines") + scale_colour_viridis_d() plot(TLMoments(xmat, 0, 1)) plot(TLMoments(xmat, 0, 1)) + coord_cartesian(xlim = c(-.05, .4), ylim = c(.05, .2)) plot(TLMoments(xdat, hq ~ station, 1, 0)) plot(TLMoments(xmat), add_center = FALSE) plot(TLMoments(xmat), use_internal = FALSE) plot(TLMoments(xmat, 2, 3)) ## End(Not run)
Calculates empirical probability weighted moments of specific order(s).
PWM(x, order = 0, na.rm = FALSE)
PWM(x, order = 0, na.rm = FALSE)
x |
numeric vector of data. |
order |
integer, order of probability weighted moment, can be a set of {0,1,...}. |
na.rm |
logical, indicates if NAs should be removed. |
numeric vector, empirical PWM of orders order
of x
.
PWM(rnorm(25)) PWM(rnorm(25), order = 2) PWM(rnorm(25), order = c(0, 2, 4))
PWM(rnorm(25)) PWM(rnorm(25), order = 2) PWM(rnorm(25), order = c(0, 2, 4))
Calculates probability weighted moments up to a specific order. Note that PWMs start with order 0. Acceptable input types are numeric vectors, matrices, lists, and data.frames.
PWMs(x, ...) ## S3 method for class 'numeric' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'matrix' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'list' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'data.frame' PWMs(x, formula, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'TLMoments' PWMs(x, ...)
PWMs(x, ...) ## S3 method for class 'numeric' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'matrix' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'list' PWMs(x, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'data.frame' PWMs(x, formula, max.order = 4L, na.rm = FALSE, ...) ## S3 method for class 'TLMoments' PWMs(x, ...)
x |
numeric vector or matrix, list, or data.frame of data OR an object of TLMoments. |
... |
additional arguments. |
max.order |
integer, maximal order of PWMs. |
na.rm |
logical, indicates if NAs should be removed. |
formula |
if x is of type data.frame a formula has to be submitted. |
numeric vector, matrix, list, or data.frame consisting of the PWMs and
with class PWMs
.
The object contains the following attributes:
order
: a integer vector with corresponding PWM orders
source
: a list with background information (used function, data, n, formula;
mainly for internal purposes)
The attributes are hidden in the print-function for a clearer presentation.
Greenwood, J. A., Landwehr, J. M., Matalas, N. C., & Wallis, J. R. (1979). Probability weighted moments: definition and relation to parameters of several distributions expressable in inverse form. Water Resources Research, 15(5), 1049-1054.
# 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 PWMs from data: PWMs(xvec) PWMs(xmat) PWMs(xlist) PWMs(xdat, formula = hq ~ station) PWMs(xdat, formula = hq ~ season) PWMs(xdat, formula = hq ~ .) PWMs(xdat, formula = . ~ station + season) # Calculating PWMs from L-moments: PWMs(TLMoments(xvec)) PWMs(TLMoments(xmat)) PWMs(TLMoments(xlist)) PWMs(TLMoments(xdat, hq ~ station)) PWMs(TLMoments(xdat, hq ~ season)) PWMs(TLMoments(xdat, hq ~ .)) PWMs(TLMoments(xdat, . ~ station + season)) # In data.frame-mode invalid names are preceded by "." xdat <- data.frame( beta0 = rep(letters[1:2], each = 50), beta1 = as.vector(xmat) ) PWMs(xdat, formula = beta1 ~ beta0)
# 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 PWMs from data: PWMs(xvec) PWMs(xmat) PWMs(xlist) PWMs(xdat, formula = hq ~ station) PWMs(xdat, formula = hq ~ season) PWMs(xdat, formula = hq ~ .) PWMs(xdat, formula = . ~ station + season) # Calculating PWMs from L-moments: PWMs(TLMoments(xvec)) PWMs(TLMoments(xmat)) PWMs(TLMoments(xlist)) PWMs(TLMoments(xdat, hq ~ station)) PWMs(TLMoments(xdat, hq ~ season)) PWMs(TLMoments(xdat, hq ~ .)) PWMs(TLMoments(xdat, . ~ station + season)) # In data.frame-mode invalid names are preceded by "." xdat <- data.frame( beta0 = rep(letters[1:2], each = 50), beta1 = as.vector(xmat) ) PWMs(xdat, formula = beta1 ~ beta0)
Calculates quantiles from distribution parameters received by parameters or from a named vector.
quantiles(x, p, distr = attr(x, "distribution"))
quantiles(x, p, distr = attr(x, "distribution"))
x |
object returned by parameters or a named vector. In the latter
you have to specify the |
p |
numeric vector giving the quantiles to calculate. |
distr |
character object defining the distribution. Supported types are
"gev", "gum" and "gpd". You do not need to set this, if |
numeric vector, matrix, list, or data.frame of the quantiles and with class
quantiles
. The object contains the following attributes:
distribution
: a character indicating the used distribution
p
: a vector with the calculated quantiles
source
: a list with background information (used function, data, n,
formula, trimmings; mainly for internal purposes)
The attributes are hidden in the print-function for a clearer presentation.
PWMs
, TLMoments
, parameters
, summary.quantiles
# 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 quantiles from parameters-object tlm <- TLMoments(xvec, leftrim = 0, rightrim = 1) quantiles(parameters(tlm, "gev"), c(.9, .99)) tlm <- TLMoments(xmat, leftrim = 1, rightrim = 1) quantiles(parameters(tlm, "gum"), c(.9, .95, .999)) tlm <- TLMoments(xlist) quantiles(parameters(tlm, "gpd"), .999) tlm <- TLMoments(xdat, hq ~ station, leftrim = 2, rightrim = 3) quantiles(parameters(tlm, "gev"), seq(.1, .9, .1)) tlm <- TLMoments(xdat, hq ~ station + season, leftrim = 0, rightrim = 2) quantiles(parameters(tlm, "gum"), seq(.1, .9, .1)) # Distribution can be overwritten (but parameters have to fit) tlm <- TLMoments(xvec, leftrim = 0, rightrim = 1) params <- parameters(tlm, "gev") quantiles(params, c(.9, .99)) quantiles(params[1:2], c(.9, .99), distr = "gum") evd::qgumbel(c(.9, .99), loc = params[1], scale = params[2]) # Using magrittr library(magrittr) rgev(50, shape = .3) %>% TLMoments(leftrim = 0, rightrim = 1) %>% parameters("gev") %>% quantiles(c(.99, .999)) # Calculating quantiles to given parameters for arbitrary functions quantiles(c(mean = 10, sd = 3), c(.95, .99), "norm") qnorm(c(.95, .99), mean = 10, sd = 3) # These give errors: #quantiles(c(loc = 10, scale = 5, shape = .3), c(.95, .99), "notexistingdistribution") #quantiles(c(loc = 10, scale = 5, shpe = .3), c(.95, .99), "gev") # wrong arguments
# 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 quantiles from parameters-object tlm <- TLMoments(xvec, leftrim = 0, rightrim = 1) quantiles(parameters(tlm, "gev"), c(.9, .99)) tlm <- TLMoments(xmat, leftrim = 1, rightrim = 1) quantiles(parameters(tlm, "gum"), c(.9, .95, .999)) tlm <- TLMoments(xlist) quantiles(parameters(tlm, "gpd"), .999) tlm <- TLMoments(xdat, hq ~ station, leftrim = 2, rightrim = 3) quantiles(parameters(tlm, "gev"), seq(.1, .9, .1)) tlm <- TLMoments(xdat, hq ~ station + season, leftrim = 0, rightrim = 2) quantiles(parameters(tlm, "gum"), seq(.1, .9, .1)) # Distribution can be overwritten (but parameters have to fit) tlm <- TLMoments(xvec, leftrim = 0, rightrim = 1) params <- parameters(tlm, "gev") quantiles(params, c(.9, .99)) quantiles(params[1:2], c(.9, .99), distr = "gum") evd::qgumbel(c(.9, .99), loc = params[1], scale = params[2]) # Using magrittr library(magrittr) rgev(50, shape = .3) %>% TLMoments(leftrim = 0, rightrim = 1) %>% parameters("gev") %>% quantiles(c(.99, .999)) # Calculating quantiles to given parameters for arbitrary functions quantiles(c(mean = 10, sd = 3), c(.95, .99), "norm") qnorm(c(.95, .99), mean = 10, sd = 3) # These give errors: #quantiles(c(loc = 10, scale = 5, shape = .3), c(.95, .99), "notexistingdistribution") #quantiles(c(loc = 10, scale = 5, shpe = .3), c(.95, .99), "gev") # wrong arguments
regionalize takes the result of TLMoments and calculates a weighted mean of TL-moments and TL-moment ratios.
regionalize(x, ...) ## S3 method for class 'numeric' regionalize(x, ...) ## S3 method for class 'matrix' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...) ## S3 method for class 'data.frame' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...) ## S3 method for class 'list' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...)
regionalize(x, ...) ## S3 method for class 'numeric' regionalize(x, ...) ## S3 method for class 'matrix' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...) ## S3 method for class 'data.frame' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...) ## S3 method for class 'list' regionalize(x, w = attr(x, "source")$n, reg.lambdas = TRUE, ...)
x |
object returned by TLMoments. |
... |
additional arguments, not used at the moment. |
w |
numeric vector giving the weights. Default: Sample lengths of corresponding data. Internally scaled so that it adds up to 1. |
reg.lambdas |
logical, if TRUE (default) regionalization is based upon TL-moments. If false it's based on TL-moment-ratios. |
list of two dimensions: lambdas
/ratios
are numeric vectors
consisting of the regionalized 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)
xmat <- matrix(rgev(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) ) regionalize(TLMoments(xmat)) regionalize(TLMoments(xlist)) regionalize(TLMoments(xdat, hq ~ station)) # For numeric vector TLMoments, nothing happens: regionalize(TLMoments(xvec)) tlm <- TLMoments(xmat) regionalize(tlm) regionalize(tlm, reg.lambdas = FALSE) parameters(regionalize(tlm), "gev") parameters(regionalize(tlm, reg.lambdas = FALSE), "gev") quantiles(parameters(regionalize(tlm), "gev"), c(.99, .999)) quantiles(parameters(regionalize(tlm, reg.lambdas = FALSE), "gev"), c(.99, .999)) # With magrittr library(magrittr) matrix(rgev(200, shape = .3), nc = 5) %>% TLMoments(rightrim = 1) %>% regionalize %>% parameters("gev") %>% quantiles(c(.99, .999))
xmat <- matrix(rgev(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) ) regionalize(TLMoments(xmat)) regionalize(TLMoments(xlist)) regionalize(TLMoments(xdat, hq ~ station)) # For numeric vector TLMoments, nothing happens: regionalize(TLMoments(xvec)) tlm <- TLMoments(xmat) regionalize(tlm) regionalize(tlm, reg.lambdas = FALSE) parameters(regionalize(tlm), "gev") parameters(regionalize(tlm, reg.lambdas = FALSE), "gev") quantiles(parameters(regionalize(tlm), "gev"), c(.99, .999)) quantiles(parameters(regionalize(tlm, reg.lambdas = FALSE), "gev"), c(.99, .999)) # With magrittr library(magrittr) matrix(rgev(200, shape = .3), nc = 5) %>% TLMoments(rightrim = 1) %>% regionalize %>% parameters("gev") %>% quantiles(c(.99, .999))
Sets attributions to parameters objects and returns them. This function is for internal use.
returnParameters(out, distribution, ...)
returnParameters(out, distribution, ...)
out |
- |
distribution |
- |
... |
- |
An object of class parameters.
Sets attributes to PWMs objects and returns them. This function is for internal use.
returnPWMs(out, order, ...)
returnPWMs(out, order, ...)
out |
- |
order |
- |
... |
- |
An object of class PWMs.
Sets attributions to quantiles objects and returns them. This function is for internal use.
returnQuantiles(out, distribution, p, ...)
returnQuantiles(out, distribution, p, ...)
out |
- |
distribution |
- |
p |
- |
... |
- |
An object of class quantiles.
Sets attributions to TLMoments objects and returns them. This function is for internal use.
returnTLMoments(out, leftrim, rightrim, order, ...)
returnTLMoments(out, leftrim, rightrim, order, ...)
out |
- |
leftrim |
- |
rightrim |
- |
order |
- |
... |
- |
An object of class TLMoments.
Calculating and printing of summary statistics to a given parameters-object.
## S3 method for class 'parameters' summary(object, ci.level = 0.9, ...)
## S3 method for class 'parameters' summary(object, ci.level = 0.9, ...)
object |
object of parameters. |
ci.level |
numeric vector of length 1 giving the confidence level (default is 0.9). |
... |
additional arguments submitted to |
A summary.parameters
-object, a list with dimensions
param
ci.level
ci
cov
It is printed with print.summary.parameters
.
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) p <- parameters(TLMoments(x[, 1]), "gev") summary(p) summary(p, select = c("scale", "shape")) p <- parameters(TLMoments(x[, 1], rightrim = 1), "gev") summary(p) p <- parameters(TLMoments(x), "gev") summary(p) summary(p, select = "shape") p <- as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev") summary(p) summary(p, rightrim = 1, set.n = 250)
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) p <- parameters(TLMoments(x[, 1]), "gev") summary(p) summary(p, select = c("scale", "shape")) p <- parameters(TLMoments(x[, 1], rightrim = 1), "gev") summary(p) p <- parameters(TLMoments(x), "gev") summary(p) summary(p, select = "shape") p <- as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev") summary(p) summary(p, rightrim = 1, set.n = 250)
Calculating and printing of summary statistics to a given PWMs-object.
## S3 method for class 'PWMs' summary(object, ci.level = 0.9, ...)
## S3 method for class 'PWMs' summary(object, ci.level = 0.9, ...)
object |
object of PWMs. |
ci.level |
numeric vector of length 1 giving the confidence level (default is 0.9). |
... |
additional arguments submitted to |
A summary.PWMs
-object, a list with dimensions
pwm
ci.level
ci
cov
It is printed with print.summary.PWMs
.
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) summary(PWMs(x[, 1])) summary(PWMs(x[, 1]), distr = "gev") summary(PWMs(x[, 1]), distr = "gev", select = 1:2) summary(PWMs(x)) summary(PWMs(x), select = 1:2) ## Not run: summary(as.PWMs(c(15, 4, .5))) ## End(Not run)
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) summary(PWMs(x[, 1])) summary(PWMs(x[, 1]), distr = "gev") summary(PWMs(x[, 1]), distr = "gev", select = 1:2) summary(PWMs(x)) summary(PWMs(x), select = 1:2) ## Not run: summary(as.PWMs(c(15, 4, .5))) ## End(Not run)
Calculating and printing of summary statistics to a given quantiles-object.
## S3 method for class 'quantiles' summary(object, ci.level = 0.9, ...)
## S3 method for class 'quantiles' summary(object, ci.level = 0.9, ...)
object |
object of quantiles. |
ci.level |
numeric vector of length 1 giving the confidence level (default is 0.9). |
... |
additional arguments submitted to |
A summary.quantiles
-object, a list with dimensions
q
ci.level
ci
cov
It is printed with print.summary.quantiles
.
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) q <- quantiles(parameters(TLMoments(x[, 1]), "gev"), c(.9, .95, .99)) summary(q) summary(q, select = c(.9, .99)) q <- quantiles(parameters(TLMoments(x[, 1], rightrim = 1), "gev"), .95) summary(q) q <- quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) summary(q) summary(q, select = .95) q <- quantiles(as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev"), c(.9, .99)) summary(q) summary(q, rightrim = 1, set.n = 250)
x <- cbind(rgev(100, shape = .2), rgev(100, shape = .2)) q <- quantiles(parameters(TLMoments(x[, 1]), "gev"), c(.9, .95, .99)) summary(q) summary(q, select = c(.9, .99)) q <- quantiles(parameters(TLMoments(x[, 1], rightrim = 1), "gev"), .95) summary(q) q <- quantiles(parameters(TLMoments(x), "gev"), c(.9, .95, .99)) summary(q) summary(q, select = .95) q <- quantiles(as.parameters(loc = 10, scale = 5, shape = .3, distr = "gev"), c(.9, .99)) summary(q) summary(q, rightrim = 1, set.n = 250)
Calculating and printing of summary statistics to a given TLMoments-object.
## S3 method for class 'TLMoments' summary(object, ci.level = 0.9, ...)
## S3 method for class 'TLMoments' summary(object, ci.level = 0.9, ...)
object |
object of TLMoments. |
ci.level |
numeric vector of length 1 giving the confidence level (default is 0.9). |
... |
additional arguments submitted to |
A summary.TLMoments
-object, a list with dimensions
tlm
ci.level
lambda.ci
lambda.cov
ratio.ci
ratio.cov
It is printed with print.summary.TLMoments
.
tlm <- TLMoments(rgev(100, shape = .2)) summary(tlm) tlm <- TLMoments(rgev(100, shape = .2), rightrim = 1) summary(tlm, select = 3:4) tlm <- TLMoments(rgev(100, shape = .2), max.order = 2, rightrim = 1) summary(tlm) tlm <- TLMoments(matrix(rgev(100, shape = .2), nc = 2)) summary(tlm, select = 3:4) tlm <- TLMoments(matrix(rgev(100, shape = .2), nc = 2), max.order = 3) summary(tlm, ci = .95, distr = "gev") tlm <- as.TLMoments(c(15, 5, 1.3)) summary(tlm, distr = "gev", set.n = 100)
tlm <- TLMoments(rgev(100, shape = .2)) summary(tlm) tlm <- TLMoments(rgev(100, shape = .2), rightrim = 1) summary(tlm, select = 3:4) tlm <- TLMoments(rgev(100, shape = .2), max.order = 2, rightrim = 1) summary(tlm) tlm <- TLMoments(matrix(rgev(100, shape = .2), nc = 2)) summary(tlm, select = 3:4) tlm <- TLMoments(matrix(rgev(100, shape = .2), nc = 2), max.order = 3) summary(tlm, ci = .95, distr = "gev") tlm <- as.TLMoments(c(15, 5, 1.3)) summary(tlm, distr = "gev", set.n = 100)
Calculates empirical Trimmed L-moments of specific order(s) and trimming.
TLMoment( x, order = 1L, leftrim = 0L, rightrim = 0L, na.rm = FALSE, computation.method = "auto" )
TLMoment( x, order = 1L, leftrim = 0L, rightrim = 0L, na.rm = FALSE, computation.method = "auto" )
x |
numeric vector of data. |
order |
integer, order of Trimmed Moment, has to be greater than 1. |
leftrim , rightrim
|
integer indicating trimming parameters, have to be greater than 0. |
na.rm |
logical, indicates if NAs should be removed. |
computation.method |
character, indicating if the computation is performed via
PWMs, direct, recursive, or recurrence (see References Hosking & Balakrishnan, 2015).
Possible values are |
numeric vector, empirical TL(leftrim
,rightrim
)-moments of orders order
of x
Elamir, E. A., & Seheult, A. H. (2003). Trimmed L-moments. Computational Statistics & Data Analysis, 43(3), 299-314.
Hosking, J. R. (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.
x <- rnorm(100) TLMoment(x, order = 1) TLMoment(x, order = 2, leftrim = 0, rightrim = 1) TLMoment(x, order = c(1, 2, 3), leftrim = 2, rightrim = 2) TLMoment(x, order = c(1, 3, 2), leftrim = 2, rightrim = 2)
x <- rnorm(100) TLMoment(x, order = 1) TLMoment(x, order = 2, leftrim = 0, rightrim = 1) TLMoment(x, order = c(1, 2, 3), leftrim = 2, rightrim = 2) TLMoment(x, order = c(1, 3, 2), leftrim = 2, rightrim = 2)
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.
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, ... )
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, ... )
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 |
formula |
if |
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.
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
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
# 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)
# 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)