median_bounds()
computes the minimal and maximal possible
median values. This is helpful if median2()
returns NA
: the median
can't be determined, but at least it might have lower and upper bounds.
It is used within median_table()
to compute the lower
and upper
columns.
Arguments
- x
Vector that can be ordered using
sort()
. It will be searched for its possible medians.- na.rm.amount, even
Passed on to
median2()
.- nna
Integer. Ignore unless the function is used as a helper. It is like
needs_prep
inmedian_count_tolerable()
except it can submit the number of missing values.
Value
Vector of length 2. Its type is double if x
is numeric (double or
integer). Otherwise, it has the same type as x
.
Details
Two edge cases may occur:
If the median can be precisely determined,
median_bounds()
returns two identical values. This is the same case in whichmedian2()
would return a non-NA
value, andmedian_plot_errorbar()
would show a "ring of certainty".If the number of missing values is so high that a continuous array of them could extend from the start or end of
x
into the median position, the data do not constrict the median to fall in between any finite bounds. The function will then returnc(NA, NA)
(of the appropriate type) because such an array ofNA
s would act as a tunnel to negative or positive infinity, enabling the median to assume indefinitely low or high values.
In the second case, c(NA, NA)
means there are no bounds, not that
existing bounds are unknown. This is unfortunate but necessary: although
c(-Inf, Inf)
would be more appropriate conceptually, it is always of type
double, so it would lead to coercion bugs when combined with non-numeric
data, which is possible in median_table()
. To illustrate, try c("abc", Inf)
.
Like median2()
, this function is generic, so methods can be defined for
other classes. This documentation describes the default method.