This is very helpful, thanks Rick!

The safe drinking water act regulations specific which quantile definitions can be used by water systems and may be of interest given your previous posts (see page 30 and 31 of https://nepis.epa.gov/Exe/ZyPDF.cgi?Dockey=P1002YN5.txt). I happen to be doing some research that requires me to get pretty precise about this.

If the 90th percentile is a round number then there's no problem and every method gives the same answer (e.g. system took 10 samples, then it's the 9th sample after sorting).

When the number of samples taken makes the quantile not a round number the EPA actually allows states to choose one of two methods:

* Round to the nearest x[j] using usual rounding (e.g. the 95th percentile of 10 samples would be the max, 94.999th would be second largest). in our parlance, that'd be type=3
* Linear interpolation of x[j] and x[j+1]. in our parlance, that'd be type = 4.

there's also some tricky business with systems that take <=5 samples in a period (e.g. see page 2 of https://nepis.epa.gov/Exe/ZyPDF.cgi?Dockey=60001N8P.txt): if exactly 5 samples, average 4th and 5th (which is the same as linear interpolation, yay!), for <5 samples, take the max (not the same as linear interpolation).

Thanks again!