I have a task from which I would like to find the confidence level given the z value. I have a sample population. From that population, given its distribution, I would like to find the confidence level of a given value of that population. In other words, given a a value of the population, I would like to know if it is within 95% (confidence level) of the whole population or 68% or 50% and so on. Usually, we can find the z value and confidence interval and given confidence level as explained here How to find the confidence Interval. But I would like to find the confidence level given the z value (which in this case is a given value from the population).

How can I tackle this? If possible it should be in python or in R


2 Answers 2


OK, for a 95% confidence interval, you want to know how many standard deviations away from the mean your point estimate is (the "z-score"). To get that, you take off the 5% "tails". Working in percentile form you have 100-95 which yields a value of 5, or 0.05 in decimal form.

Divide that in half to get 0.025 and then, in R, use the qnorm function to get the z-star ("critical value"). Since you only care about one "side" of the curve (the values on either side are mirror images of each other) and you want a positive number, pass the argument lower.tail=FALSE.

So, in the end, it would look like this:


yielding a value of 1.959964

You then plug that value into the equation for the margin of error to finish things up.

If you want to go the other direction, from a "critical value" to a probability, use the pnorm function. Something like:


which will give you back 0.025

  • $\begingroup$ I could have worded that better, but the net-net is "use qnorm/pnorm". $\endgroup$
    – mindcrime
    Aug 4, 2016 at 18:48

To convert between z-scores and confidence values with python, use the cdf and ppf functions in scipy.stats.norm.

There is a nice example of how to use them in the answer for this question.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.