2025-11-17

Overview

  • Topic: P-value in hypothesis testing

  • Goal: Understand what a p-value is and how to interpret it

  • Key Points:

    • Define the p-value
    • The basic idea behind how it’s calculated
    • How to compute and visualze it using R

What is a P-value?

  • A p-value measure how compatible the sample data is with the null hypothesis
  • In simple words : It is the probability of seeing data atleast as extreme as what we observed, assuming the null hypothesis is true
  • A p-value does not tell us :
    • The probability that the null hypothesis is true
    • The probability that our alternative hypothesis is true

Mathematical Definition

For a right tailed test, the p-value is : \[ p = P(T \ge t_{\text{obs}} \mid H_0 \text{ is true}) \]

For a left tailed test : \[ p = P(T \le t_{\text{obs}} \mid H_0 \text{ is true}) \]

Hypothesis Testing Setup

We test a population mean: \[ H_0: \mu = \mu_0 \\ H_a: \mu \ne \mu_0 \] we collect a sample \(X_1, \dots, X_n\) with mean \(\bar{X}\) and standard deviation \(s\).

The test statistic is : \[ t = \frac{\bar{X} - \mu_0}{s / \sqrt{n}} \]

R Code : One Sample t-test

t_test_result
## 
##  One Sample t-test
## 
## data:  Sample_data
## t = 0.99041, df = 99, p-value = 0.3244
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.909283 5.271528
## sample estimates:
## mean of x 
##  5.090406

Histogram of Sample Data

Density Plot with Null and Sample Mean

3D Plot of the Sample

Interpreting the P-value

  • Small p-value (e.g, < 0.05):
    • Data would be rare if \(H_0\) were true
    • We say there is evidence against \(H_0\)
  • Large p-value:
    • Data is consistent with \(H_0\)
    • We do not reject the null hypothesis

Conclusion

  • P-values show how well the data align with the null hypothesis
  • They are useful, but only one part of the overall analysis
  • Always interpret p-values along with :
    • Sample size
    • Effect size
    • Context