[R] quantiles for sorted pairs of data
Monica Pisica
pisicandru at hotmail.com
Mon Feb 2 18:53:33 CET 2009
Hi everybody,
Suppose I have continuous measurements of an energy waveform that is sampled discretely for different heights every 0.5m. Let's say I want to find out the height for which I have equal amount of energy above and below.
My colleague did the following:
a. calculate the cumulative sum of the energy
b. calculate the median of the cumulative energy
c. find out what is the height for which this median corresponds.
My take on this is: Since the heights are already sorted from min to max, and the cumulative energy is by default sorted from min to max …. it does not matter if I calculate the median of the cumulative energy and see which height it belongs to when I can calculate directly the median of the height and get actually same result. I think the same holds if I calculate any other quantile if I am interested in the corresponding height of that cumulative energy quantile.
I did some simulations to see if this is true, and I have simulated the energy values as a random sample of a normal distribution, gamma, f distribution or random sample of a combination of normal and gamma distributions. My question is: do any of you know of any reference that proves that? Paper, math property of already ordered sequences, anything to prove that this is not just a coincidence?
Following is an example, with n = 15 just for convenience to see with "naked eye" which value should be the median (I will also use only examples from a normal distribution, but the results prove the same does not matter which distribution I use for energy)
### code starts
set.seed = 123
xn <- rnorm(15)
xn <- xn+3 #to have only positive numbers
yn <- seq(1, 8, 0.5)
zn <- cumsum(xn)
dfn <- data.frame(energy = xn, elevation = yn, cum.energ = zn)
percent <- apply(dfn,2, function(x) quantile(x, probs = c(0.1, 0.25, 0.5, 0.75, 0.95)))
percent
dfn
f <- approxfun(yn, zn)
f(percent[1,2])
## code ends
As you can see quantiles for the cumulative energy corresponds to the respective quantiles of elevation, but quantiles of the energy waveform itself correspond to different heights than the elevation quantiles. Any help for references will be very much appreciated.
Thanks for any help,
Monica
_________________________________________________________________
12009
More information about the R-help
mailing list