Class: Array
- Includes:
- Statsample::VectorShorthands
- Defined in:
- lib/statsample.rb,
lib/statsample/vector.rb
Instance Method Summary collapse
- #mean ⇒ Object
-
#sd ⇒ Object
Calculate sample standard deviation.
- #sum ⇒ Object
-
#sum_of_squares(m = nil) ⇒ Object
Calcualte sum of squares.
-
#variance_sample(m = nil) ⇒ Object
Calculate sample variance.
Methods included from Statsample::VectorShorthands
Instance Method Details
#mean ⇒ Object
61 62 63 |
# File 'lib/statsample.rb', line 61 def mean sum.fdiv(size) end |
#sd ⇒ Object
Calculate sample standard deviation
78 79 80 81 |
# File 'lib/statsample.rb', line 78 def sd m ||= mean Math::sqrt(variance_sample(m)) end |
#sum ⇒ Object
57 58 59 |
# File 'lib/statsample.rb', line 57 def sum inject(:+) end |
#sum_of_squares(m = nil) ⇒ Object
Calcualte sum of squares
66 67 68 69 |
# File 'lib/statsample.rb', line 66 def sum_of_squares(m=nil) m ||= mean inject(0) {|a,x| a + (x-m).square } end |
#variance_sample(m = nil) ⇒ Object
Calculate sample variance
72 73 74 75 |
# File 'lib/statsample.rb', line 72 def variance_sample(m=nil) m ||= mean sum_of_squares(m).quo(size - 1) end |