Learn R Programming

extremeStat (version 1.5.9)

q_weighted: Compute weighted averages of quantile estimates

Description

Compute weighted averages of quantile estimates

Usage

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

Value

data.frame with rows "weighted*" added.

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*.

Author

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

See Also

distLquantile

Examples

Run this code
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)  )

if (FALSE)  # 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


Run the code above in your browser using DataLab