q_weighted | R Documentation |
Compute weighted averages of quantile estimates
q_weighted(quant, weights = distLweights(quant, ...), onlyc = FALSE, ...)
quant |
Data.frame as in |
weights |
Data.frame as in |
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 |
data.frame with rows "weighted*" added.
Berry Boessenkool, berry-b@gmx.de, Dec 2016
distLquantile
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.