HP Forums
Winsorising - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Winsorising (/thread-5461.html)



Winsorising - salvomic - 01-04-2016 08:24 PM

hi,
a program to make the winsorising of a data set for statistical purpose.
See here in Wikipedia: «Winsorising or Winsorisation is the transformation of statistics by limiting extreme values in the statistical data to reduce the effect of possibly spurious outliers. It is named after the engineer-turned-biostatistician Charles P. Winsor (1895–1951)...»
Values must be already in Statistic 1var (D1 matrix). The program put the resulting items in D2.

Enjoy!

Salvo Micciché

Code:

EXPORT winsorising(p)
// Data in Statistic 1var; p -> i.e. 90 = 90%, from 5th to 95th percentile)
BEGIN
LOCAL q1, q2, j;
q1 := quantile(D1, (100-p)/100);
q2 := quantile(D1, p/100);
D2 := D1;
FOR j FROM 1 TO size(D1) DO
    IF D1(j) < q1 THEN D2(j):= q1; END;
    IF D1(j) > q2 THEN D2(j):= q2; END;
END;
RETURN D2;
END;