module Mikon::Stats
Public Instance Methods
==(other)
click to toggle source
# File lib/mikon/stats.rb, line 82 def ==(other) @data==other end
average_deviation_population(m=nil)
click to toggle source
# File lib/mikon/stats.rb, line 10 def average_deviation_population(m=nil) m ||= self.mean (self.reduce(0){|memo, val| val + (val - m).abs})/self.length end
Also aliased as: adp
coefficient_of_variation()
click to toggle source
# File lib/mikon/stats.rb, line 15 def coefficient_of_variation self.standard_deviation_sample/self.mean end
count(x=false) { |val;| ... }
click to toggle source
# File lib/mikon/stats.rb, line 19 def count(x=false) if block_given? self.reduce(0){|memo, val| memo += 1 if yield val; memo} else val = self.frequencies[x] val.nil? ? 0 : val end end
each(&block)
click to toggle source
# File lib/mikon/stats.rb, line 28 def each(&block) return self.to_enum(:each) unless block_given? @data.each_along_dim(0, &block) end
each_index(&block)
click to toggle source
# File lib/mikon/stats.rb, line 33 def each_index(&block) self.each.with_index(&block) end
factors()
click to toggle source
uniq
# File lib/mikon/stats.rb, line 38 def factors index = @data.sorted_indices index.reduce([]){|memo, val| memo.push(@data[val]) if memo.last != @data[val]; memo} end
frequencies()
click to toggle source
# File lib/mikon/stats.rb, line 43 def frequencies index = @data.sorted_indices index.reduce({}){|memo, val| memo[@data[val]] ||= 0; memo[@data[val]] += 1; memo} end
has_missing_data?()
click to toggle source
# File lib/mikon/stats.rb, line 48 def has_missing_data? false end
Also aliased as: flawed?
is_valid?()
click to toggle source
# File lib/mikon/stats.rb, line 52 def is_valid? true end
kurtosis(m=nil)
click to toggle source
# File lib/mikon/stats.rb, line 56 def kurtosis(m=nil) m ||= self.mean fo=self.reduce(0){|a, x| a+((x-m)**4)} fo.quo(self.length*sd(m)**4)-3 end
mean()
click to toggle source
alias_method :label, :labeling labeling(x) would be not implemented
# File lib/mikon/stats.rb, line 65 def mean @data.mean.first end
median()
click to toggle source
# File lib/mikon/stats.rb, line 69 def median self.percentil(50) end
median_absolute_deviation()
click to toggle source
# File lib/mikon/stats.rb, line 73 def median_absolute_deviation m = self.median self.recode{|val| (val-m).abls}.median end
Also aliased as: mad
mode()
click to toggle source
# File lib/mikon/stats.rb, line 78 def mode self.frequencies.max end
n_valid()
click to toggle source
# File lib/mikon/stats.rb, line 86 def n_valid self.length end
percentil(percent)
click to toggle source
# File lib/mikon/stats.rb, line 90 def percentil(percent) index = @data.sorted_indices pos = (self.length * percent)/100 if pos.to_i == pos @data[index[pos.to_i]] else pos = (pos-0.5).to_i (@data[index[pos]] + @data[index[pos+1]])/2 end end
product()
click to toggle source
# File lib/mikon/stats.rb, line 101 def product @data.inject(1){|memo, val| memo*val} end
proportion(val=1)
click to toggle source
# File lib/mikon/stats.rb, line 105 def proportion(val=1) self.frequencies[val]/self.n_valid end
proportion_confidence_interval_t()
click to toggle source
# File lib/mikon/stats.rb, line 109 def proportion_confidence_interval_t raise "NotImplementedError" end
proportion_confidence_interval_z()
click to toggle source
# File lib/mikon/stats.rb, line 113 def proportion_confidence_interval_z raise "NotImplementedError" end
proportions()
click to toggle source
# File lib/mikon/stats.rb, line 117 def proportions len = self.n_valid self.frequencies.reduce({}){|memo, arr| memo[arr[0]] = arr[1]/len} end
push(val)
click to toggle source
# File lib/mikon/stats.rb, line 122 def push(val) self.expand(self.length+1) self[self.length-1] = recode end
range()
click to toggle source
# File lib/mikon/stats.rb, line 127 def range max - min end
ranked()
click to toggle source
?
# File lib/mikon/stats.rb, line 132 def ranked sum = 0 r = self.frequencies.sort.reduce({}) do |memo, val| memo[val[0]] = ((sum+1) + (sum+val[1]))/2 sum += val[1] memo end Mikon::DArray.new(self.reduce{|val| r[val]}) end
recode(&block)
click to toggle source
# File lib/mikon/stats.rb, line 142 def recode(&block) Mikon::DArray.new(@data.map(&block)) end
recode!(&block)
click to toggle source
# File lib/mikon/stats.rb, line 146 def recode!(&block) @data.map!(&block) end
skew(m=nil)
click to toggle source
set_valid_data
# File lib/mikon/stats.rb, line 156 def skew(m=nil) m ||= self.mean th = self.reduce(0){|memo, val| memo + ((val - m)**3)} th/((self.length)*self.sd(m)**3) end
standard_deviation_population(m=nil)
click to toggle source
split_by_separator_freq splitted
# File lib/mikon/stats.rb, line 165 def standard_deviation_population(m=nil) m ||= self.mean Math.sqrt(self.variance_population(m)) end
Also aliased as: sdp
standard_deviation_sample(m=nil)
click to toggle source
# File lib/mikon/stats.rb, line 170 def standard_deviation_sample(m=nil) if !m.nil? Math.sqrt(variance_sample(m)) else @data.std.first end end
standard_error()
click to toggle source
# File lib/mikon/stats.rb, line 178 def standard_error self.standard_deviation_sample/(Math.sqrt(self.length)) end
Also aliased as: se
sum()
click to toggle source
# File lib/mikon/stats.rb, line 191 def sum @data.sum.first end
sum_of_squared_deviation()
click to toggle source
# File lib/mikon/stats.rb, line 182 def sum_of_squared_deviation self.reduce(0){|memo, val| val**2 + memo} end
sum_of_squares(m=nil)
click to toggle source
# File lib/mikon/stats.rb, line 186 def sum_of_squares(m=nil) m ||= self.mean self.reduce(0){|memo, val| memo + (val-m)**2} end
Also aliased as: ss
variance_sample(m=nil)
click to toggle source
def variance_population def variance_proportion
# File lib/mikon/stats.rb, line 201 def variance_sample(m=nil) m ||= self.mean self.sum_of_squares(m)/(self.length-1) end
Also aliased as: variance
vector_standarized()
click to toggle source
def variance_total def vector_centered def vector_labeled def vector_percentil
# File lib/mikon/stats.rb, line 211 def vector_standarized raise "NotImplementedError" end
Also aliased as: standarized