wquantile {lazy.irtx} | R Documentation |
This program calculates the cdf of x from the frequency distribution (x, freq) and reverse interpolates it to calculate quantiles.
wquantile(x, freq = 1, probs = c(0, 0.25, 0.5, 0.75, 1), int = 1, interpol = approx, ...)
x |
A vector of the random variable |
freq |
A vector of probability or frequency associated with x |
probs |
A vector of percents/100 |
int |
= 0 to omit the correction for integer. |
interpol |
Name of interpolation function: approx or spline |
... |
additional parameters to interpol function. |
A vector containing quantile values with name.
seed <- 1701 set.seed(seed) # original real random variable n <- 100 x0 <- 100+10*rnorm(n) # round to integers x <- round(x0) # (xc, f) summarizes the dist of x f <- table(x) xc <- as.numeric(names(f)) # expand (xc, f) to (xxf, 1) : These two contains the same info. xxf <- unlist(mapply( rep,xc,f )) # quantiles qtx0 <- quantile(x0) qtx <- quantile(x) qtxxf <- quantile(xxf) qtxc <- quantile(xc) wqtxc <- wquantile( xc, f ) # comparison qt <- cbind(qtx0,qtx,qtxxf,qtxc,wqtxc) Print(qt) # difference from the real quantiles dif <- abs(qt-qt[,1]) mad <- matrix(colMeans(dif),,1); rownames(mad)=colnames(dif) Print(dif,mad)