% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wquantile.R
\name{wquantile}
\alias{wquantile}
\title{Weighted Quantile}
\usage{
wquantile(
  x,
  freq = 1,
  probs = c(0, 0.25, 0.5, 0.75, 1),
  interpol = approx,
  ...
)
}
\arguments{
\item{x}{A vector of the random variable}

\item{freq}{A vector of probability or frequency associated with x}

\item{probs}{A vector of percents/100}

\item{interpol}{Name of interpolation function: approx or spline}

\item{...}{additional parameters to interpol function.}
}
\value{
A vector containing quantile values with name.
}
\description{
This program calculates the cdf of x from the frequency distribution
 (x, freq) and reverse interpolates it to calculate quantiles.
}
\details{
When \code{length(unique(x)) <= 10 }, \code{quantile(x,probs=probs)}
will be returned.

Quantile and wquantile differs in the way the interpolate (cdf,x). \cr
wquantile modifies (cdf,x) to (cdf, xb ) where xb is the mid point of
neighboring unique values of x.
}
\examples{
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)

}
