- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How To Find A P-Value From A Z-Score In Python?

Obtaining a p−value from a z−score is a typical statistical procedure. The number of standard deviations a value is from the mean of a normal distribution is expressed as a z−score, sometimes referred to as a standard score. The z-score can be used to assess the probability that a specific value will appear in a normal distribution.

The probability of getting a test statistic at least as severe as the one that was observed is the p-value, assuming that the null hypothesis is true. Because the z−score is typically the test statistic, determining the p-value from the z−score allows one to evaluate the statistical significance of the observed z−score. This article will discuss P−values, Z−scores, and how to calculate a P−value in Python from a Z-score.

## What is P-value?

In statistics, the probability that a test statistic will be at least as severe as the one that was observed is expressed as a p-value, assuming that the null hypothesis is true. The null hypothesis claims that there is no appreciable difference between an experiment's results and what was predicted.

Hypothesis testing makes use of the p-value to help determine whether a study's results are statistically significant. If the null hypothesis is correct, it is rejected because a very small p-value indicates that the observed data are very improbable to have occurred by chance. Due to the high likelihood that the observed facts were the result of chance, the null hypothesis is not refuted.

## What is Z-score?

The number of standard deviations a value is from the mean of a normal distribution is expressed as a z−score, sometimes referred to as a standard score. The z−score is determined by subtracting the distribution's mean from the value of interest and dividing the result by the distribution's standard deviation.

The z−score is a valuable metric because it enables scale-free comparison of values from various normal distributions. It is now simpler to assess if a given number is an outlier or the probability of that value happening in a normal distribution.

## How to find P-value from a Z-score in Python?

Python's norm.sf function from the scipy.stats package may be used to calculate a p-value from a z-score. The likelihood that an input z−score will be larger than a typical normal random variable is what this function returns. Here is an illustration of how to apply this function to get a p−value from a z−score −

### Syntax

p_value = norm.sf(abs(2.0)) p_value = norm.cdf(2.0)

### Example 1

The p-value for a z−score can also be found using the norm.cdf method from the scipy.stats package. This method returns the likelihood that an input z−score will be less than or equal to a standard normal random variable.

from scipy.stats import norm # Calculate the p-value for a z-score of 2.0 p_value = norm.sf(abs(2.0)) # Print the p-value print(p_value)

### Output

0.022750131948179195

### Example 2

An illustration of how to get a p−value using this function is given below.

from scipy.stats import norm # Calculate the p-value for a z-score of 2.0 p_value = norm.cdf(2.0) # Print the p-value print(p_value)

### Output

0.9772498680518208

## Conclusion

Finally, calculating a p-value from a z-score is a typical statistical activity. The p-value is the likelihood of receiving a test statistic that is at least as severe as the one observed, given that the null hypothesis is true. Because the z-score is frequently the test statistic, calculating the p-value from the z-score is a method of determining the statistical significance of the observed z-score.

Finding a p-value from a z-score is a handy method for determining the statistical significance of a normal distribution. It can assist researchers in making educated judgments regarding the consequences of their results and drawing conclusions about variable connections.