what is the p-value?

Vinay Chaudhari
4 min readDec 12, 2022
https://analystprep.com/cfa-level-1-exam/wp-content/uploads/2019/08/page-178.jpg

The p-value is the probability of observing a test statistic at least as extreme as the one observed, given that the null hypothesis is true. It is used in hypothesis testing to determine whether the observed data is statistically significant.

Imagine that you are trying to decide whether a coin is fair or not. You can flip the coin a few times and count the number of heads and tails to see if the proportion of heads is close to 0.5. If the proportion of heads is significantly different from 0.5, you can reject the null hypothesis that the coin is fair.

The p-value is the probability that the coin is actually fair, given the data you observed. If the p-value is very low, it means that the data is very unlikely to have occurred by chance, and you can reject the null hypothesis with confidence.

Here is a simple python code example to illustrate the concept of the p-value:

import numpy as np
from scipy.stats import t

# Define the number of coin flips we will do
n = 10

# Flip the coin n times and count the number of heads
heads = np.random.binomial(n, 0.5)

# Calculate the proportion of heads
proportion_of_heads = heads / n

# Use the t-test to calculate the p-value
t_value, p_value = t.interval(alpha=0.05, df=n-1, loc=0.5, scale=0.5/np.sqrt(n))

print("The p-value is: ", p_value)
print("This means that the probability that the coin…

--

--

Vinay Chaudhari

Enthusiastic article writer and lifelong learner, passionate about documenting and exploring new ideas.