Skip to content

Instantly share code, notes, and snippets.

@terrbear
Created December 21, 2008 15:30
Show Gist options
  • Save terrbear/38694 to your computer and use it in GitHub Desktop.
Save terrbear/38694 to your computer and use it in GitHub Desktop.
Math.module_eval do
def self.variance(population)
n = 0
mean = 0.0
s = 0.0
population.each do |x|
n += 1
delta = x - mean
mean = mean + (delta / n)
s = s + delta * (x - mean)
end
return s / n
end
def self.stddev(population)
Math.sqrt(Math.variance(population)) rescue (0.0/0.0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment