Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/expcalc/array_expansion.rb

Instance Method Summary collapse

Instance Method Details

#get_quantiles(position = 0.5) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/expcalc/array_expansion.rb', line 13

def get_quantiles(position=0.5)
  self.sort!
  n_items = self.size
  quantile_coor = n_items * position - 1
  if n_items % 2 == 0
    quantile_value = (self[quantile_coor.to_i] + self[quantile_coor.to_i + 1]).fdiv(2)   
  else
    quantile_value = self[quantile_coor.ceil]
  end
  return quantile_value
end

#meanObject



3
4
5
# File 'lib/expcalc/array_expansion.rb', line 3

def mean
	return self.inject(0){|sum, n | sum + n}.fdiv(self.length)
end

#standard_deviationObject



7
8
9
10
11
# File 'lib/expcalc/array_expansion.rb', line 7

def standard_deviation
	x_mean = self.mean
	variance = self.inject(0){|sum, n | sum + (n - x_mean)**2 }.fdiv(self.length)
	return Math.sqrt(variance)
end