q_weighted: Compute weighted averages of quantile estimates

View source: R/q_weighted.R

q_weightedR Documentation

Compute weighted averages of quantile estimates

Description

Compute weighted averages of quantile estimates

Usage

q_weighted(quant, weights = distLweights(quant, ...), onlyc = FALSE, ...)

Arguments

quant

Data.frame as in distLquantile output.

weights

Data.frame as in distLweights output.

onlyc

Logical: only return custom weighted quantile estimates as a vector? Useful to add those to existing results. See examples. DEFAULT: FALSE

...

Arguments passed to distLweights like weightc, onlydn=FALSE. order will be ignored, as q_weighted only adds/changes the rows weighted*.

Value

data.frame with rows "weighted*" added.

Author(s)

Berry Boessenkool, berry-b@gmx.de, Dec 2016

See Also

distLquantile

Examples

x <- data.frame(A=1:5, RMSE=runif(5))
distLweights(x, onlydn=FALSE)

q_weighted(x,  onlydn=FALSE)
q_weighted(x,  distLweights(x, weightc=c("1"=3, "3"=5), order=FALSE, onlydn=FALSE)  )

## Not run:  # time consuming
x <- rexp(190)
d <- distLquantile(x)
d2 <- q_weighted(d)
stopifnot(all(d==d2, na.rm=TRUE))

# fast option for adding custom weighted estimates:
cw <- runif(17)
names(cw) <- c("exp", "gam", "gev", "glo", "gno", "gpa", "gum", "kap", "lap",
               "ln3", "nor", "pe3", "ray", "revgum", "rice", "wak", "wei")
dw <- distLweights(d, weightc=cw)
qw1 <- q_weighted(d, weightc=cw); qw1
qw2 <- q_weighted(d, weights=dw); qw2
stopifnot(all(qw1==qw2, na.rm=TRUE))
q_weighted(d, weights=dw, onlyc=TRUE)
q_weighted(d, weights=data.frame(weightc=cw), onlyc=TRUE)

system.time(pbreplicate(5000, q_weighted(d, weightc=cw)))             # 8.5 secs
system.time(pbreplicate(5000, q_weighted(d, weights=dw, onlyc=TRUE))) # 0.8 secs

## End(Not run)


brry/extremeStat documentation built on Nov. 24, 2022, 3:35 p.m.