Michael Becher wrote:
Dear Professor Harrell,

please allow me a brief question about the wtd.quantile() function in your marvelous R package Hmisc that I was not able to answer using the documentation or the web. For type="quantile", what is the exact statistic that is estimated? The documentation says that the same interpolated order statistic as in the quantile() function is used. As far as I can tell, the quantile() function has 5 different interpolated order statistics (types 4-9). The default for quantile() is type 7 - is the same used in wtd.quantile? Or is it tpye 8, which is recommended by Hyndman and Fan (1996), since it is median unbiased and distribution free? Or something else?

Thanks a lot for your attention.

Respectfully,

Michael


---
Michael Becher
Princeton University
Department of Politics
mbec...@princeton.edu

Here is an empirical way to answer the question, for the case where the weights are all equal to 1. Methods could be said to be identical when then maximum difference is < 1e-10. You can see that the default for wtd.quantile equals the default for quantile. -Frank

require(Hmisc)

set.seed(1)
u <-  eval(formals(wtd.quantile)$type)
v <- as.character(1:9)
r <- matrix(0, nrow=length(u), ncol=9, dimnames=list(u,v))

for(n in c(8, 13, 22, 29))
  {
    x <- rnorm(n)
    for(i in 1:5) {
      probs <- sort( runif(9))
      for(wtype in u) {
wq <- wtd.quantile(x, type=wtype, weights=rep(1,length(x)), probs=probs)
        for(qtype in 1:9) {
          rq <- quantile(x, type=qtype, probs=probs)
          r[wtype, qtype] <- max(r[wtype,qtype], max(abs(wq-rq)))
        }
      }
    }
  }

r
1 2 3 4 5 6 quantile 0.5729927 0.5729927 0.7547948 5.022317e-01 0.3725233 6.416295e-01 (i-1)/(n-1) 0.5729927 0.5729927 0.7547948 5.022317e-01 0.3725233 6.416295e-01 i/(n+1) 0.7088892 0.7088892 0.8569561 7.195455e-01 0.3208148 4.440892e-16 i/n 0.7774653 0.7774653 0.4093181 4.440892e-16 0.4284780 7.195455e-01
                       7         8         9
quantile    0.000000e+00 0.4717554 0.4422707
(i-1)/(n-1) 8.881784e-16 0.4717554 0.4422707
i/(n+1)     6.416295e-01 0.2138765 0.2406111
i/n         5.022317e-01 0.5464169 0.5169322




--
Frank E Harrell Jr   Professor and Chair           School of Medicine
                     Department of Biostatistics   Vanderbilt University

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to