Raku::Statistics::OutlierIdentifiers
In brief
This a Raku package for 1D outlier identifier functions. If follows closely the Mathematica package [AAp1] and the R package [AAp3].
Installation
From Raku.land:
zef install Statistics::OutlierIdentifiers
From GitHub:
zef install https://github.com/antononcube/Raku-Statistics-OutlierIdentifiers.git
Usage examples
Load packages:
use Data::Generators; use Statistics::OutlierIdentifiers;
# (Any)
Generate a vector with random numbers:
srand(121); my @vec=random-variate(NormalDistribution.new(:mean(10), :sd(20)), 10); say @vec
# [34.660719020315 -8.030075964297922 7.9024919424237945 -1.6431949264279329 -62.06920928324861 5.844068195507269 1.654648693137439 -9.477538748192543 26.94082690136212 37.086889685282394]
Find outlier positions and values:
say outlier-identifier(@vec); say outlier-identifier(@vec):values;
# [0 4 8 9]
# (34.660719020315 -62.06920928324861 26.94082690136212 37.086889685282394)
Find top outlier positions and values:
say outlier-identifier(@vec, identifier => (&top-outliers o &hampel-identifier-parameters)); say outlier-identifier(@vec, identifier => (&top-outliers o &hampel-identifier-parameters)):values;
# [0 8 9]
# (34.660719020315 26.94082690136212 37.086889685282394)
Find bottom outlier positions and values (using quartiles-based identifier):
say outlier-identifier(@vec, identifier => (&bottom-outliers o &quartile-identifier-parameters)); say outlier-identifier(@vec, identifier => (&bottom-outliers o &quartile-identifier-parameters)):values;
# [4]
# (-62.06920928324861)
The available outlier parameters functions are:
hampel-identifier-parameters
splus-quartile-identifier-parameters
quartile-identifier-parameters
.say for (&hampel-identifier-parameters, &splus-quartile-identifier-parameters, &quartile-identifier-parameters).map({ $_ => $_.(@vec) });
# &hampel-identifier-parameters => (-14.787835171599149 22.286552060243856)
# &splus-quartile-identifier-parameters => (-25.699227577228335 21.418510057252767)
# &quartile-identifier-parameters => (-31.221544421337683 38.72026130998239)
References
[AA1] Anton Antonov, "Outlier detection in a list of numbers", (2013), MathematicaForPrediction at WordPress.
[AAp1] Anton Antonov, "Implementation of one dimensional outlier identifying algorithms in Mathematica", (2013), MathematicaForPrediction at GitHub.
[AAp2] Anton Antonov, OutlierIdentifiers R-package, (2019), R-packages at GitHub/antononcube.