[R] Percentiles/Quantiles with Weighting
dwinsemius at comcast.net
Tue Feb 17 18:22:45 CET 2009
I do know that Harrell's Quantile function in the Hmisc package will
allow quantile estimates from models. Whether it is general enough to
extend to time series, I have no experience and cannot say.
On Feb 17, 2009, at 11: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
> data more heavily.
> I wrote the following function, but it seems quite inefficient, and
> really very flexible in its applications - so if anyone has any
> 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(quantile(X, pctile))
> print("Weighted Percentiles:")
> print(quantile(Xprime, pctile, na.rm=TRUE))
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help