[R] Percentiles/Quantiles with Weighting
Thomas Lumley
tlumley at u.washington.edu
Wed Feb 18 10:50:06 CET 2009
On Tue, 17 Feb 2009, Brigid Mooney wrote:
> Thanks for pointing me to the quantreg package as a resource. I was hoping
> to ask be able to address one quick follow-up question...
>
> I get slightly different variants between using the rq funciton with formula
> = mydata ~ 1 as I would if I ran the same data using the quantile function.
>
> Example:
>
> mydata <- (1:10)^2/2
> pctile <- seq(.59, .99, .1)
>
> quantile(mydata, pctile)
> 59% 69% 79% 89% 99%
> 20.015 26.075 32.935 40.595 49.145
>
> rq(mydata~1, tau=pctile)
> Call:
> rq(formula = mydata ~ 1, tau = pctile)
> Coefficients:
> tau= 0.59 tau= 0.69 tau= 0.79 tau= 0.89 tau= 0.99
> (Intercept) 18 24.5 32 40.5 50
> Degrees of freedom: 10 total; 9 residual
>
> Is it correct to assume this is due to the different accepted methods of
> calculating quantiles?
If you try
lapply(1:9, function(i)quantile(mydata, pctile,type=i))
the answers from type=1 or 2 agree with rq().
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list