Module: DaruLite::Vector::Calculatable
- Included in:
- DaruLite::Vector
- Defined in:
- lib/daru_lite/vector/calculatable.rb
Instance Method Summary collapse
-
#count_values(*values) ⇒ Integer
Count the number of values specified.
-
#numeric_summary ⇒ String
Displays summary for an numeric type Vector.
-
#object_summary ⇒ String
Displays summary for an object type Vector.
-
#summary(indent_level = 0) ⇒ String
Create a summary of the Vector.
Instance Method Details
#count_values(*values) ⇒ Integer
Count the number of values specified
11 12 13 |
# File 'lib/daru_lite/vector/calculatable.rb', line 11 def count_values(*values) positions(*values).size end |
#numeric_summary ⇒ String
Displays summary for an numeric type Vector
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/daru_lite/vector/calculatable.rb', line 62 def numeric_summary summary = "\n median: #{median}" + format("\n mean: %0.4f", mean) if sd summary << (format("\n std.dev.: %0.4f", sd) + format("\n std.err.: %0.4f", se)) end if count_values(*DaruLite::MISSING_VALUES).zero? summary << (format("\n skew: %0.4f", skew) + format("\n kurtosis: %0.4f", kurtosis)) end summary end |
#object_summary ⇒ String
Displays summary for an object type Vector
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/daru_lite/vector/calculatable.rb', line 47 def object_summary nval = count_values(*DaruLite::MISSING_VALUES) summary = "\n factors: #{factors.to_a.join(',')}" \ "\n mode: #{mode.to_a.join(',')}" \ "\n Distribution\n" data = frequencies.sort.each_with_index.map do |v, k| [k, v, format('%0.2f%%', ((nval.zero? ? 1 : v.quo(nval)) * 100))] end summary + Formatters::Table.format(data) end |
#summary(indent_level = 0) ⇒ String
Create a summary of the Vector
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/daru_lite/vector/calculatable.rb', line 31 def summary(indent_level = 0) non_missing = size - count_values(*DaruLite::MISSING_VALUES) summary = (' =' * indent_level) + "= #{name}" \ "\n n :#{size}" \ "\n non-missing:#{non_missing}" case type when :object summary << object_summary when :numeric summary << numeric_summary end summary.split("\n").join("\n#{' ' * indent_level}") end |