# How to calculate a percentile of y for a given x given a series of (x, y)?

I have a scatter plot of (for example) height against age. How does one calculate for an individual point the percentile of the height for a given age?

Suggestions in R would be most appreciated. Thanks!

The dataset would have to be enormous for the empirical approaches to have sufficient precision, and it doesn't help very much to look at percentiles of the marginal distribution of height. I suggest quantile regression, allowing age to be flexibly modeled (e.g., using restricted cubic splines). Here is an example using R.

require(rms)  # loads quantreg, Hmisc, SparseM packages too
f <- Rq(ht ~ rcs(age,5), tau=.25, data=mydata) # model 25th percentile
f
plot(Predict(f))  # shows confidence bands
nomogram(f) # make a nomogram to predict the quantile manually

• Aha - it's Rq not Qr() [I think]. Works brilliantly! Upvote from me. – Andrew May 12 '11 at 15:19
• Sorry that should have been Rq. I'll correct the above. – Frank Harrell May 12 '11 at 21:09

'The' percentile for a given age implies some sort of regression (i.e. you can find 'the' mean predicted height from a given age).

Once you have found this, the result depends on your assumptions: if you want no assumptions (besides the regression's), find how many of the heights in your original data are smaller than the predicted one for your age (=use empirical distribution).

Otherwise, you can fit whatever model you like to the marginal distribution of height and then find the percentile of the predicted height in that distribution.

• With a sufficient size of data set, a model isn't needed. Take all the people of a given age (say, 8 years old) and take the percentile within that group. You might find the 30th percentile is .8 meters, the 60th percentile is 1.2 meters, etc. – zbicyclist May 11 '11 at 15:02
• @ Nick & @Sabbe Thanks - we'd have to collect a lot more data though, so I don't think this would work. I should have said this in the question - apologies. – Andrew May 13 '11 at 13:23
• Smooth modeling (e.g., using quantile regression) requires a much lower sample size than required by binning the data. However the sample sizes needed are not trivial. – Frank Harrell May 16 '11 at 15:49