----- Original Message -----
From: Harper Shull <[EMAIL PROTECTED]>
> Does anyone have an algorithm (computer code)
> for calculating percentiles.
> There is a formula for doing such in Excel,
> so it must be possible to
> program.  A friend is trying to write a
> macro to do such in another PC
> based software(Filemaker Pro). Thanks.

Your question is for sci.math.num-analysis.

Consult statistical a textbook about definition of
percentile. Try the following Pascal code to find K-th
smallest observation; I think that it is fast enough (or
seek in AS or TOMS).

    -----------------------------
    Alexander Tsyplakov
    Novosibirsk State University
    http://www.nsu.ru/ef/tsy/


function Selct1(K: Integer): Real;
{-- Find the K-th smallest element in an array A --}
var
  I, I_Rand, I_Min, I_Max, N_Min, N_Max, N: Integer;
  Q, Q_Upper, Tmp: Real;
begin
  {-- The algorithm --}
  N_Min := 1;
  N_Max := N;
  Q_Upper := 8934567; {-- Any strange number --}
  while N_Min < N_Max do
  begin
    {-- Choose separating number Q --}
    I_Rand := N_Min + Random(N_Max - N_Min + 1);
    Q := A[I_Rand];
    if Q = Q_Upper then
    begin
      I := I_Rand;
      while Q = Q_Upper do
      begin
        I := I + 1;
        if I > N_Max then I := N_Min;
        if I = I_Rand then
        begin
          {-- All numbers are the same (= Q_Upper) --}
          Selct1 := Q_Upper;
          Exit;
        end;
        Q := A[I];
      end;
    end;
    {-- Separate --}
    I_Min := N_Min;
    I_Max := N_Max;
    while 1 = 1 do
    begin
      while (I_Min <= N_Max) and (A[I_Min] <= Q) do
        Inc(I_Min);
      if I_Min > N_Max then Break;
      while A[I_Max] > Q do Dec(I_Max);
      if I_Min > I_Max then Break;
      Tmp := A[I_Min];
      A[I_Min] := A[I_Max];
      A[I_Max] := Tmp;
    end;
    Dec(I_Min);
    Inc(I_Max);
    if K <= I_Min then
    begin
      N_Max := I_Min;
      Q_Upper := Q;
    end
    else if K >= I_Max then N_Min := I_Max;
  end;
  Selct1 := A[K];
end;




=================================================================
Instructions for joining and leaving this list and remarks about
the problem of INAPPROPRIATE MESSAGES are available at
                  http://jse.stat.ncsu.edu/
=================================================================

Reply via email to