z分数在红宝石概率,反之亦然(z-score to probability and vice ver

2019-10-24 15:57发布

我如何可以转换使用Ruby z分数概率?

例:

z_score = 0
probability should be 0.5

z_score = 1.76
probability should be 0.039204

Answer 1:

根据这一https://stackoverflow.com/a/16197404/1062711后,这里是让你从z分数在p PROBA功能

def getPercent(z)
  return 0 if z < -6.5
  return 1 if z > 6.5

  factk = 1
  sum = 0
  term = 1
  k = 0

  loopStop = Math.exp(-23)
  while term.abs > loopStop do
      term = 0.3989422804 * ((-1)**k) * (z**k) / (2*k+1) / (2**k) * (z**(k+1)) /factk
      sum += term
      k += 1
      factk *= k
  end

  sum += 0.5
  1-sum
end

puts getPercent(1.76)


文章来源: z-score to probability and vice verse in ruby