View source: R/quantile_weighted.R
quantile_weighted | R Documentation |
The default method (type=2
) corresponds to weighted percentiles in SAS.
quantile_weighted(
x,
probs = (0:4)/4,
weights = rep(1, length(x)),
type = 2,
eps = 1e-09
)
x |
Numeric vector |
probs |
Numeric vector of probabilities |
weights |
Numeric vector of weights of the same length as |
type |
An integer, |
eps |
Precision parameter used when |
When type=2
, averaging is used in case of equal of probabilities.
Equal probabilities (p[j]==probs[i]
) is determined by
abs(1-p[j]/probs[i])<eps
with p=cumsum(w)/sum(w)
where w=weights[order(x)]
.
With zero length of x
, NA
s are returned.
When all weights are zero and when when all x
's are not equal,
NaN
s are returned except for the 0% and 100% quantiles.
Quantiles as a named numeric vector.
Type 2 similar to type 5 in DescTools::Quantile
x <- rnorm(27)/5 + 1:27
w <- (1:27)/27
quantile_weighted(x, (0:5)/5, weights = w)
quantile_weighted(x, (0:5)/5, weights = w, type = 5)
quantile_weighted(x) - quantile(x, type = 2)
quantile_weighted(x, type = 5) - quantile(x, type = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.