wquantile: Weighted Quantiles

View source: R/wquantile.R

wquantileR Documentation

Weighted Quantiles

Description

This function computes weighted quantiles of each column (by default, or for each row if specified by the user) of a matrix/data.frame.

It is a wrapper to the wtd.quantile function of the Hmisc package, specially designed for a matrix containing daily/monthly/seasonal/annual streamflows simulated by different (behavioural) parameter sets.

Usage

wquantile(x, weights=NULL, byrow=FALSE, probs=c(.025, .5, .975), 
          normwt=TRUE, verbose=TRUE)

Arguments

x

numeric or matrix for the computation of the weighted quantiles

weights

numeric vector, values of the weights to be used for computing the quantiles. See wtd.quantile.
Omitting the weights argument or specifying NULL or a zero-length vector will result in the usual unweighted estimates

byrow

logical, indicates if the computations have to be made for each column or for each row of x
When the simulated values obtained with different behavioural parameter sets are stored in columns, byrow must be TRUE
When the simulated values obtained with different behavioural parameter sets are stored in rows, byrow must be FALSE

probs

numeric vector, quantiles to be computed. wtd.quantile
Default value is c(.025, .5, .975) ( => 2.5%, 50%, 97.5% )

normwt

See wtd.quantile. Specify normwt=TRUE to make weights sum to length(x) after deletion of NAs

verbose

logical; if TRUE, progress messages are printed

Value

A data.frame with the weighted quantiles of each column (by default, or for each row if specified by the user using the byrow argument) of a matrix/data.frame given as input in x.

Author(s)

Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com

See Also

wtd.quantile

Examples

# random matrix with 100 parameter sets (in rows) corresponding to 10
# different parameters
params <- matrix(rnorm(1000), ncol=10, nrow=100)
colnames(params) <- paste("Param", 1:10, sep="")

# empirical CDFs for each one of the 10 parameters of x, with equal weight for 
# each one of the 100 parameter sets
wquantile(params, weights=rep(1,100), byrow=FALSE) 

hzambran/hydroPSO documentation built on July 19, 2024, 1:21 p.m.