Skip to content

Commit de27778

Browse files
committed
Merge pull request #38 from calonso/improve_percentile
documented percentile strategies
2 parents 090256b + 4ac417f commit de27778

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/statsample/vector.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,22 @@ def proportion_confidence_interval_z(n_poblation,margin=0.95,v=1)
830830
### Ordinal Methods
831831
######
832832

833-
# Return the value of the percentil q
834-
def percentil(q, strategy = :nearest)
833+
# == Percentil
834+
# Returns the value of the percentile q
835+
#
836+
# Accepts an optional second argument specifying the strategy to interpolate
837+
# when the requested percentile lies between two data points a and b
838+
# Valid strategies are:
839+
# * :midpoint (Default): (a + b) / 2
840+
# * :linear : a + (b - a) * d where d is the decimal part of the index between a and b.
841+
# This is the NIST recommended method (http://en.wikipedia.org/wiki/Percentile#NIST_method)
842+
#
843+
def percentil(q, strategy = :midpoint)
835844
check_type :ordinal
836845
sorted=@valid_data.sort
837846

838847
case strategy
839-
when :nearest
848+
when :midpoint
840849
v = (n_valid * q).quo(100)
841850
if(v.to_i!=v)
842851
sorted[v.to_i]

0 commit comments

Comments
 (0)