are using the previously mentioned formula to calculate the Z score.
The output of the above program will be:
-0.7825419893293738
How to calculate the p-value from z-score using Python?
After calculating the Z-score like the above, we need to calculate the p-value or the critical value to know whether the difference in the average values is statistically significant. In Python, we can calculate the p-value from z-score using the numpy.norm.sf function. numpy.norm.sf is the survival function. It is also defined as (1 – cdf), where cdf is the cumulative distribution fucntion. But it is always recommended to use the sf function as it is more accurate.
from scipy.stats import norm import numpy # Calculate p-value for the specific z-score and left-tailed z-test p_value = norm.sf(numpy.abs(z_score)) print("For left-tailed test: ", p_value) # Calculate p-value for the specific z-score and right-tailed z-test p_value = norm.sf(numpy.abs(z_score)) print("For right-tailed test: ", p_value) # Calculate p-value for the specific z-score and two-tailed z-test p_value = 2*norm.sf(numpy.abs(z_score)) print("For two-tailed test: ", p_value)
For the z-score -0.7825419893293738, the output of the above program will be:
For left-tailed test: 0.2169480593233185 For right-tailed test: 0.2169480593233185 For two-tailed test: 0.433896118646637
How to calculate the critical value for a z-test?
The critical value for a z-test can be calculated using the norm.ppf function in Python. ppf is the percent point function. A Percent Point Function or a quantile function specifies the value x of a random variable X such that the probability of X being less than or equal to x equals the given probability p. …






0 Comments