Table of Contents
The process of finding a p-value from a z-score using Python involves utilizing statistical functions and modules within the Python programming language. This includes calculating the probability under the normal distribution curve using the cumulative distribution function and the use of the scipy.stats module. By inputting the z-score value and specifying the desired significance level, the p-value can be calculated and interpreted to determine the level of statistical significance. This method is commonly used in hypothesis testing and other statistical analyses.
Find a P-Value from a Z-Score in Python
Often in statistics we’re interested in determining the associated with a certain z-score that results from a . If this p-value is below some significance level, we can reject the null hypothesis of our hypothesis test.
To find the p-value associated with a z-score in Python, we can use the , which uses the following syntax:
scipy.stats.norm.sf(abs(x))
where:
- x: The z-score
The following examples illustrate how to find the p-value associated with a z-score for a left-tailed test, right-tailed test, and a two-tailed test.
Left-tailed test
Suppose we want to find the p-value associated with a z-score of -0.77 in a left-tailed hypothesis test.
import scipy.stats #find p-value scipy.stats.norm.sf(abs(-0.77)) 0.22064994634264962
The p-value is 0.2206. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.
Right-tailed test
Suppose we want to find the p-value associated with a z-score of 1.87 in a right-tailed hypothesis test.
import scipy.stats #find p-value scipy.stats.norm.sf(abs(1.87)) 0.030741908929465954
The p-value is 0.0307. If we use a significance level of α = 0.05, we would reject the null hypothesis of our hypothesis test because this p-value is less than 0.05.
Two-tailed test
Suppose we want to find the p-value associated with a z-score of 1.24 in a two-tailed hypothesis test.
import scipy.stats #find p-value for two-tailed test scipy.stats.norm.sf(abs(1.24))*2 0.21497539414917388
The p-value is 0.2149. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.
Related: You can also use this online to find p-values.