% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Quantile.R
\name{Quantile}
\alias{Quantile}
\title{Calculation of sample quantiles by interpolating
sample cumulative distribution function.}
\usage{
Quantile(
  x,
  freq = NULL,
  probs = seq(0, 1, 0.25),
  method = "constant",
  cdf = NULL
)
}
\arguments{
\item{x}{numeric vector}

\item{freq}{frequency associated with x \cr
(x,freq) is the frequency table}

\item{probs}{numeric vector of probabilities with values in [0,1]}

\item{method}{= "constant" | "linear" | "spline",  interpolation method}

\item{cdf}{cdf at x. This has priority over freq.}
}
\value{
a vector of quantiles
}
\description{
Calculation of sample quantiles by interpolating
sample cumulative distribution function.
}
\details{
If freq=1  and method="constant" (default),
 the result is equivalent to native quantile function with type=1.

 Given the frequency table of data, (x, freq), cdf will be calculated as:
 \preformatted{
 cdf = sumsum(freq)/sum(freq)
 }
}
\examples{

# generate data
set.seed(1701)
n <- 100
x <- round(10*rnorm(n),0)

# by native quantile func
probs <- c(0.25, 0.5, 0.75)
res1 <- quantile(x,probs, type=1)

# by Quantile
res2 <- Quantile( x,1, probs=probs )

# frequency table
freq <- table(x)
xc <- as.numeric(names(freq))

# from frequency table
res3 <- Quantile( xc,freq, probs=probs )

# comparison
Print(probs,res1,res2, res3)



#
# Effect of the sample size
#
# When small, Quantile with linear method is equal to quantile with type=4.
#
#

getQ <- function( x, prob ){
 res1 <- NULL;
 for( type in 1:9 ) res1 <- cbind(res1,quantile(x,probs, type=type))
 colnames(res1) <- paste("t",1:9,sep="")
 return( res1 )
}

# generate data
set.seed(1701)
n <- 5
x <- round(10*rnorm(n),0)
probs <- c(0.10, 0.25, 0.5, 0.75, 0.90)

# by native quantile func
res1 <- getQ(x,probs)
# by Quantile
res2 <- Quantile( x,1, probs=probs, method="linear" )
# comparison
Print(res1, fmt="8.4")
Print(probs,res2, fmt="8.4")


# generate data
set.seed(1701)
n <- 50
x <- round(10*rnorm(n),0)
probs <- c(0.10, 0.25, 0.5, 0.75, 0.90)

# by native quantile func
res1 <- getQ(x,probs)
# by Quantile
res2 <- Quantile( x,1, probs=probs, method="linear" )
# comparison
Print(res1, fmt="8.4")
Print(probs,res2, fmt="8.4")

# comparison
Print(res1)
Print(probs,res2, res3)


# generate data
set.seed(1701)
n <- 500
x <- round(10*rnorm(n),0)
probs <- c(0.10, 0.25, 0.5, 0.75, 0.90)

# by native quantile func
res1 <- getQ(x,probs)
# by Quantile
res2 <- Quantile( x,1, probs=probs, method="linear" )
# comparison
Print(res1, fmt="8.4")
Print(probs,res2, fmt="8.4")

# comparison
Print(res1)
Print(probs,res2, res3)


}
