quantile
Empirical Quantiles

Description

Calculates a vector of the desired quantiles of the data.

Usage

quantile(x, ...)
quantile.default(x, probs = 0:4/4, na.rm = FALSE, 
    names = TRUE, type = 7, ...)

Arguments

x a numeric vector. Missing values (NAs) are only allowed if you set na.rm = TRUE.
probs a vector of desired probability levels where the values are must be between or equal to 0 and 1. The default value, seq(0, 1, 0.25), produces a "five number summary" that includes: the minimum, lower quartile, median, upper quartile, and maximum of x.
na.rm a logical value that specifies if missing values (NAs) are removed before the function performs the computation.
names a logical value that specifies if a "names" attribute should be included in the result.
type an integer value between 1 and 9 that is used to select one quantile algorithm. For more information about the definition of each value, see the Details section.
... methods may have other arguments. The following arguments are available in the default method.

Details

The type argument, depending on the value, returns a discontinuous or continuous sample quantile type. You can assign a value from the range one to nine and the sample quantiles of type i are defined by: Q[i](p) = (1 - y) x[j] + y x[j+1]
where: Discontinuous
For types 1 to 3, Q[i](p) is a discontinuous function of p, with m = 0 when i = 1 or i = 2, and m = -1/2 when i = 3.
type Calculation
1 y = 0 if g = 0, and 1 otherwise.
2 y = 0.5 if g = 0, and 1 otherwise.
3 SAS definition: nearest even order statistic. y = 0 if g = 0 and j is even, and 1 otherwise.
Continuous
For types 4 to 9, Q[i](p) is a continuous function of p, with gamma = g and m given below. The sample quantiles can be obtained equivalently by linear interpolation between the points (p[k],x[k]) where x[k] is the kth order statistic. Specific expressions for p[k] are given below.
type Calculation
4 m = 0. p[k] = k / n.
5 m = 1/2. p[k] = (k - 0.5) / n.
6 m = p. p[k] = k / (n + 1). Thus p[k] = E[F(x[k])]. This is used by Minitab and by SPSS.
7 m = 1-p. p[k] = (k - 1) / (n - 1). In this case, p[k] = mode[F(x[k])]. This is used by S.
8 m = (p+1)/3. p[k] = (k - 1/3) / (n + 1/3). Then p[k] =~ median[F(x[k])].
9 m = p/4 + 3/8. p[k] = (k - 3/8) / (n + 1/4).
Value
returns a vector of empirical quantiles that correspond to the probs levels in the sorted x data. The length of the return value is the same as the probs vector. A names attribute is also returned if names = TRUE. Missing values (NAs) and values that are not a number (NaNs), are passed through to the result.
References
Hyndman, R. J. and Fan, Y (1996), "Sample Quantiles in Statistical Packages," The American Statistician, 50, 361-365.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
See Also
approx, diff, function, median, ppoints, qqplot, rank.
Examples

quantile(1:9) # 0% 25% 50% 75% 100% # 1 3 5 7 9

quantile(1:9, probs=seq(0,1,.1)) # 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% # 1.0 1.8 2.6 3.4 4.2 5.0 5.8 6.6 7.4 8.2 9.0

quantile(1:9, probs=c(0.1,0.3,NA,NA)) # 10% 30% # 1.8 3.4 NA NA

Package stats version 6.1.1-7
Package Index