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 so, do you know where I would be able to see the algorithms used in these functions? I'm not finding it in the documentation for function rq, and am new enough to R that I don't know where those references would generally be. On Tue, Feb 17, 2009 at 12:29 PM, roger koenker <rkoen...@uiuc.edu> wrote: > http://www.nabble.com/weighted-quantiles-to19864562.html#a19865869 > > gives one possibility... > > url: www.econ.uiuc.edu/~roger Roger Koenker > email rkoen...@uiuc.edu Department of Economics > vox: 217-333-4558 University of Illinois > fax: 217-244-6678 Champaign, IL 61820 > > > > > On Feb 17, 2009, at 10:57 AM, Brigid Mooney wrote: > > Hi All, >> >> I am looking at applications of percentiles to time sequenced data. I had >> just been using the quantile function to get percentiles over various >> periods, but am more interested in if there is an accepted (and/or >> R-implemented) method to apply weighting to the data so as to weigh recent >> data more heavily. >> >> I wrote the following function, but it seems quite inefficient, and not >> really very flexible in its applications - so if anyone has any >> suggestions >> on how to look at quantiles/percentiles within R while also using a >> weighting schema, I would be very interested. >> >> Note - this function supposes the data in X is time-sequenced, with the >> most >> recent (and thus heaviest weighted) data at the end of the vector >> >> WtPercentile <- function(X=rnorm(100), pctile=seq(.1,1,.1)) >> { >> Xprime <- NA >> >> for(i in 1:length(X)) >> { >> Xprime <- c(Xprime, rep(X[i], times=i)) >> } >> >> print("Percentiles:") >> print(quantile(X, pctile)) >> print("Weighted:") >> print(Xprime) >> print("Weighted Percentiles:") >> print(quantile(Xprime, pctile, na.rm=TRUE)) >> } >> >> WtPercentile(1:10) >> WtPercentile(rnorm(10)) >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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<http://www.r-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] ______________________________________________ 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.