boxplot.stats {grDevices} | R Documentation |
Box Plot Statistics
Description
This function is typically called by another function to gather the statistics necessary for producing box plots, but may be invoked separately.
Usage
boxplot.stats(x, coef = 1.5, do.conf = TRUE, do.out = TRUE)
Arguments
x |
a numeric vector for which the boxplot will
be constructed ( |
coef |
this determines how far the plot ‘whiskers’ extend out
from the box. If |
do.conf , do.out |
logicals; if |
Details
The two ‘hinges’ are versions of the first and third quartile,
i.e., close to quantile(x, c(1,3)/4)
. The hinges equal
the quartiles for odd n
(where n <- length(x)
) and
differ for even n
. Whereas the quartiles only equal observations
for n %% 4 == 1
(n\equiv 1 \bmod 4
),
the hinges do so additionally for n %% 4 == 2
(n\equiv 2 \bmod 4
), and are in the middle of
two observations otherwise.
The notches (if requested) extend to +/-1.58 IQR/sqrt(n)
.
This seems to be based on the same calculations as the formula with 1.57 in
, given in
.
They are based on asymptotic normality of the median
and roughly equal sample sizes for the two medians being compared, and
are said to be rather insensitive to the underlying distributions of
the samples. The idea appears to be to give roughly a 95% confidence
interval for the difference in two medians.
Value
A list with named components as follows:
stats |
a vector of length 5, containing the extreme of the
lower whisker, the lower ‘hinge’, the median, the upper
‘hinge’ and the extreme of the upper whisker.
For |
n |
the number of non- |
conf |
the lower and upper extremes of the ‘notch’
( |
out |
the values of any data points which lie beyond the
extremes of the whiskers ( |
Note that stats
and conf
are sorted in increasing
order, unlike S, and that n
and out
include any
+- Inf
values.
See Also
Examples
require(stats)
x <- c(1:100, 1000)
(b1 <- boxplot.stats(x))
(b2 <- boxplot.stats(x, do.conf = FALSE, do.out = FALSE))
stopifnot(b1 $ stats == b2 $ stats) # do.out = FALSE is still robust
boxplot.stats(x, coef = 3, do.conf = FALSE)
## no outlier treatment:
(b3 <- boxplot.stats(x, coef = 0))
stopifnot(b3$stats == fivenum(x))
## missing values are ignored
stopifnot(identical(boxplot.stats(c(x, NA)), b1))
## ... infinite values are not:
(r <- boxplot.stats(c(x, -1:1/0)))
stopifnot(r$out == c(1000, -Inf, Inf))