2025-10-23

1) What is a p-value?

  • Definition: A p-value, or probability value, is a number describing the likelihood of obtaining the observed data under the null hypothesis of a statistical test, \(H_0\)
  • Intuition: A statistical measure used to determine that an observed outcome is the result of chance
  • Right-tailed definition: \[ p \;=\; \Pr(T \ge t_{\text{obs}} \mid H_0) \]
  • Smaller \(p\) ⇒ stronger evidence against \(H_0\)

2) Hypotheses & Test Statistic

One-sample mean (known \(\sigma\)), right-tailed test: \[ \begin{aligned} H_0 &: \mu = \mu_0, \qquad H_1 &: \mu > \mu_0 \end{aligned} \] \[ z \;=\; \frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}}, \qquad p = \Pr\big(Z \ge z_{\text{obs}}\big) \]

3) P-Value Example: Coin Fairness Test

You have a coin and wish to check whether it is fair or biased
Let \(\theta = P(H)\) be the probability of heads

\[ \begin{aligned} H_0 \; (\text{Null hypothesis}) &: \; \theta = \theta_0 = 0.5 &\quad (\text{coin is fair}) \\ H_1 \; (\text{Alternative hypothesis}) &: \; \theta > 0.5 &\quad (\text{coin favors heads}) \end{aligned} \]

We toss the coin \(n = 100\) times and observe \(k_{\text{obs}} = 60\) heads

  • p-value:
    \[ p = \Pr\{K \ge 60 \mid K \sim \mathrm{Binom}(100, 0.5)\} = 0.02844 \]

  • At significance level \(\alpha = 0.05\):
    Reject H₀

  • At significance level \(\alpha = 0.01\):
    Fail to reject H₀

4) ggplot #1 — Binomial PMF (Tail Shaded)

Explanation: The bars show the null distribution for heads counts when the coin is fair
Darker bars mark the right-tail (results \(\ge k_{\text{obs}}=60\)). The area of that tail equals the p-value.

5) ggplot #2 — Simulated p-values under H₀

Explanation: Under \(H_0\), p-values are roughly Uniform(0,1).
This validates the idea that small p-values are rare when \(H_0\) is true.

6) plotly — Interactive PMF (Tail Highlight)

Explanation: Same PMF as Slide 4, but interactive: hover to see exact probabilities.
Bars for \(k \ge 60\) are highlighted to show the right-tail used to compute the p-value.

7) R Code (Visible) — Build PMF & Tail Plot

n <- 100; p0 <- 0.5; k_obs <- 60
k <- 0:n
pmf <- dbinom(k, size = n, prob = p0)
tail_flag <- k >= k_obs
df_binom <- data.frame(k = k, pmf = pmf, tail = tail_flag)
p_val_binom <- sum(dbinom(k_obs:n, size = n, prob = p0))

ggplot(df_binom, aes(x = k, y = pmf, fill = tail)) +
  geom_col() +
  scale_fill_manual(values = c("grey80", "grey30")) +
  labs(
    title = "Binomial PMF under H₀: p = 0.5, n = 100",
    subtitle = paste0("Tail k ≥ ", k_obs, "; p ≈ ", signif(p_val_binom, 4)),
    x = "k",
    y = "Probability"
  ) +
  theme_minimal(base_size = 13) +
  theme(legend.position = "none")

Explanation: This code computes binomial probabilities, marks the right-tail region, computes the p-value, and plots the PMF.

8) Wrap-up

  • Observed \(k = 60\) heads in 100 tosses.
  • \(p = \Pr(K \ge 60 \mid \text{Binom}(100, 0.5)) \approx\) 0.02844.
  • At \(\alpha = 0.05\): Reject H₀
  • At \(\alpha = 0.01\): Fail to reject H₀

9) Sources