Z-score to probability and vice versa in ruby

How to convert z-score to probability using ruby?

Example:

z_score = 0 probability should be 0.5 z_score = 1.76 probability should be 0.039204 
0
source share
1 answer

According to this post by fooobar.com/questions/686661 / ... , here is a function that gives you p proba from a score of z

 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) 
+4
source

All Articles