Function to convert a z-score into a percentage

2020-08-01 06:17发布

问题:

Google doesn't want to help!

I'm able to calculate z-scores, and we are trying to produce a function that given a z-score gives us a percent of the population in a normal distribution that would be under that z-score. All I can find are references to z-score to percentage tables.

Any pointers?

回答1:

Is it this z-score (link) you're talking about?

If so, the function you're looking for is called the normal cumulative distribution, also sometimes referred to as the error function (although Wikipedia defines the two slightly differently). How to calculate it depends on what programming environment you're using.



回答2:

If you're programming in C++, you can do this with the Boost library, which has routines for working with normal distributions. You are looking for the cdf accessor function, which takes a z-score as input and returns the probability you want.



回答3:

Here's a code snippet for python:

import math

def percentage_of_area_under_std_normal_curve_from_zcore(z_score):
    return .5 * (math.erf(z_score / 2 ** .5) + 1)

Using the following photo for reference: http://www.math.armstrong.edu/statsonline/5/cntrl8.gif

The z-score is 1.645, and that covers 95 percent of the area under the standard normal distribution curve.

When you run the code, it looks like this:

>>> std_normal_percentile_from_zcore(1.645)
0.9500150944608786

More about the error function: http://en.wikipedia.org/wiki/Error_function



标签: math