[R] Getting empirical percentiles for data
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Jan 7 09:24:06 CET 2005
Mike Cheung <mikewlcheung at hku.hk> writes:
> I know that "ecdf" can be used to calculate the empirical cumulative
> distribution. However, I don't know how to exact the cumulative
> probabilities for each unique element. The requirement is similar to
> the "FREQUENCIES" in SPSS. Could someone help me in exacting the
> cumulative probabilities from the ecdf object? Thanks in advance!
>
> # Generating artificial data
> x <- round( rnorm(50, mean=50, sd=10) )
> probs <- seq(0.1, 0.9, by=0.1)
> # Calculating percentiles
> x.percentiles <- quantile(x, probs)
> # Calculating percentile ranks
> x.ranks <- ecdf(x)
I don't quite see why you call it "x.ranks", but it's just a function
that you could evaluate at the step points, so continuing your code:
val <- sort(unique(x))
cbind(val,cum.prop=x.ranks(val))
I'd go for a more direct approach though:
cumsum(prop.table(table(x)))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list