[R] quantile() depends on order of probs?
Joshua Wiley
jwiley.psych at gmail.com
Sat Jun 19 06:02:41 CEST 2010
Hello All,
I am trying to figure out the rational behind why quantile() returns
different values for the same probabilities depending on whether 0 is
first.
Here is an example:
quantile(c(54, 72, 83, 112), type=6, probs=c(0, .25, .5, .75, 1))
quantile(c(54, 72, 83, 112), type=6, probs=c(.25, .5, .75, 1, 0))
It seems to come down to this part of the code for quantile:
fuzz <- 4 * .Machine$double.eps
nppm <- a + probs * (n + 1 - a - b)
j <- floor(nppm + fuzz)
h <- nppm - j
qs <- x[j + 2L]
qs[h == 1] <- x[j + 3L][h == 1]
other <- (h > 0) && (h < 1)
if (any(other))
qs[other] <- ((1 - h) * x[j + 2L] + h * x[j + 3L])[other]
In my example, a and b are both 0, and n = 4. Particularly, the
alternate formula for qs is only used when the first element of h is
both > 0 and < 1. Any ideas on this? It seems like a simple
alternative would be
other <- (h > 0) & (h < 1)
but I do not know if that would cause problems for other quantile
formulae. By the way, this comes around lines 39-70 in
quantile.default in:
> version
_
platform x86_64-pc-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 2
minor 11.1
year 2010
month 05
day 31
svn rev 52157
language R
version.string R version 2.11.1 (2010-05-31)
Best regards,
Josh
--
Joshua Wiley
Ph.D. Student
Health Psychology
University of California, Los Angeles
More information about the R-help
mailing list