Maham Haroon

# P-Values: Understanding Statistical Significance in Plain Language

(Note: this article is also published for TDS on medium)

Hello there!

Today, we’d do a fun exploration of statistics, tackling a concept that is both familiar and yet frequently misconstrued - the elusive, yet ever present, p-value. Don’t worry if you’ve found yourself scratching your head over it before; I’m here to break it down in hopefully an engaging and clear way.

### Significance of P-value

Before we go deeper, lets start with a visual:

Imagine starting out as a freshly graduated data scientist, looking for your first job, you’ve done your due diligence, invested countless hours conquering coding challenges like leet code, and mastered intricate concepts of machine learning algorithms, you're prepared and confident for your very first job interview. The interviewer is welcoming, the atmosphere is inviting, and the questions appear within your knowledge base, and then they ask you: "What exactly is a p-value?"

While you've encountered the term previously, your response in the moment might have been something like, "It indicates the significance of our hypothesis." However, as the interviewer digs further, you realize you might be diving into deeper waters than anticipated. If this scenario sounds familiar, rest assured – you're not alone. In this blog post, we'd attempt to genuinely try to deconstruct what a p-value is and what it isn’t. We'll do so, step by step, so that the next time you encounter this concept, you'll possess proper understanding of the concept.

At its heart, the term "p-value" stands for "probability value." Yet, believe me, its significance is far from straightforward. This concept can prove to be a bit unintuitive and difficult to grasp, primarily due to common misconceptions and even misuse in the industry.

### Setting the Stage with an Example

Picture a fictional pharmaceutical company, MM Pharmaceuticals, introducing “Drug Alpha” as a remedy for headaches. The question at hand: does Drug Alpha genuinely alleviates headaches? To scrutinize its efficacy, MM Pharmaceuticals conduct a study involving two groups — one receives Drug Alpha, while the other is administered a placebo.

The scientists at MM Pharmaceuticals are naturally skeptical, positing that Drug Alpha’s impact on headache relief mirrors that of the placebo aka Drug Alpha has no substantial impact. So, upon analyzing the outcomes of the conducted study, they anticipate results that support this assumption. However, to their astonishment, the results deviate significantly from what one would expect if Drug Alpha acted similarly to the placebo. This anomaly captures their attention, prompting further investigation. This scenario exemplifies an instance of a very low p-value.

Now, let’s introduce some key terminology. The **null hypothesis** serves as our initial assumption also known as the status quo assumption - stating that Drug Alpha lacks the ability to alleviate headaches and mirrors the placebo’s effects. This hypothesis is akin to the skepticism embraced by the scientists at MM Pharmaceuticals. It represents our baseline notion, suggesting no discernible effect of Drug Alpha whatsoever. This is the assumption we’ve modeled our world around where we conduct the study. Conversely, the **alternative hypothesis** posits that Drug Alpha indeed provides headache relief - an outcome we consider unlikely. This alternate hypothesis is what we’re rigorously testing for.

**Enter the p-value!** The p-value quantifies the alignment of our test results with the null hypothesis assumption. A high p-value indicates congruence between results and the null hypothesis, implying that our outcomes are not surprising, and the initial assumption holds merit.

However, a low p-value introduces an element of surprise as observed by scientists at MM Pharmaceuticals. The test outcomes deviate from the expected test outcome under the null hypothesis. This prompts us to reevaluate our starting assumptions, contemplating the possibility that our initial assumption might be incorrect. In this **improbable** scenario, the p-value presents the chance that Drug Alpha could genuinely relieve headaches.

In essence, the p-value equips us with a tool to assess whether our observed results are congruent with our initial assumption. A high p-value aligns with the null hypothesis, whereas a low p-value hints at the need to reconsider our assumptions and do further investigation. Therefore , p-value is a gauge that assists us in determining if the evidence is compelling enough to question preconceived notions. However, it’s vital to note that the p-value itself is not evidence, proof, or an objective measure; rather, it’s a guideline.

In simpler terms:

The p-value informs us of the probability of obtaining our observed results if the null hypothesis were true.

### Statistical Explanation of P-Value

In mathematical terms, the p-value denotes the likelihood of observing data as extreme as what we’ve gathered, under the assumption that the null hypothesis is valid. A notably low p-value (typically less than 0.05) implies that our observed data is improbable under the null hypothesis. This leads us to question the null hypothesis and entertain the possibility of a substantial effect.

We can define p-value mathematically as:

**P-value = P(Result|Null Hypothesis)**

A note to keep in mind: The decision about what constitutes a small enough p-value i.e. 0.05 or 0.01 for an unlikely event, to be significant is subjective. Generally, the rarer the event’s occurrence, the smaller the p-value.

And now for a lighthearted XKCD meme:

## Looking at some Python Code to Distinguish Two Outcomes

In this demonstration, we attempt to simulate the effectiveness of a headache-curing drug through experimentation involving two groups: one group is administered the drug and the other a placebo. We utilize an independent t-test to compare the means of these groups. The ttest_ind function from the scipy.stats module computes both the t-statistic and the p-value.

The p-value signifies the likelihood of observing the disparity in headache-curing effectiveness that we've observed, assuming the drug and placebo yield identical results. When the p-value falls below a predefined significance threshold (often 0.05, referred to as alpha), we tend to question the truth of the null hypothesis and infer there's significance to the alternate hypothesis i.e. the drug does relieve headaches.

Below, we look at two scenarios: one where the p-value is substantial, indicating no noteworthy difference between the observed and expected results under the null hypothesis, and the other where the p-value signifies a significant difference between the two groups.

### Scenario 1: Substantial p-value, no significant difference between observed and expected results

As our goal isn't to conduct actual clinical trials, we mimic the trials by designing a scenario using uniform distributions for both the placebo and drug groups, which we then introduce to our pvalue_significance_estimator function.

When we visualize our results we observe that in the central subplot, the means for both groups are relatively close, resulting in a substantial p-value (approx 0.24). Examining the data, it appears that both groups possess comparable headache-curing attributes.

### Scenario 2: Extreme/very small p-value, significant difference between observed and expected results

To emulate the second scenario, we introduce a bias towards 1 to the drug group's values, noting that this manipulation would be **VERY** questionable in a genuine clinical trial with hopefully far reaching consequences. Once again, we feed the data into our pvalue_significance_estimator function.

Here, we can see a significant variance in the means of the two groups, alongside a very small p-value. It indicates that the drug does have an effect. While this simplified analysis only compares means of two groups with straightforward data, even in this scenario, the alternate hypothesis, pointing towards the effectiveness of the drug, warrants further investigation.

It's important to recognize that this example is a simplified to convey a concept. In practical settings, you'd work with larger datasets, more intricate statistical tests, and additional complexities.

## Understanding the Role and Limitations of the P-Value

Before we conclude, we should discuss some nuanced limitations of p-value's. The p-value is indeed a powerful tool for hypothesis testing. It allows us to assess the extent to which our observed data aligns with our initial assumptions, and helps us in making informed decisions about hypotheses. However, the p-value is not a verdict or a definitive measure of truth. Instead, it serves as a gauge that points researchers toward further investigation into a given hypothesis.

Another thing to note is that while a low p-value may suggest that our observed results differ significantly from what we'd expect under the null hypothesis, it doesn't provide a magnitude of effect. In other words, it doesn't inform us about the practical or quantifiable significance or even the real-world impact of our findings. Additionally, a high p-value, is not a proof in favor of the null hypothesis, and doesn't **definitively** negate alternate hypotheses. Therefore, you need to be cautious when using p-value to draw conclusions.

Furthermore, usually there's reliance on a predefined alpha / significance level, often set at 0.05, brings more ambiguity i.e. is 0.51 significantly different than 0.49? Is the alpha determined really appropriate for the hypothesis under consideration?

Then there's the concept of Type I and Type II errors. A low p-value doesn't eliminate the possibility of a Type I error, where we incorrectly reject a true null hypothesis. Similarly, a high p-value doesn't guarantee avoidance of a Type II error, where we fail to reject a false null hypothesis.

In conclusion, being more nuanced in our understanding of the p-value is a step toward better statistical thinking and better results as an outcome. Recognizing its role as a guide rather than a definitive answer can help us to navigate the complexities landscape of data analysis and hypothesis testing. Simultaneously, acknowledging its limitations helps us to approach results with caution.

## Wrapping Up

In essence, the p-value serves as a guidepost for researchers. It points them towards further exploration, signaling when their data deviates from their initial assumptions. So, the next time you come across p-value, I hope you know exactly what purpose it serves.

Feel free to share your thoughts and questions about p-values in the comments below. I'm all ears.