Motivation

In statistics, we often ask a simple question:

Is what we see in the data real, or could it just be random chance?

The p-value helps us answer this question.

Hypothesis Testing

We will begin with two statements:

\[ H_0: \mu = \mu_0 \]

\[ H_a: \mu \neq \mu_0 \]

  • \(H_0\) says there is no effect
  • \(H_a\) says there is an effect
  • \(\mu\) is the true population mean

Test Statistic

To test the hypotheses, we compute:

\[ t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}} \]

This value tells us
how far the sample mean is from the null value, measured in standard error units.

What Is a p-value?

The p-value is:

\[ \text{Probability of seeing results this extreme if } H_0 \text{ is true} \]

  • Small p-value → strong evidence against \(H_0\)
  • Large p-value → weak evidence against \(H_0\)

Example Data

We will generate sample data from a normal distribution.

The goal is to test
whether the population mean is equal to 50.

Sample Data Distribution

This plot shows:

  • The histogram of the data
  • A smooth curve showing the overall shape

It helps us see where the data values fall.

p-value Region

The shaded areas show the p-value.

They represent outcomes that are
as extreme or more extreme than our data, assuming the null hypothesis is true.

Computing the p-value in R

R can calculate the p-value directly
using a one-sample t-test.

## 
##  One Sample t-test
## 
## data:  data
## t = 3.1361, df = 39, p-value = 0.00325
## alternative hypothesis: true mean is not equal to 50
## 95 percent confidence interval:
##  50.79029 53.66154
## sample estimates:
## mean of x 
##  52.22592

p-value vs Sample Mean and Sample Size

This plot shows how the p-value changes as the sample mean moves away from the null value and as the sample size increases. Smaller p-values mean stronger evidence against the null hypothesis.

Conclusion

  • The p-value measures evidence against the null hypothesis
  • It depends on both effect size and sample size
  • A small p-value does not always mean a big or important effect

Context always matters.