Daniel
Daniel

Reputation: 1663

Function to convert a z-score into a percentage

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?

Upvotes: 2

Views: 7776

Answers (3)

ohzanab
ohzanab

Reputation: 31

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

Upvotes: 3

Jim Lewis
Jim Lewis

Reputation: 45105

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.

Upvotes: 3

David Z
David Z

Reputation: 131640

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.

Upvotes: 4

Related Questions