Skip to content

Instantly share code, notes, and snippets.

@branch14
Last active May 27, 2021 21:16
Show Gist options
  • Save branch14/760d948329b01b3fa4b8a0a34ae45844 to your computer and use it in GitHub Desktop.
Save branch14/760d948329b01b3fa4b8a0a34ae45844 to your computer and use it in GitHub Desktop.
require 'gsl'
a = [0,1,2,3,4,8]
v = GSL::Vector.alloc(a).sort
q1 = v.quantile_from_sorted_data(0.25)
q3 = v.quantile_from_sorted_data(0.75)
iqr = q3 - q1
tw = q3 + iqr * 1.5
bw = q1 - iqr * 1.5
to = a.filter { |x| x > tw }
bo = a.filter { |x| x < bw }
# - https://www.gnu.org/software/gsl/doc/html/statistics.html#median-and-percentiles
# - https://github.com/ampl/gsl/blob/dee1063dd57ec2841981b010eb732901b452c30a/statistics/quantiles_source.c
# - https://muse.union.edu/dvorakt/what-drives-the-length-of-whiskers-in-a-box-plot/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment