Module: Mikon::Stats
Instance Method Summary collapse
- #==(other) ⇒ Object
- #average_deviation_population(m = nil) ⇒ Object (also: #adp)
- #coefficient_of_variation ⇒ Object
- #count(x = false) ⇒ Object
- #each(&block) ⇒ Object
- #each_index(&block) ⇒ Object
-
#factors ⇒ Object
uniq.
- #frequencies ⇒ Object
- #has_missing_data? ⇒ Boolean (also: #flawed?)
- #is_valid? ⇒ Boolean
- #kurtosis(m = nil) ⇒ Object
-
#mean ⇒ Object
alias_method :label, :labeling labeling(x) would be not implemented.
- #median ⇒ Object
- #median_absolute_deviation ⇒ Object (also: #mad)
- #mode ⇒ Object
- #n_valid ⇒ Object
- #percentil(percent) ⇒ Object
- #product ⇒ Object
- #proportion(val = 1) ⇒ Object
- #proportion_confidence_interval_t ⇒ Object
- #proportion_confidence_interval_z ⇒ Object
- #proportions ⇒ Object
- #push(val) ⇒ Object
- #range ⇒ Object
-
#ranked ⇒ Object
?.
- #recode(&block) ⇒ Object
- #recode!(&block) ⇒ Object
-
#skew(m = nil) ⇒ Object
set_valid_data.
-
#standard_deviation_population(m = nil) ⇒ Object
(also: #sdp)
split_by_separator_freq splitted.
- #standard_deviation_sample(m = nil) ⇒ Object (also: #sd, #sds)
- #standard_error ⇒ Object (also: #se)
- #sum ⇒ Object
- #sum_of_squared_deviation ⇒ Object
- #sum_of_squares(m = nil) ⇒ Object (also: #ss)
-
#variance_sample(m = nil) ⇒ Object
(also: #variance)
def variance_population def variance_proportion.
-
#vector_standarized ⇒ Object
(also: #standarized)
def variance_total def vector_centered def vector_labeled def vector_percentil.
Instance Method Details
#==(other) ⇒ Object
82 83 84 |
# File 'lib/mikon/stats.rb', line 82 def ==(other) @data==other end |
#average_deviation_population(m = nil) ⇒ Object Also known as: adp
10 11 12 13 |
# 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 |
#coefficient_of_variation ⇒ Object
15 16 17 |
# File 'lib/mikon/stats.rb', line 15 def coefficient_of_variation self.standard_deviation_sample/self.mean end |
#count(x = false) ⇒ Object
19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 |
# 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) ⇒ Object
33 34 35 |
# File 'lib/mikon/stats.rb', line 33 def each_index(&block) self.each.with_index(&block) end |
#factors ⇒ Object
uniq
38 39 40 41 |
# 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 ⇒ Object
43 44 45 46 |
# 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? ⇒ Boolean Also known as: flawed?
48 49 50 |
# File 'lib/mikon/stats.rb', line 48 def has_missing_data? false end |
#is_valid? ⇒ Boolean
52 53 54 |
# File 'lib/mikon/stats.rb', line 52 def is_valid? true end |
#kurtosis(m = nil) ⇒ Object
56 57 58 59 60 |
# 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 ⇒ Object
alias_method :label, :labeling labeling(x) would be not implemented
65 66 67 |
# File 'lib/mikon/stats.rb', line 65 def mean @data.mean.first end |
#median ⇒ Object
69 70 71 |
# File 'lib/mikon/stats.rb', line 69 def median self.percentil(50) end |
#median_absolute_deviation ⇒ Object Also known as: mad
73 74 75 76 |
# File 'lib/mikon/stats.rb', line 73 def median_absolute_deviation m = self.median self.recode{|val| (val-m).abls}.median end |
#mode ⇒ Object
78 79 80 |
# File 'lib/mikon/stats.rb', line 78 def mode self.frequencies.max end |
#n_valid ⇒ Object
86 87 88 |
# File 'lib/mikon/stats.rb', line 86 def n_valid self.length end |
#percentil(percent) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# 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 ⇒ Object
101 102 103 |
# File 'lib/mikon/stats.rb', line 101 def product @data.inject(1){|memo, val| memo*val} end |
#proportion(val = 1) ⇒ Object
105 106 107 |
# File 'lib/mikon/stats.rb', line 105 def proportion(val=1) self.frequencies[val]/self.n_valid end |
#proportion_confidence_interval_t ⇒ Object
109 110 111 |
# File 'lib/mikon/stats.rb', line 109 def proportion_confidence_interval_t raise "NotImplementedError" end |
#proportion_confidence_interval_z ⇒ Object
113 114 115 |
# File 'lib/mikon/stats.rb', line 113 def proportion_confidence_interval_z raise "NotImplementedError" end |
#proportions ⇒ Object
117 118 119 120 |
# 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) ⇒ Object
122 123 124 125 |
# File 'lib/mikon/stats.rb', line 122 def push(val) self.(self.length+1) self[self.length-1] = recode end |
#range ⇒ Object
127 128 129 |
# File 'lib/mikon/stats.rb', line 127 def range max - min end |
#ranked ⇒ Object
?
132 133 134 135 136 137 138 139 140 |
# 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) ⇒ Object
142 143 144 |
# File 'lib/mikon/stats.rb', line 142 def recode(&block) Mikon::DArray.new(@data.map(&block)) end |
#recode!(&block) ⇒ Object
146 147 148 |
# File 'lib/mikon/stats.rb', line 146 def recode!(&block) @data.map!(&block) end |
#skew(m = nil) ⇒ Object
set_valid_data
156 157 158 159 160 |
# 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) ⇒ Object Also known as: sdp
split_by_separator_freq splitted
165 166 167 168 |
# File 'lib/mikon/stats.rb', line 165 def standard_deviation_population(m=nil) m ||= self.mean Math.sqrt(self.variance_population(m)) end |
#standard_deviation_sample(m = nil) ⇒ Object Also known as: sd, sds
170 171 172 173 174 175 176 |
# 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 ⇒ Object Also known as: se
178 179 180 |
# File 'lib/mikon/stats.rb', line 178 def standard_error self.standard_deviation_sample/(Math.sqrt(self.length)) end |
#sum ⇒ Object
191 192 193 |
# File 'lib/mikon/stats.rb', line 191 def sum @data.sum.first end |
#sum_of_squared_deviation ⇒ Object
182 183 184 |
# 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) ⇒ Object Also known as: ss
186 187 188 189 |
# 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 |
#variance_sample(m = nil) ⇒ Object Also known as: variance
def variance_population def variance_proportion
201 202 203 204 |
# File 'lib/mikon/stats.rb', line 201 def variance_sample(m=nil) m ||= self.mean self.sum_of_squares(m)/(self.length-1) end |
#vector_standarized ⇒ Object Also known as: standarized
def variance_total def vector_centered def vector_labeled def vector_percentil
211 212 213 |
# File 'lib/mikon/stats.rb', line 211 def vector_standarized raise "NotImplementedError" end |