本文介绍了分数和红宝石中的z分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用红宝石将z分数转换为概率?
How can I convert z-score to probability using ruby?
示例:
z_score = 0
probability should be 0.5
z_score = 1.76
probability should be 0.039204
推荐答案
根据此 https://stackoverflow.com/a/16197404/1062711 帖子,这是从z得分为您提供p proba的函数
According to this https://stackoverflow.com/a/16197404/1062711 post, here is the function that give you the p proba from the z score
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分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!