top of page

# P - Value

In statistical hypothesis testing, the P-value is a measure of the evidence against a null hypothesis. It is the probability of observing a test statistic as extreme or more extreme than the one observed, assuming that the null hypothesis is true.

A small P-value indicates strong evidence against the null hypothesis and in favor of the alternative hypothesis. Conversely, a large P-value indicates weak evidence against the null hypothesis and in favor of the null hypothesis.

The common threshold for the P-value is 0.05, which means that if the P-value is less than or equal to 0.05, the null hypothesis is rejected, and the result is considered statistically significant. In other words, if the P-value is less than or equal to 0.05, there is less than a 5% chance that the result occurred by chance.

It is important to note that the P-value is not the probability that the null hypothesis is true, nor is it the probability that the alternative hypothesis is true. The P-value is simply a measure of the evidence against the null hypothesis and in favor of the alternative hypothesis.

In conclusion, the P-value is a useful tool in statistical hypothesis testing to determine the statistical significance of a result. A small P-value indicates strong evidence against the null hypothesis, while a large P-value indicates weak evidence against the null hypothesis.

Here's an example to help explain the concept of P-value in statistics:

Suppose we have a coin that we believe is biased towards heads, and we want to test this hypothesis. Our null hypothesis is that the coin is fair, meaning that it has a 50% chance of landing on either heads or tails. Our alternative hypothesis is that the coin is biased towards heads, meaning that it has a greater than 50% chance of landing on heads.

To test the hypothesis, we flip the coin 10 times and observe 8 heads. Given this result, we can calculate the P-value, which is the probability of observing 8 or more heads in 10 flips given that the coin is fair. If the P-value is less than or equal to 0.05, we reject the null hypothesis and conclude that the coin is biased towards heads.

Using a binomial distribution, we can calculate the P-value to be 0.024, which is less than 0.05. Therefore, we reject the null hypothesis and conclude that the coin is biased towards heads.

In this example, the P-value of 0.024 gives us the evidence against the null hypothesis and in favor of the alternative hypothesis. It indicates that there is only a 2.4% chance that the result of 8 heads in 10 flips occurred by chance if the coin is fair, which is considered statistically significant.

here's an example implementation of P-value calculation in Python using the scipy library:

from scipy.stats import binom

def p_value(n, k, p):

"""
Calculates the P-value for a binomial distribution with parameters n, k, and p.
n: number of trials
k: number of successes
p: probability of success in each trial
"""
p_value = 1 - binom.cdf(k - 1, n, p)
return p_value

n = 10
k = 8
p = 0.5

p_value = p_value(n, k, p)

print(p_value)

In this implementation, the p_value function calculates the P-value for a binomial distribution with parameters n, k, and p. n is the number of trials, k is the number of successes, and p is the probability of success in each trial. The function uses the cumulative distribution function binom.cdf from the scipy.stats library to calculate the P-value.

In this example, the coin flip experiment with 10 trials and 8 heads has a P-value of 0.024, which is the probability of observing 8 or more heads given that the coin is fair. This indicates that there is only a 2.4% chance that the result of 8 heads in 10 flips occurred by chance if the coin is fair.

bottom of page