Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Last active December 10, 2015 05:08
Show Gist options
  • Select an option

  • Save flaneur2020/4385443 to your computer and use it in GitHub Desktop.

Select an option

Save flaneur2020/4385443 to your computer and use it in GitHub Desktop.
平均值、方差与统计显著性
require 'mathn'
def variance(arr)
m = avg(arr)
s = arr.map{|i| (i-m) ** 2 }.inject(:+).to_f
s / arr.size
end
def avg(arr)
arr.inject(:+).to_f / arr.size
end
# 数字越大越显著
def signifinance(arr1, arr2)
f = avg(arr1) - avg(arr2)
p = Math.sqrt(variance(arr1) ** 2 / arr1.size +
variance(arr2) ** 2 / arr2.size)
f / p
end
@loddit
Copy link

loddit commented Apr 30, 2013

看来你还是更喜欢ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment